geometry.fragment.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // Do not edit.
  2. import { ShaderStore } from "../Engines/shaderStore.js";
  3. import "./ShadersInclude/clipPlaneFragmentDeclaration.js";
  4. import "./ShadersInclude/mrtFragmentDeclaration.js";
  5. import "./ShadersInclude/bumpFragmentMainFunctions.js";
  6. import "./ShadersInclude/bumpFragmentFunctions.js";
  7. import "./ShadersInclude/helperFunctions.js";
  8. import "./ShadersInclude/clipPlaneFragment.js";
  9. import "./ShadersInclude/bumpFragment.js";
  10. const name = "geometryPixelShader";
  11. const shader = `#extension GL_EXT_draw_buffers : require
  12. #if defined(BUMP) || !defined(NORMAL)
  13. #extension GL_OES_standard_derivatives : enable
  14. #endif
  15. precision highp float;
  16. #ifdef BUMP
  17. varying mat4 vWorldView;varying vec3 vNormalW;
  18. #else
  19. varying vec3 vNormalV;
  20. #endif
  21. varying vec4 vViewPos;
  22. #if defined(POSITION) || defined(BUMP)
  23. varying vec3 vPositionW;
  24. #endif
  25. #ifdef VELOCITY
  26. varying vec4 vCurrentPosition;varying vec4 vPreviousPosition;
  27. #endif
  28. #ifdef NEED_UV
  29. varying vec2 vUV;
  30. #endif
  31. #ifdef BUMP
  32. uniform vec3 vBumpInfos;uniform vec2 vTangentSpaceParams;
  33. #endif
  34. #if defined(REFLECTIVITY)
  35. #if defined(ORMTEXTURE) || defined(SPECULARGLOSSINESSTEXTURE) || defined(REFLECTIVITYTEXTURE)
  36. uniform sampler2D reflectivitySampler;varying vec2 vReflectivityUV;
  37. #endif
  38. #ifdef ALBEDOTEXTURE
  39. varying vec2 vAlbedoUV;uniform sampler2D albedoSampler;
  40. #endif
  41. #ifdef REFLECTIVITYCOLOR
  42. uniform vec3 reflectivityColor;
  43. #endif
  44. #ifdef ALBEDOCOLOR
  45. uniform vec3 albedoColor;
  46. #endif
  47. #ifdef METALLIC
  48. uniform float metallic;
  49. #endif
  50. #if defined(ROUGHNESS) || defined(GLOSSINESS)
  51. uniform float glossiness;
  52. #endif
  53. #endif
  54. #if defined(ALPHATEST) && defined(NEED_UV)
  55. uniform sampler2D diffuseSampler;
  56. #endif
  57. #include<clipPlaneFragmentDeclaration>
  58. #include<mrtFragmentDeclaration>[RENDER_TARGET_COUNT]
  59. #include<bumpFragmentMainFunctions>
  60. #include<bumpFragmentFunctions>
  61. #include<helperFunctions>
  62. void main() {
  63. #include<clipPlaneFragment>
  64. #ifdef ALPHATEST
  65. if (texture2D(diffuseSampler,vUV).a<0.4)
  66. discard;
  67. #endif
  68. vec3 normalOutput;
  69. #ifdef BUMP
  70. vec3 normalW=normalize(vNormalW);
  71. #include<bumpFragment>
  72. #ifdef NORMAL_WORLDSPACE
  73. normalOutput=normalW;
  74. #else
  75. normalOutput=normalize(vec3(vWorldView*vec4(normalW,0.0)));
  76. #endif
  77. #else
  78. normalOutput=normalize(vNormalV);
  79. #endif
  80. #ifdef ENCODE_NORMAL
  81. normalOutput=normalOutput*0.5+0.5;
  82. #endif
  83. #ifdef PREPASS
  84. #ifdef PREPASS_DEPTH
  85. gl_FragData[DEPTH_INDEX]=vec4(vViewPos.z/vViewPos.w,0.0,0.0,1.0);
  86. #endif
  87. #ifdef PREPASS_NORMAL
  88. gl_FragData[NORMAL_INDEX]=vec4(normalOutput,1.0);
  89. #endif
  90. #else
  91. gl_FragData[0]=vec4(vViewPos.z/vViewPos.w,0.0,0.0,1.0);gl_FragData[1]=vec4(normalOutput,1.0);
  92. #endif
  93. #ifdef POSITION
  94. gl_FragData[POSITION_INDEX]=vec4(vPositionW,1.0);
  95. #endif
  96. #ifdef VELOCITY
  97. vec2 a=(vCurrentPosition.xy/vCurrentPosition.w)*0.5+0.5;vec2 b=(vPreviousPosition.xy/vPreviousPosition.w)*0.5+0.5;vec2 velocity=abs(a-b);velocity=vec2(pow(velocity.x,1.0/3.0),pow(velocity.y,1.0/3.0))*sign(a-b)*0.5+0.5;gl_FragData[VELOCITY_INDEX]=vec4(velocity,0.0,1.0);
  98. #endif
  99. #ifdef REFLECTIVITY
  100. vec4 reflectivity=vec4(0.0,0.0,0.0,1.0);
  101. #ifdef METALLICWORKFLOW
  102. float metal=1.0;float roughness=1.0;
  103. #ifdef ORMTEXTURE
  104. metal*=texture2D(reflectivitySampler,vReflectivityUV).b;roughness*=texture2D(reflectivitySampler,vReflectivityUV).g;
  105. #endif
  106. #ifdef METALLIC
  107. metal*=metallic;
  108. #endif
  109. #ifdef ROUGHNESS
  110. roughness*=(1.0-glossiness);
  111. #endif
  112. reflectivity.a-=roughness;vec3 color=vec3(1.0);
  113. #ifdef ALBEDOTEXTURE
  114. color=texture2D(albedoSampler,vAlbedoUV).rgb;
  115. #ifdef GAMMAALBEDO
  116. color=toLinearSpace(color);
  117. #endif
  118. #endif
  119. #ifdef ALBEDOCOLOR
  120. color*=albedoColor.xyz;
  121. #endif
  122. reflectivity.rgb=mix(vec3(0.04),color,metal);
  123. #else
  124. #if defined(SPECULARGLOSSINESSTEXTURE) || defined(REFLECTIVITYTEXTURE)
  125. reflectivity=texture2D(reflectivitySampler,vReflectivityUV);
  126. #ifdef GAMMAREFLECTIVITYTEXTURE
  127. reflectivity.rgb=toLinearSpace(reflectivity.rgb);
  128. #endif
  129. #else
  130. #ifdef REFLECTIVITYCOLOR
  131. reflectivity.rgb=toLinearSpace(reflectivityColor.xyz);reflectivity.a=1.0;
  132. #endif
  133. #endif
  134. #ifdef GLOSSINESSS
  135. reflectivity.a*=glossiness;
  136. #endif
  137. #endif
  138. gl_FragData[REFLECTIVITY_INDEX]=reflectivity;
  139. #endif
  140. }
  141. `;
  142. // Sideeffect
  143. ShaderStore.ShadersStore[name] = shader;
  144. /** @internal */
  145. export const geometryPixelShader = { name, shader };
  146. //# sourceMappingURL=geometry.fragment.js.map