fur.fragment.fx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. precision highp float;
  2. // Constants
  3. uniform vec3 vEyePosition;
  4. uniform vec4 vDiffuseColor;
  5. // Input
  6. uniform vec4 furColor;
  7. varying vec3 vPositionW;
  8. varying float vfur_length;
  9. #ifdef NORMAL
  10. varying vec3 vNormalW;
  11. #endif
  12. #ifdef VERTEXCOLOR
  13. varying vec4 vColor;
  14. #endif
  15. // Lights
  16. #include<lightFragmentDeclaration>[0..maxSimultaneousLights]
  17. // Samplers
  18. #ifdef DIFFUSE
  19. varying vec2 vDiffuseUV;
  20. uniform sampler2D diffuseSampler;
  21. uniform vec2 vDiffuseInfos;
  22. #endif
  23. // Fur uniforms
  24. #ifdef HIGHLEVEL
  25. uniform float furOffset;
  26. uniform sampler2D furTexture;
  27. varying vec2 vFurUV;
  28. #endif
  29. #include<lightsFragmentFunctions>
  30. #include<shadowsFragmentFunctions>
  31. #include<fogFragmentDeclaration>
  32. #include<clipPlaneFragmentDeclaration>
  33. float Rand(vec3 rv) {
  34. float x = dot(rv, vec3(12.9898,78.233, 24.65487));
  35. return fract(sin(x) * 43758.5453);
  36. }
  37. void main(void) {
  38. // Clip plane
  39. #include<clipPlaneFragment>
  40. vec3 viewDirectionW = normalize(vEyePosition - vPositionW);
  41. // Base color
  42. vec4 baseColor = furColor;
  43. vec3 diffuseColor = vDiffuseColor.rgb;
  44. // Alpha
  45. float alpha = vDiffuseColor.a;
  46. #ifdef DIFFUSE
  47. baseColor *= texture2D(diffuseSampler, vDiffuseUV);
  48. #ifdef ALPHATEST
  49. if (baseColor.a < 0.4)
  50. discard;
  51. #endif
  52. baseColor.rgb *= vDiffuseInfos.y;
  53. #endif
  54. #ifdef VERTEXCOLOR
  55. baseColor.rgb *= vColor.rgb;
  56. #endif
  57. // Bump
  58. #ifdef NORMAL
  59. vec3 normalW = normalize(vNormalW);
  60. #else
  61. vec3 normalW = vec3(1.0, 1.0, 1.0);
  62. #endif
  63. #ifdef HIGHLEVEL
  64. // Fur
  65. vec4 furTextureColor = texture2D(furTexture, vec2(vFurUV.x, vFurUV.y));
  66. if (furTextureColor.a <= 0.0 || furTextureColor.g < furOffset) {
  67. discard;
  68. }
  69. float occlusion = mix(0.0, furTextureColor.b * 1.2, furOffset);
  70. baseColor = vec4(baseColor.xyz * occlusion, 1.1 - furOffset);
  71. #endif
  72. // Lighting
  73. vec3 diffuseBase = vec3(0., 0., 0.);
  74. lightingInfo info;
  75. float shadow = 1.;
  76. float glossiness = 0.;
  77. #include<lightFragment>[0..maxSimultaneousLights]
  78. #ifdef VERTEXALPHA
  79. alpha *= vColor.a;
  80. #endif
  81. vec3 finalDiffuse = clamp(diffuseBase.rgb * baseColor.rgb, 0.0, 1.0);
  82. // Composition
  83. #ifdef HIGHLEVEL
  84. vec4 color = vec4(finalDiffuse, alpha);
  85. #else
  86. float r = vfur_length * 0.5;
  87. vec4 color = vec4(finalDiffuse * (0.5 + r), alpha);
  88. #endif
  89. #include<fogFragment>
  90. gl_FragColor = color;
  91. }