pbrBlockReflection.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. // Do not edit.
  2. import { ShaderStore } from "../../Engines/shaderStore.js";
  3. const name = "pbrBlockReflection";
  4. const shader = `#ifdef REFLECTION
  5. struct reflectionOutParams
  6. {vec4 environmentRadiance;vec3 environmentIrradiance;
  7. #ifdef REFLECTIONMAP_3D
  8. vec3 reflectionCoords;
  9. #else
  10. vec2 reflectionCoords;
  11. #endif
  12. #ifdef SS_TRANSLUCENCY
  13. #ifdef USESPHERICALFROMREFLECTIONMAP
  14. #if !defined(NORMAL) || !defined(USESPHERICALINVERTEX)
  15. vec3 irradianceVector;
  16. #endif
  17. #endif
  18. #endif
  19. };
  20. #define pbr_inline
  21. void createReflectionCoords(
  22. in vec3 vPositionW,
  23. in vec3 normalW,
  24. #ifdef ANISOTROPIC
  25. in anisotropicOutParams anisotropicOut,
  26. #endif
  27. #ifdef REFLECTIONMAP_3D
  28. out vec3 reflectionCoords
  29. #else
  30. out vec2 reflectionCoords
  31. #endif
  32. )
  33. {
  34. #ifdef ANISOTROPIC
  35. vec3 reflectionVector=computeReflectionCoords(vec4(vPositionW,1.0),anisotropicOut.anisotropicNormal);
  36. #else
  37. vec3 reflectionVector=computeReflectionCoords(vec4(vPositionW,1.0),normalW);
  38. #endif
  39. #ifdef REFLECTIONMAP_OPPOSITEZ
  40. reflectionVector.z*=-1.0;
  41. #endif
  42. #ifdef REFLECTIONMAP_3D
  43. reflectionCoords=reflectionVector;
  44. #else
  45. reflectionCoords=reflectionVector.xy;
  46. #ifdef REFLECTIONMAP_PROJECTION
  47. reflectionCoords/=reflectionVector.z;
  48. #endif
  49. reflectionCoords.y=1.0-reflectionCoords.y;
  50. #endif
  51. }
  52. #define pbr_inline
  53. #define inline
  54. void sampleReflectionTexture(
  55. in float alphaG,
  56. in vec3 vReflectionMicrosurfaceInfos,
  57. in vec2 vReflectionInfos,
  58. in vec3 vReflectionColor,
  59. #if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)
  60. in float NdotVUnclamped,
  61. #endif
  62. #ifdef LINEARSPECULARREFLECTION
  63. in float roughness,
  64. #endif
  65. #ifdef REFLECTIONMAP_3D
  66. in samplerCube reflectionSampler,
  67. const vec3 reflectionCoords,
  68. #else
  69. in sampler2D reflectionSampler,
  70. const vec2 reflectionCoords,
  71. #endif
  72. #ifndef LODBASEDMICROSFURACE
  73. #ifdef REFLECTIONMAP_3D
  74. in samplerCube reflectionSamplerLow,
  75. in samplerCube reflectionSamplerHigh,
  76. #else
  77. in sampler2D reflectionSamplerLow,
  78. in sampler2D reflectionSamplerHigh,
  79. #endif
  80. #endif
  81. #ifdef REALTIME_FILTERING
  82. in vec2 vReflectionFilteringInfo,
  83. #endif
  84. out vec4 environmentRadiance
  85. )
  86. {
  87. #if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)
  88. float reflectionLOD=getLodFromAlphaG(vReflectionMicrosurfaceInfos.x,alphaG,NdotVUnclamped);
  89. #elif defined(LINEARSPECULARREFLECTION)
  90. float reflectionLOD=getLinearLodFromRoughness(vReflectionMicrosurfaceInfos.x,roughness);
  91. #else
  92. float reflectionLOD=getLodFromAlphaG(vReflectionMicrosurfaceInfos.x,alphaG);
  93. #endif
  94. #ifdef LODBASEDMICROSFURACE
  95. reflectionLOD=reflectionLOD*vReflectionMicrosurfaceInfos.y+vReflectionMicrosurfaceInfos.z;
  96. #ifdef LODINREFLECTIONALPHA
  97. float automaticReflectionLOD=UNPACK_LOD(sampleReflection(reflectionSampler,reflectionCoords).a);float requestedReflectionLOD=max(automaticReflectionLOD,reflectionLOD);
  98. #else
  99. float requestedReflectionLOD=reflectionLOD;
  100. #endif
  101. #ifdef REALTIME_FILTERING
  102. environmentRadiance=vec4(radiance(alphaG,reflectionSampler,reflectionCoords,vReflectionFilteringInfo),1.0);
  103. #else
  104. environmentRadiance=sampleReflectionLod(reflectionSampler,reflectionCoords,reflectionLOD);
  105. #endif
  106. #else
  107. float lodReflectionNormalized=saturate(reflectionLOD/log2(vReflectionMicrosurfaceInfos.x));float lodReflectionNormalizedDoubled=lodReflectionNormalized*2.0;vec4 environmentMid=sampleReflection(reflectionSampler,reflectionCoords);if (lodReflectionNormalizedDoubled<1.0){environmentRadiance=mix(
  108. sampleReflection(reflectionSamplerHigh,reflectionCoords),
  109. environmentMid,
  110. lodReflectionNormalizedDoubled
  111. );} else {environmentRadiance=mix(
  112. environmentMid,
  113. sampleReflection(reflectionSamplerLow,reflectionCoords),
  114. lodReflectionNormalizedDoubled-1.0
  115. );}
  116. #endif
  117. #ifdef RGBDREFLECTION
  118. environmentRadiance.rgb=fromRGBD(environmentRadiance);
  119. #endif
  120. #ifdef GAMMAREFLECTION
  121. environmentRadiance.rgb=toLinearSpace(environmentRadiance.rgb);
  122. #endif
  123. environmentRadiance.rgb*=vReflectionInfos.x;environmentRadiance.rgb*=vReflectionColor.rgb;}
  124. #define pbr_inline
  125. #define inline
  126. void reflectionBlock(
  127. in vec3 vPositionW,
  128. in vec3 normalW,
  129. in float alphaG,
  130. in vec3 vReflectionMicrosurfaceInfos,
  131. in vec2 vReflectionInfos,
  132. in vec3 vReflectionColor,
  133. #ifdef ANISOTROPIC
  134. in anisotropicOutParams anisotropicOut,
  135. #endif
  136. #if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)
  137. in float NdotVUnclamped,
  138. #endif
  139. #ifdef LINEARSPECULARREFLECTION
  140. in float roughness,
  141. #endif
  142. #ifdef REFLECTIONMAP_3D
  143. in samplerCube reflectionSampler,
  144. #else
  145. in sampler2D reflectionSampler,
  146. #endif
  147. #if defined(NORMAL) && defined(USESPHERICALINVERTEX)
  148. in vec3 vEnvironmentIrradiance,
  149. #endif
  150. #ifdef USESPHERICALFROMREFLECTIONMAP
  151. #if !defined(NORMAL) || !defined(USESPHERICALINVERTEX)
  152. in mat4 reflectionMatrix,
  153. #endif
  154. #endif
  155. #ifdef USEIRRADIANCEMAP
  156. #ifdef REFLECTIONMAP_3D
  157. in samplerCube irradianceSampler,
  158. #else
  159. in sampler2D irradianceSampler,
  160. #endif
  161. #endif
  162. #ifndef LODBASEDMICROSFURACE
  163. #ifdef REFLECTIONMAP_3D
  164. in samplerCube reflectionSamplerLow,
  165. in samplerCube reflectionSamplerHigh,
  166. #else
  167. in sampler2D reflectionSamplerLow,
  168. in sampler2D reflectionSamplerHigh,
  169. #endif
  170. #endif
  171. #ifdef REALTIME_FILTERING
  172. in vec2 vReflectionFilteringInfo,
  173. #endif
  174. out reflectionOutParams outParams
  175. )
  176. {vec4 environmentRadiance=vec4(0.,0.,0.,0.);
  177. #ifdef REFLECTIONMAP_3D
  178. vec3 reflectionCoords=vec3(0.);
  179. #else
  180. vec2 reflectionCoords=vec2(0.);
  181. #endif
  182. createReflectionCoords(
  183. vPositionW,
  184. normalW,
  185. #ifdef ANISOTROPIC
  186. anisotropicOut,
  187. #endif
  188. reflectionCoords
  189. );sampleReflectionTexture(
  190. alphaG,
  191. vReflectionMicrosurfaceInfos,
  192. vReflectionInfos,
  193. vReflectionColor,
  194. #if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)
  195. NdotVUnclamped,
  196. #endif
  197. #ifdef LINEARSPECULARREFLECTION
  198. roughness,
  199. #endif
  200. #ifdef REFLECTIONMAP_3D
  201. reflectionSampler,
  202. reflectionCoords,
  203. #else
  204. reflectionSampler,
  205. reflectionCoords,
  206. #endif
  207. #ifndef LODBASEDMICROSFURACE
  208. reflectionSamplerLow,
  209. reflectionSamplerHigh,
  210. #endif
  211. #ifdef REALTIME_FILTERING
  212. vReflectionFilteringInfo,
  213. #endif
  214. environmentRadiance
  215. );vec3 environmentIrradiance=vec3(0.,0.,0.);
  216. #ifdef USESPHERICALFROMREFLECTIONMAP
  217. #if defined(NORMAL) && defined(USESPHERICALINVERTEX)
  218. environmentIrradiance=vEnvironmentIrradiance;
  219. #else
  220. #ifdef ANISOTROPIC
  221. vec3 irradianceVector=vec3(reflectionMatrix*vec4(anisotropicOut.anisotropicNormal,0)).xyz;
  222. #else
  223. vec3 irradianceVector=vec3(reflectionMatrix*vec4(normalW,0)).xyz;
  224. #endif
  225. #ifdef REFLECTIONMAP_OPPOSITEZ
  226. irradianceVector.z*=-1.0;
  227. #endif
  228. #ifdef INVERTCUBICMAP
  229. irradianceVector.y*=-1.0;
  230. #endif
  231. #if defined(REALTIME_FILTERING)
  232. environmentIrradiance=irradiance(reflectionSampler,irradianceVector,vReflectionFilteringInfo);
  233. #else
  234. environmentIrradiance=computeEnvironmentIrradiance(irradianceVector);
  235. #endif
  236. #ifdef SS_TRANSLUCENCY
  237. outParams.irradianceVector=irradianceVector;
  238. #endif
  239. #endif
  240. #elif defined(USEIRRADIANCEMAP)
  241. vec4 environmentIrradiance4=sampleReflection(irradianceSampler,reflectionCoords);environmentIrradiance=environmentIrradiance4.rgb;
  242. #ifdef RGBDREFLECTION
  243. environmentIrradiance.rgb=fromRGBD(environmentIrradiance4);
  244. #endif
  245. #ifdef GAMMAREFLECTION
  246. environmentIrradiance.rgb=toLinearSpace(environmentIrradiance.rgb);
  247. #endif
  248. #endif
  249. environmentIrradiance*=vReflectionColor.rgb;outParams.environmentRadiance=environmentRadiance;outParams.environmentIrradiance=environmentIrradiance;outParams.reflectionCoords=reflectionCoords;}
  250. #endif
  251. `;
  252. // Sideeffect
  253. ShaderStore.IncludesShadersStore[name] = shader;
  254. /** @internal */
  255. export const pbrBlockReflection = { name, shader };
  256. //# sourceMappingURL=pbrBlockReflection.js.map