geometry.fragment.fx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #extension GL_EXT_draw_buffers : require
  2. #if defined(BUMP) || !defined(NORMAL)
  3. #extension GL_OES_standard_derivatives : enable
  4. #endif
  5. precision highp float;
  6. precision highp int;
  7. #ifdef BUMP
  8. varying mat4 vWorldView;
  9. varying vec3 vNormalW;
  10. #else
  11. varying vec3 vNormalV;
  12. #endif
  13. varying vec4 vViewPos;
  14. #if defined(POSITION) || defined(BUMP)
  15. varying vec3 vPositionW;
  16. #endif
  17. #ifdef VELOCITY
  18. varying vec4 vCurrentPosition;
  19. varying vec4 vPreviousPosition;
  20. #endif
  21. #ifdef NEED_UV
  22. varying vec2 vUV;
  23. #endif
  24. #ifdef BUMP
  25. uniform vec3 vBumpInfos;
  26. uniform vec2 vTangentSpaceParams;
  27. #endif
  28. #ifdef REFLECTIVITY
  29. varying vec2 vReflectivityUV;
  30. uniform sampler2D reflectivitySampler;
  31. #endif
  32. #ifdef ALPHATEST
  33. uniform sampler2D diffuseSampler;
  34. #endif
  35. #include<mrtFragmentDeclaration>[RENDER_TARGET_COUNT]
  36. #include<bumpFragmentFunctions>
  37. void main() {
  38. #ifdef ALPHATEST
  39. if (texture2D(diffuseSampler, vUV).a < 0.4)
  40. discard;
  41. #endif
  42. gl_FragData[0] = vec4(vViewPos.z / vViewPos.w, 0.0, 0.0, 1.0);
  43. //color0 = vec4(vViewPos.z / vViewPos.w, 0.0, 0.0, 1.0);
  44. #ifdef BUMP
  45. vec3 normalW = normalize(vNormalW);
  46. #include<bumpFragment>
  47. gl_FragData[1] = vec4(normalize(vec3(vWorldView * vec4(normalW, 0.0))), 1.0);
  48. #else
  49. gl_FragData[1] = vec4(normalize(vNormalV), 1.0);
  50. #endif
  51. #ifdef POSITION
  52. gl_FragData[POSITION_INDEX] = vec4(vPositionW, 1.0);
  53. #endif
  54. #ifdef VELOCITY
  55. vec2 a = (vCurrentPosition.xy / vCurrentPosition.w) * 0.5 + 0.5;
  56. vec2 b = (vPreviousPosition.xy / vPreviousPosition.w) * 0.5 + 0.5;
  57. vec2 velocity = abs(a - b);
  58. velocity = vec2(pow(velocity.x, 1.0 / 3.0), pow(velocity.y, 1.0 / 3.0)) * sign(a - b) * 0.5 + 0.5;
  59. gl_FragData[VELOCITY_INDEX] = vec4(velocity, 0.0, 1.0);
  60. #endif
  61. #ifdef REFLECTIVITY
  62. #ifdef HAS_SPECULAR
  63. // Specular
  64. vec4 reflectivity = texture2D(reflectivitySampler, vReflectivityUV);
  65. #elif HAS_REFLECTIVITY
  66. // Reflectivity
  67. vec4 reflectivity = vec4(texture2D(reflectivitySampler, vReflectivityUV).rgb, 1.0);
  68. #else
  69. vec4 reflectivity = vec4(0.0, 0.0, 0.0, 1.0);
  70. #endif
  71. gl_FragData[REFLECTIVITY_INDEX] = reflectivity;
  72. #endif
  73. }