fur.fragment.fx 2.4 KB

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