@graphty/graphty-element 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/README.md +9 -0
  2. package/dist/basisTextureLoader-BqIvxvNl.js +312 -0
  3. package/dist/basisTextureLoader-BqIvxvNl.js.map +1 -0
  4. package/dist/custom-elements.json +1 -0
  5. package/dist/dds-BlAaKjyJ.js +357 -0
  6. package/dist/dds-BlAaKjyJ.js.map +1 -0
  7. package/dist/ddsTextureLoader-D7Jh83wc.js +44 -0
  8. package/dist/ddsTextureLoader-D7Jh83wc.js.map +1 -0
  9. package/dist/default.fragment-BNc4beoN.js +452 -0
  10. package/dist/default.fragment-BNc4beoN.js.map +1 -0
  11. package/dist/default.fragment-CSeCDRwv.js +512 -0
  12. package/dist/default.fragment-CSeCDRwv.js.map +1 -0
  13. package/dist/default.vertex-9pBFrn06.js +202 -0
  14. package/dist/default.vertex-9pBFrn06.js.map +1 -0
  15. package/dist/default.vertex-DDjK1DRv.js +185 -0
  16. package/dist/default.vertex-DDjK1DRv.js.map +1 -0
  17. package/dist/defaultUboDeclaration-CG47IDRY.js +9 -0
  18. package/dist/defaultUboDeclaration-CG47IDRY.js.map +1 -0
  19. package/dist/defaultUboDeclaration-Ct5CiQ-w.js +11 -0
  20. package/dist/defaultUboDeclaration-Ct5CiQ-w.js.map +1 -0
  21. package/dist/dumpTools-DA1xMSIZ.js +103 -0
  22. package/dist/dumpTools-DA1xMSIZ.js.map +1 -0
  23. package/dist/envTextureLoader-DdCLpySN.js +238 -0
  24. package/dist/envTextureLoader-DdCLpySN.js.map +1 -0
  25. package/dist/exrTextureLoader-CnJSRQ9w.js +741 -0
  26. package/dist/exrTextureLoader-CnJSRQ9w.js.map +1 -0
  27. package/dist/graphty.js +12 -0
  28. package/dist/graphty.js.map +1 -0
  29. package/dist/graphty.umd.cjs +12657 -0
  30. package/dist/graphty.umd.cjs.map +1 -0
  31. package/dist/greasedLine.fragment-BZnGGe-r.js +30 -0
  32. package/dist/greasedLine.fragment-BZnGGe-r.js.map +1 -0
  33. package/dist/greasedLine.fragment-DixuqXus.js +12 -0
  34. package/dist/greasedLine.fragment-DixuqXus.js.map +1 -0
  35. package/dist/greasedLine.vertex-BhhwFKPy.js +33 -0
  36. package/dist/greasedLine.vertex-BhhwFKPy.js.map +1 -0
  37. package/dist/greasedLine.vertex-DIhgGSOi.js +49 -0
  38. package/dist/greasedLine.vertex-DIhgGSOi.js.map +1 -0
  39. package/dist/harmonicsFunctions-B9jTNKTF.js +197 -0
  40. package/dist/harmonicsFunctions-B9jTNKTF.js.map +1 -0
  41. package/dist/harmonicsFunctions-D9ZL5yLA.js +194 -0
  42. package/dist/harmonicsFunctions-D9ZL5yLA.js.map +1 -0
  43. package/dist/hdrTextureLoader-DreWCvHD.js +112 -0
  44. package/dist/hdrTextureLoader-DreWCvHD.js.map +1 -0
  45. package/dist/helperFunctions-Dh1WD8YN.js +106 -0
  46. package/dist/helperFunctions-Dh1WD8YN.js.map +1 -0
  47. package/dist/helperFunctions-ZBnqb-in.js +79 -0
  48. package/dist/helperFunctions-ZBnqb-in.js.map +1 -0
  49. package/dist/iesTextureLoader-JdfAyRK-.js +94 -0
  50. package/dist/iesTextureLoader-JdfAyRK-.js.map +1 -0
  51. package/dist/index-ChGTkj2q.js +62191 -0
  52. package/dist/index-ChGTkj2q.js.map +1 -0
  53. package/dist/instancesVertex-BrWNnWxF.js +46 -0
  54. package/dist/instancesVertex-BrWNnWxF.js.map +1 -0
  55. package/dist/instancesVertex-evcSIvCA.js +55 -0
  56. package/dist/instancesVertex-evcSIvCA.js.map +1 -0
  57. package/dist/ktxTextureLoader-Dg1h0a-4.js +520 -0
  58. package/dist/ktxTextureLoader-Dg1h0a-4.js.map +1 -0
  59. package/dist/logDepthDeclaration-BHUUDd5l.js +12 -0
  60. package/dist/logDepthDeclaration-BHUUDd5l.js.map +1 -0
  61. package/dist/logDepthDeclaration-Bou5AJOP.js +28 -0
  62. package/dist/logDepthDeclaration-Bou5AJOP.js.map +1 -0
  63. package/dist/logDepthVertex-CCFGLExi.js +496 -0
  64. package/dist/logDepthVertex-CCFGLExi.js.map +1 -0
  65. package/dist/logDepthVertex-r_niddz9.js +496 -0
  66. package/dist/logDepthVertex-r_niddz9.js.map +1 -0
  67. package/dist/mesh.vertexData.functions-Bc9lJlrU.js +75 -0
  68. package/dist/mesh.vertexData.functions-Bc9lJlrU.js.map +1 -0
  69. package/dist/meshUboDeclaration-Dg__Mhmj.js +18 -0
  70. package/dist/meshUboDeclaration-Dg__Mhmj.js.map +1 -0
  71. package/dist/oitFragment-Bn29Ggvj.js +1191 -0
  72. package/dist/oitFragment-Bn29Ggvj.js.map +1 -0
  73. package/dist/oitFragment-D6JBEGk0.js +1328 -0
  74. package/dist/oitFragment-D6JBEGk0.js.map +1 -0
  75. package/dist/pass.fragment-C9O4ZLJL.js +11 -0
  76. package/dist/pass.fragment-C9O4ZLJL.js.map +1 -0
  77. package/dist/pass.fragment-Cf0ob1Y3.js +11 -0
  78. package/dist/pass.fragment-Cf0ob1Y3.js.map +1 -0
  79. package/dist/passCube.fragment-Mg8Qj5T9.js +30 -0
  80. package/dist/passCube.fragment-Mg8Qj5T9.js.map +1 -0
  81. package/dist/passCube.fragment-uM4B7TOI.js +30 -0
  82. package/dist/passCube.fragment-uM4B7TOI.js.map +1 -0
  83. package/dist/pbr.fragment-C8Lm3cwF.js +3176 -0
  84. package/dist/pbr.fragment-C8Lm3cwF.js.map +1 -0
  85. package/dist/pbr.fragment-siOdCYqI.js +3219 -0
  86. package/dist/pbr.fragment-siOdCYqI.js.map +1 -0
  87. package/dist/pbr.vertex-Bw_TrGQv.js +229 -0
  88. package/dist/pbr.vertex-Bw_TrGQv.js.map +1 -0
  89. package/dist/pbr.vertex-CmEPCcBW.js +365 -0
  90. package/dist/pbr.vertex-CmEPCcBW.js.map +1 -0
  91. package/dist/postprocess.vertex-B086G8mM.js +16 -0
  92. package/dist/postprocess.vertex-B086G8mM.js.map +1 -0
  93. package/dist/rgbdDecode.fragment-bNaGtQ-x.js +9 -0
  94. package/dist/rgbdDecode.fragment-bNaGtQ-x.js.map +1 -0
  95. package/dist/rgbdDecode.fragment-koAcppx0.js +9 -0
  96. package/dist/rgbdDecode.fragment-koAcppx0.js.map +1 -0
  97. package/dist/rgbdEncode.fragment-BDHL2P_i.js +9 -0
  98. package/dist/rgbdEncode.fragment-BDHL2P_i.js.map +1 -0
  99. package/dist/rgbdEncode.fragment-Dw0FS9aH.js +9 -0
  100. package/dist/rgbdEncode.fragment-Dw0FS9aH.js.map +1 -0
  101. package/dist/tgaTextureLoader-DIfkfgQh.js +199 -0
  102. package/dist/tgaTextureLoader-DIfkfgQh.js.map +1 -0
  103. package/package.json +124 -0
@@ -0,0 +1,3176 @@
1
+ import { S as e } from "./index-ChGTkj2q.js";
2
+ import "./oitFragment-Bn29Ggvj.js";
3
+ import "./harmonicsFunctions-B9jTNKTF.js";
4
+ import "./logDepthDeclaration-BHUUDd5l.js";
5
+ import "./helperFunctions-ZBnqb-in.js";
6
+ const r = "pbrFragmentExtraDeclaration", y = `varying vPositionW: vec3f;
7
+ #if DEBUGMODE>0
8
+ varying vClipSpacePosition: vec4f;
9
+ #endif
10
+ #include<mainUVVaryingDeclaration>[1..7]
11
+ #ifdef NORMAL
12
+ varying vNormalW: vec3f;
13
+ #if defined(USESPHERICALFROMREFLECTIONMAP) && defined(USESPHERICALINVERTEX)
14
+ varying vEnvironmentIrradiance: vec3f;
15
+ #endif
16
+ #endif
17
+ #if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)
18
+ varying vColor: vec4f;
19
+ #endif
20
+ `;
21
+ e.IncludesShadersStoreWGSL[r] || (e.IncludesShadersStoreWGSL[r] = y);
22
+ const a = "samplerFragmentAlternateDeclaration", V = `#ifdef _DEFINENAME_
23
+ #if _DEFINENAME_DIRECTUV==1
24
+ #define v_VARYINGNAME_UV vMainUV1
25
+ #elif _DEFINENAME_DIRECTUV==2
26
+ #define v_VARYINGNAME_UV vMainUV2
27
+ #elif _DEFINENAME_DIRECTUV==3
28
+ #define v_VARYINGNAME_UV vMainUV3
29
+ #elif _DEFINENAME_DIRECTUV==4
30
+ #define v_VARYINGNAME_UV vMainUV4
31
+ #elif _DEFINENAME_DIRECTUV==5
32
+ #define v_VARYINGNAME_UV vMainUV5
33
+ #elif _DEFINENAME_DIRECTUV==6
34
+ #define v_VARYINGNAME_UV vMainUV6
35
+ #else
36
+ varying v_VARYINGNAME_UV: vec2f;
37
+ #endif
38
+ #endif
39
+ `;
40
+ e.IncludesShadersStoreWGSL[a] || (e.IncludesShadersStoreWGSL[a] = V);
41
+ const n = "pbrFragmentSamplersDeclaration", x = `#include<samplerFragmentDeclaration>(_DEFINENAME_,ALBEDO,_VARYINGNAME_,Albedo,_SAMPLERNAME_,albedo)
42
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,BASE_WEIGHT,_VARYINGNAME_,BaseWeight,_SAMPLERNAME_,baseWeight)
43
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,BASE_DIFFUSE_ROUGHNESS,_VARYINGNAME_,BaseDiffuseRoughness,_SAMPLERNAME_,baseDiffuseRoughness)
44
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,AMBIENT,_VARYINGNAME_,Ambient,_SAMPLERNAME_,ambient)
45
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,OPACITY,_VARYINGNAME_,Opacity,_SAMPLERNAME_,opacity)
46
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,EMISSIVE,_VARYINGNAME_,Emissive,_SAMPLERNAME_,emissive)
47
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,LIGHTMAP,_VARYINGNAME_,Lightmap,_SAMPLERNAME_,lightmap)
48
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,REFLECTIVITY,_VARYINGNAME_,Reflectivity,_SAMPLERNAME_,reflectivity)
49
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,MICROSURFACEMAP,_VARYINGNAME_,MicroSurfaceSampler,_SAMPLERNAME_,microSurface)
50
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,METALLIC_REFLECTANCE,_VARYINGNAME_,MetallicReflectance,_SAMPLERNAME_,metallicReflectance)
51
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,REFLECTANCE,_VARYINGNAME_,Reflectance,_SAMPLERNAME_,reflectance)
52
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,DECAL,_VARYINGNAME_,Decal,_SAMPLERNAME_,decal)
53
+ #ifdef CLEARCOAT
54
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,CLEARCOAT_TEXTURE,_VARYINGNAME_,ClearCoat,_SAMPLERNAME_,clearCoat)
55
+ #include<samplerFragmentAlternateDeclaration>(_DEFINENAME_,CLEARCOAT_TEXTURE_ROUGHNESS,_VARYINGNAME_,ClearCoatRoughness)
56
+ #if defined(CLEARCOAT_TEXTURE_ROUGHNESS)
57
+ var clearCoatRoughnessSamplerSampler: sampler;var clearCoatRoughnessSampler: texture_2d<f32>;
58
+ #endif
59
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,CLEARCOAT_BUMP,_VARYINGNAME_,ClearCoatBump,_SAMPLERNAME_,clearCoatBump)
60
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,CLEARCOAT_TINT_TEXTURE,_VARYINGNAME_,ClearCoatTint,_SAMPLERNAME_,clearCoatTint)
61
+ #endif
62
+ #ifdef IRIDESCENCE
63
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,IRIDESCENCE_TEXTURE,_VARYINGNAME_,Iridescence,_SAMPLERNAME_,iridescence)
64
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,IRIDESCENCE_THICKNESS_TEXTURE,_VARYINGNAME_,IridescenceThickness,_SAMPLERNAME_,iridescenceThickness)
65
+ #endif
66
+ #ifdef SHEEN
67
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,SHEEN_TEXTURE,_VARYINGNAME_,Sheen,_SAMPLERNAME_,sheen)
68
+ #include<samplerFragmentAlternateDeclaration>(_DEFINENAME_,SHEEN_TEXTURE_ROUGHNESS,_VARYINGNAME_,SheenRoughness)
69
+ #if defined(SHEEN_ROUGHNESS) && defined(SHEEN_TEXTURE_ROUGHNESS)
70
+ var sheenRoughnessSamplerSampler: sampler;var sheenRoughnessSampler: texture_2d<f32>;
71
+ #endif
72
+ #endif
73
+ #ifdef ANISOTROPIC
74
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,ANISOTROPIC_TEXTURE,_VARYINGNAME_,Anisotropy,_SAMPLERNAME_,anisotropy)
75
+ #endif
76
+ #ifdef REFLECTION
77
+ #ifdef REFLECTIONMAP_3D
78
+ var reflectionSamplerSampler: sampler;var reflectionSampler: texture_cube<f32>;
79
+ #ifdef LODBASEDMICROSFURACE
80
+ #else
81
+ var reflectionLowSamplerSampler: sampler;var reflectionLowSampler: texture_cube<f32>;var reflectionHighSamplerSampler: sampler;var reflectionHighSampler: texture_cube<f32>;
82
+ #endif
83
+ #ifdef USEIRRADIANCEMAP
84
+ var irradianceSamplerSampler: sampler;var irradianceSampler: texture_cube<f32>;
85
+ #endif
86
+ #else
87
+ var reflectionSamplerSampler: sampler;var reflectionSampler: texture_2d<f32>;
88
+ #ifdef LODBASEDMICROSFURACE
89
+ #else
90
+ var reflectionLowSamplerSampler: sampler;var reflectionLowSampler: texture_2d<f32>;var reflectionHighSamplerSampler: sampler;var reflectionHighSampler: texture_2d<f32>;
91
+ #endif
92
+ #ifdef USEIRRADIANCEMAP
93
+ var irradianceSamplerSampler: sampler;var irradianceSampler: texture_2d<f32>;
94
+ #endif
95
+ #endif
96
+ #ifdef REFLECTIONMAP_SKYBOX
97
+ varying vPositionUVW: vec3f;
98
+ #else
99
+ #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)
100
+ varying vDirectionW: vec3f;
101
+ #endif
102
+ #endif
103
+ #endif
104
+ #ifdef ENVIRONMENTBRDF
105
+ var environmentBrdfSamplerSampler: sampler;var environmentBrdfSampler: texture_2d<f32>;
106
+ #endif
107
+ #ifdef SUBSURFACE
108
+ #ifdef SS_REFRACTION
109
+ #ifdef SS_REFRACTIONMAP_3D
110
+ var refractionSamplerSampler: sampler;var refractionSampler: texture_cube<f32>;
111
+ #ifdef LODBASEDMICROSFURACE
112
+ #else
113
+ var refractionLowSamplerSampler: sampler;var refractionLowSampler: texture_cube<f32>;var refractionHighSamplerSampler: sampler;var refractionHighSampler: texture_cube<f32>;
114
+ #endif
115
+ #else
116
+ var refractionSamplerSampler: sampler;var refractionSampler: texture_2d<f32>;
117
+ #ifdef LODBASEDMICROSFURACE
118
+ #else
119
+ var refractionLowSamplerSampler: sampler;var refractionLowSampler: texture_2d<f32>;var refractionHighSamplerSampler: sampler;var refractionHighSampler: texture_2d<f32>;
120
+ #endif
121
+ #endif
122
+ #endif
123
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,SS_THICKNESSANDMASK_TEXTURE,_VARYINGNAME_,Thickness,_SAMPLERNAME_,thickness)
124
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,SS_REFRACTIONINTENSITY_TEXTURE,_VARYINGNAME_,RefractionIntensity,_SAMPLERNAME_,refractionIntensity)
125
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,SS_TRANSLUCENCYINTENSITY_TEXTURE,_VARYINGNAME_,TranslucencyIntensity,_SAMPLERNAME_,translucencyIntensity)
126
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,SS_TRANSLUCENCYCOLOR_TEXTURE,_VARYINGNAME_,TranslucencyColor,_SAMPLERNAME_,translucencyColor)
127
+ #endif
128
+ #ifdef IBL_CDF_FILTERING
129
+ var icdfSamplerSampler: sampler;var icdfSampler: texture_2d<f32>;
130
+ #endif
131
+ `;
132
+ e.IncludesShadersStoreWGSL[n] || (e.IncludesShadersStoreWGSL[n] = x);
133
+ const f = "subSurfaceScatteringFunctions", H = `fn testLightingForSSS(diffusionProfile: f32)->bool
134
+ {return diffusionProfile<1.;}`;
135
+ e.IncludesShadersStoreWGSL[f] || (e.IncludesShadersStoreWGSL[f] = H);
136
+ const t = "importanceSampling", W = `fn hemisphereCosSample(u: vec2f)->vec3f {var phi: f32=2.*PI*u.x;var cosTheta2: f32=1.-u.y;var cosTheta: f32=sqrt(cosTheta2);var sinTheta: f32=sqrt(1.-cosTheta2);return vec3f(sinTheta*cos(phi),sinTheta*sin(phi),cosTheta);}
137
+ fn hemisphereImportanceSampleDggx(u: vec2f,a: f32)->vec3f {var phi: f32=2.*PI*u.x;var cosTheta2: f32=(1.-u.y)/(1.+(a+1.)*((a-1.)*u.y));var cosTheta: f32=sqrt(cosTheta2);var sinTheta: f32=sqrt(1.-cosTheta2);return vec3f(sinTheta*cos(phi),sinTheta*sin(phi),cosTheta);}
138
+ fn hemisphereImportanceSampleDCharlie(u: vec2f,a: f32)->vec3f {
139
+ var phi: f32=2.*PI*u.x;var sinTheta: f32=pow(u.y,a/(2.*a+1.));var cosTheta: f32=sqrt(1.-sinTheta*sinTheta);return vec3f(sinTheta*cos(phi),sinTheta*sin(phi),cosTheta);}`;
140
+ e.IncludesShadersStoreWGSL[t] || (e.IncludesShadersStoreWGSL[t] = W);
141
+ const o = "pbrHelperFunctions", Y = `#define MINIMUMVARIANCE 0.0005
142
+ fn convertRoughnessToAverageSlope(roughness: f32)->f32
143
+ {return roughness*roughness+MINIMUMVARIANCE;}
144
+ fn fresnelGrazingReflectance(reflectance0: f32)->f32 {var reflectance90: f32=saturate(reflectance0*25.0);return reflectance90;}
145
+ fn getAARoughnessFactors(normalVector: vec3f)->vec2f {
146
+ #ifdef SPECULARAA
147
+ var nDfdx: vec3f=dpdx(normalVector.xyz);var nDfdy: vec3f=dpdy(normalVector.xyz);var slopeSquare: f32=max(dot(nDfdx,nDfdx),dot(nDfdy,nDfdy));var geometricRoughnessFactor: f32=pow(saturate(slopeSquare),0.333);var geometricAlphaGFactor: f32=sqrt(slopeSquare);geometricAlphaGFactor*=0.75;return vec2f(geometricRoughnessFactor,geometricAlphaGFactor);
148
+ #else
149
+ return vec2f(0.);
150
+ #endif
151
+ }
152
+ #ifdef ANISOTROPIC
153
+ #ifdef ANISOTROPIC_LEGACY
154
+ fn getAnisotropicRoughness(alphaG: f32,anisotropy: f32)->vec2f {var alphaT: f32=max(alphaG*(1.0+anisotropy),MINIMUMVARIANCE);var alphaB: f32=max(alphaG*(1.0-anisotropy),MINIMUMVARIANCE);return vec2f(alphaT,alphaB);}
155
+ fn getAnisotropicBentNormals(T: vec3f,B: vec3f,N: vec3f,V: vec3f,anisotropy: f32,roughness: f32)->vec3f {var anisotropicFrameDirection: vec3f=select(T,B,anisotropy>=0.0);var anisotropicFrameTangent: vec3f=cross(normalize(anisotropicFrameDirection),V);var anisotropicFrameNormal: vec3f=cross(anisotropicFrameTangent,anisotropicFrameDirection);var anisotropicNormal: vec3f=normalize(mix(N,anisotropicFrameNormal,abs(anisotropy)));return anisotropicNormal;}
156
+ #else
157
+ fn getAnisotropicRoughness(alphaG: f32,anisotropy: f32)->vec2f {var alphaT: f32=max(mix(alphaG,1.0,anisotropy*anisotropy),MINIMUMVARIANCE);var alphaB: f32=max(alphaG,MINIMUMVARIANCE);return vec2f(alphaT,alphaB);}
158
+ fn getAnisotropicBentNormals(T: vec3f,B: vec3f,N: vec3f,V: vec3f,anisotropy: f32,roughness: f32)->vec3f {var bentNormal: vec3f=cross(B,V);bentNormal=normalize(cross(bentNormal,B));var sq=1.0-anisotropy*(1.0-roughness);var a: f32=sq*sq*sq*sq;bentNormal=normalize(mix(bentNormal,N,a));return bentNormal;}
159
+ #endif
160
+ #endif
161
+ #if defined(CLEARCOAT) || defined(SS_REFRACTION)
162
+ fn cocaLambertVec3(alpha: vec3f,distance: f32)->vec3f {return exp(-alpha*distance);}
163
+ fn cocaLambert(NdotVRefract: f32,NdotLRefract: f32,alpha: vec3f,thickness: f32)->vec3f {return cocaLambertVec3(alpha,(thickness*((NdotLRefract+NdotVRefract)/(NdotLRefract*NdotVRefract))));}
164
+ fn computeColorAtDistanceInMedia(color: vec3f,distance: f32)->vec3f {return -log(color)/distance;}
165
+ fn computeClearCoatAbsorption(NdotVRefract: f32,NdotLRefract: f32,clearCoatColor: vec3f,clearCoatThickness: f32,clearCoatIntensity: f32)->vec3f {var clearCoatAbsorption: vec3f=mix( vec3f(1.0),
166
+ cocaLambert(NdotVRefract,NdotLRefract,clearCoatColor,clearCoatThickness),
167
+ clearCoatIntensity);return clearCoatAbsorption;}
168
+ #endif
169
+ #ifdef MICROSURFACEAUTOMATIC
170
+ fn computeDefaultMicroSurface(microSurface: f32,reflectivityColor: vec3f)->f32
171
+ {const kReflectivityNoAlphaWorkflow_SmoothnessMax: f32=0.95;var reflectivityLuminance: f32=getLuminance(reflectivityColor);var reflectivityLuma: f32=sqrt(reflectivityLuminance);var resultMicroSurface=reflectivityLuma*kReflectivityNoAlphaWorkflow_SmoothnessMax;return resultMicroSurface;}
172
+ #endif
173
+ `;
174
+ e.IncludesShadersStoreWGSL[o] || (e.IncludesShadersStoreWGSL[o] = Y);
175
+ const c = "pbrDirectLightingSetupFunctions", w = `struct preLightingInfo
176
+ {lightOffset: vec3f,
177
+ lightDistanceSquared: f32,
178
+ lightDistance: f32,
179
+ attenuation: f32,
180
+ L: vec3f,
181
+ H: vec3f,
182
+ NdotV: f32,
183
+ NdotLUnclamped: f32,
184
+ NdotL: f32,
185
+ VdotH: f32,
186
+ LdotV: f32,
187
+ roughness: f32,
188
+ diffuseRoughness: f32,
189
+ surfaceAlbedo: vec3f,
190
+ #ifdef IRIDESCENCE
191
+ iridescenceIntensity: f32
192
+ #endif
193
+ #if defined(AREALIGHTUSED) && defined(AREALIGHTSUPPORTED)
194
+ areaLightDiffuse: vec3f,
195
+ #ifdef SPECULARTERM
196
+ areaLightSpecular: vec3f,
197
+ areaLightFresnel: vec4f
198
+ #endif
199
+ #endif
200
+ };fn computePointAndSpotPreLightingInfo(lightData: vec4f,V: vec3f,N: vec3f,posW: vec3f)->preLightingInfo {var result: preLightingInfo;result.lightOffset=lightData.xyz-posW;result.lightDistanceSquared=dot(result.lightOffset,result.lightOffset);result.lightDistance=sqrt(result.lightDistanceSquared);result.L=normalize(result.lightOffset);result.H=normalize(V+result.L);result.VdotH=saturate(dot(V,result.H));result.NdotLUnclamped=dot(N,result.L);result.NdotL=saturateEps(result.NdotLUnclamped);return result;}
201
+ fn computeDirectionalPreLightingInfo(lightData: vec4f,V: vec3f,N: vec3f)->preLightingInfo {var result: preLightingInfo;result.lightDistance=length(-lightData.xyz);result.L=normalize(-lightData.xyz);result.H=normalize(V+result.L);result.VdotH=saturate(dot(V,result.H));result.NdotLUnclamped=dot(N,result.L);result.NdotL=saturateEps(result.NdotLUnclamped);result.LdotV=dot(result.L,V);return result;}
202
+ fn computeHemisphericPreLightingInfo(lightData: vec4f,V: vec3f,N: vec3f)->preLightingInfo {var result: preLightingInfo;result.NdotL=dot(N,lightData.xyz)*0.5+0.5;result.NdotL=saturateEps(result.NdotL);result.NdotLUnclamped=result.NdotL;
203
+ #ifdef SPECULARTERM
204
+ result.L=normalize(lightData.xyz);result.H=normalize(V+result.L);result.VdotH=saturate(dot(V,result.H));
205
+ #endif
206
+ return result;}
207
+ #if defined(AREALIGHTUSED) && defined(AREALIGHTSUPPORTED)
208
+ #include<ltcHelperFunctions>
209
+ var areaLightsLTC1SamplerSampler: sampler;var areaLightsLTC1Sampler: texture_2d<f32>;var areaLightsLTC2SamplerSampler: sampler;var areaLightsLTC2Sampler: texture_2d<f32>;fn computeAreaPreLightingInfo(ltc1: texture_2d<f32>,ltc1Sampler:sampler,ltc2:texture_2d<f32>,ltc2Sampler:sampler,viewDirectionW: vec3f,vNormal:vec3f,vPosition:vec3f,lightCenter:vec3f,halfWidth:vec3f, halfHeight:vec3f,roughness:f32)->preLightingInfo {var result: preLightingInfo;var data: areaLightData=computeAreaLightSpecularDiffuseFresnel(ltc1,ltc1Sampler,ltc2,ltc2Sampler,viewDirectionW,vNormal,vPosition,lightCenter,halfWidth,halfHeight,roughness);
210
+ #ifdef SPECULARTERM
211
+ result.areaLightFresnel=data.Fresnel;result.areaLightSpecular=data.Specular;
212
+ #endif
213
+ result.areaLightDiffuse+=data.Diffuse;return result;}
214
+ #endif
215
+ `;
216
+ e.IncludesShadersStoreWGSL[c] || (e.IncludesShadersStoreWGSL[c] = w);
217
+ const l = "pbrDirectLightingFalloffFunctions", X = `fn computeDistanceLightFalloff_Standard(lightOffset: vec3f,range: f32)->f32
218
+ {return max(0.,1.0-length(lightOffset)/range);}
219
+ fn computeDistanceLightFalloff_Physical(lightDistanceSquared: f32)->f32
220
+ {return 1.0/maxEps(lightDistanceSquared);}
221
+ fn computeDistanceLightFalloff_GLTF(lightDistanceSquared: f32,inverseSquaredRange: f32)->f32
222
+ {var lightDistanceFalloff: f32=1.0/maxEps(lightDistanceSquared);var factor: f32=lightDistanceSquared*inverseSquaredRange;var attenuation: f32=saturate(1.0-factor*factor);attenuation*=attenuation;lightDistanceFalloff*=attenuation;return lightDistanceFalloff;}
223
+ fn computeDirectionalLightFalloff_IES(lightDirection: vec3f,directionToLightCenterW: vec3f,iesLightTexture: texture_2d<f32>,iesLightTextureSampler: sampler)->f32
224
+ {var cosAngle: f32=dot(-lightDirection,directionToLightCenterW);var angle=acos(cosAngle)/PI;return textureSampleLevel(iesLightTexture,iesLightTextureSampler,vec2f(angle,0),0.).r;}
225
+ fn computeDistanceLightFalloff(lightOffset: vec3f,lightDistanceSquared: f32,range: f32,inverseSquaredRange: f32)->f32
226
+ {
227
+ #ifdef USEPHYSICALLIGHTFALLOFF
228
+ return computeDistanceLightFalloff_Physical(lightDistanceSquared);
229
+ #elif defined(USEGLTFLIGHTFALLOFF)
230
+ return computeDistanceLightFalloff_GLTF(lightDistanceSquared,inverseSquaredRange);
231
+ #else
232
+ return computeDistanceLightFalloff_Standard(lightOffset,range);
233
+ #endif
234
+ }
235
+ fn computeDirectionalLightFalloff_Standard(lightDirection: vec3f,directionToLightCenterW: vec3f,cosHalfAngle: f32,exponent: f32)->f32
236
+ {var falloff: f32=0.0;var cosAngle: f32=maxEps(dot(-lightDirection,directionToLightCenterW));if (cosAngle>=cosHalfAngle)
237
+ {falloff=max(0.,pow(cosAngle,exponent));}
238
+ return falloff;}
239
+ fn computeDirectionalLightFalloff_Physical(lightDirection: vec3f,directionToLightCenterW: vec3f,cosHalfAngle: f32)->f32
240
+ {const kMinusLog2ConeAngleIntensityRatio: f32=6.64385618977;
241
+ var concentrationKappa: f32=kMinusLog2ConeAngleIntensityRatio/(1.0-cosHalfAngle);var lightDirectionSpreadSG: vec4f= vec4f(-lightDirection*concentrationKappa,-concentrationKappa);var falloff: f32=exp2(dot( vec4f(directionToLightCenterW,1.0),lightDirectionSpreadSG));return falloff;}
242
+ fn computeDirectionalLightFalloff_GLTF(lightDirection: vec3f,directionToLightCenterW: vec3f,lightAngleScale: f32,lightAngleOffset: f32)->f32
243
+ {var cd: f32=dot(-lightDirection,directionToLightCenterW);var falloff: f32=saturate(cd*lightAngleScale+lightAngleOffset);falloff*=falloff;return falloff;}
244
+ fn computeDirectionalLightFalloff(lightDirection: vec3f,directionToLightCenterW: vec3f,cosHalfAngle: f32,exponent: f32,lightAngleScale: f32,lightAngleOffset: f32)->f32
245
+ {
246
+ #ifdef USEPHYSICALLIGHTFALLOFF
247
+ return computeDirectionalLightFalloff_Physical(lightDirection,directionToLightCenterW,cosHalfAngle);
248
+ #elif defined(USEGLTFLIGHTFALLOFF)
249
+ return computeDirectionalLightFalloff_GLTF(lightDirection,directionToLightCenterW,lightAngleScale,lightAngleOffset);
250
+ #else
251
+ return computeDirectionalLightFalloff_Standard(lightDirection,directionToLightCenterW,cosHalfAngle,exponent);
252
+ #endif
253
+ }`;
254
+ e.IncludesShadersStoreWGSL[l] || (e.IncludesShadersStoreWGSL[l] = X);
255
+ const d = "hdrFilteringFunctions", k = `#ifdef NUM_SAMPLES
256
+ #if NUM_SAMPLES>0
257
+ fn radicalInverse_VdC(value: u32)->f32
258
+ {var bits=(value<<16u) | (value>>16u);bits=((bits & 0x55555555u)<<1u) | ((bits & 0xAAAAAAAAu)>>1u);bits=((bits & 0x33333333u)<<2u) | ((bits & 0xCCCCCCCCu)>>2u);bits=((bits & 0x0F0F0F0Fu)<<4u) | ((bits & 0xF0F0F0F0u)>>4u);bits=((bits & 0x00FF00FFu)<<8u) | ((bits & 0xFF00FF00u)>>8u);return f32(bits)*2.3283064365386963e-10; }
259
+ fn hammersley(i: u32,N: u32)->vec2f
260
+ {return vec2f( f32(i)/ f32(N),radicalInverse_VdC(i));}
261
+ fn log4(x: f32)->f32 {return log2(x)/2.;}
262
+ fn uv_to_normal(uv: vec2f)->vec3f {var N: vec3f;var uvRange: vec2f=uv;var theta: f32=uvRange.x*2.0*PI;var phi: f32=uvRange.y*PI;N.x=cos(theta)*sin(phi);N.z=sin(theta)*sin(phi);N.y=cos(phi);return N;}
263
+ const NUM_SAMPLES_FLOAT: f32= f32(NUM_SAMPLES);const NUM_SAMPLES_FLOAT_INVERSED: f32=1./NUM_SAMPLES_FLOAT;const K: f32=4.;fn irradiance(inputTexture: texture_cube<f32>,inputSampler: sampler,inputN: vec3f,filteringInfo: vec2f,diffuseRoughness: f32,surfaceAlbedo: vec3f,inputV: vec3f
264
+ #ifdef IBL_CDF_FILTERING
265
+ ,icdfSampler: texture_2d<f32>,icdfSamplerSampler: sampler
266
+ #endif
267
+ )->vec3f
268
+ {var n: vec3f=normalize(inputN);var result: vec3f= vec3f(0.0);
269
+ #ifndef IBL_CDF_FILTERING
270
+ var tangent: vec3f=select(vec3f(1.,0.,0.),vec3f(0.,0.,1.),abs(n.z)<0.999);tangent=normalize(cross(tangent,n));var bitangent: vec3f=cross(n,tangent);var tbn: mat3x3f= mat3x3f(tangent,bitangent,n);var tbnInverse: mat3x3f=transpose(tbn);
271
+ #endif
272
+ var maxLevel: f32=filteringInfo.y;var dim0: f32=filteringInfo.x;var omegaP: f32=(4.*PI)/(6.*dim0*dim0);var clampedAlbedo: vec3f=clamp(surfaceAlbedo,vec3f(0.1),vec3f(1.0));for(var i: u32=0u; i<NUM_SAMPLES; i++)
273
+ {var Xi: vec2f=hammersley(i,NUM_SAMPLES);
274
+ #ifdef IBL_CDF_FILTERING
275
+ var T: vec2f;T.x=textureSampleLevel(icdfSampler,icdfSamplerSampler,vec2(Xi.x,0.0),0.0).x;T.y=textureSampleLevel(icdfSampler,icdfSamplerSampler,vec2(T.x,Xi.y),0.0).y;var Ls: vec3f=uv_to_normal(vec2f(1.0-fract(T.x+0.25),T.y));var NoL: f32=dot(n,Ls);var NoV: f32=dot(n,inputV);
276
+ #if BASE_DIFFUSE_MODEL==BRDF_DIFFUSE_MODEL_EON
277
+ var LoV: f32=dot(Ls,inputV);
278
+ #elif BASE_DIFFUSE_MODEL==BRDF_DIFFUSE_MODEL_BURLEY
279
+ var H: vec3f=(inputV+Ls)*0.5;var VoH: f32=dot(inputV,H);
280
+ #endif
281
+ #else
282
+ var Ls: vec3f=hemisphereCosSample(Xi);Ls=normalize(Ls);var Ns: vec3f= vec3f(0.,0.,1.);var NoL: f32=dot(Ns,Ls);var V: vec3f=tbnInverse*inputV;var NoV: f32=dot(Ns,V);
283
+ #if BASE_DIFFUSE_MODEL==BRDF_DIFFUSE_MODEL_EON
284
+ var LoV: f32=dot(Ls,V);
285
+ #elif BASE_DIFFUSE_MODEL==BRDF_DIFFUSE_MODEL_BURLEY
286
+ var H: vec3f=(V+Ls)*0.5;var VoH: f32=dot(V,H);
287
+ #endif
288
+ #endif
289
+ if (NoL>0.) {
290
+ #ifdef IBL_CDF_FILTERING
291
+ var pdf: f32=textureSampleLevel(icdfSampler,icdfSamplerSampler,T,0.0).z;var c: vec3f=textureSampleLevel(inputTexture,inputSampler,Ls,0.0).rgb;
292
+ #else
293
+ var pdf_inversed: f32=PI/NoL;var omegaS: f32=NUM_SAMPLES_FLOAT_INVERSED*pdf_inversed;var l: f32=log4(omegaS)-log4(omegaP)+log4(K);var mipLevel: f32=clamp(l,0.0,maxLevel);var c: vec3f=textureSampleLevel(inputTexture,inputSampler,tbn*Ls,mipLevel).rgb;
294
+ #endif
295
+ #ifdef GAMMA_INPUT
296
+ c=toLinearSpaceVec3(c);
297
+ #endif
298
+ var diffuseRoughnessTerm: vec3f=vec3f(1.0);
299
+ #if BASE_DIFFUSE_MODEL==BRDF_DIFFUSE_MODEL_EON
300
+ diffuseRoughnessTerm=diffuseBRDF_EON(clampedAlbedo,diffuseRoughness,NoL,NoV,LoV)*PI;
301
+ #elif BASE_DIFFUSE_MODEL==BRDF_DIFFUSE_MODEL_BURLEY
302
+ diffuseRoughnessTerm=vec3f(diffuseBRDF_Burley(NoL,NoV,VoH,diffuseRoughness)*PI);
303
+ #endif
304
+ #ifdef IBL_CDF_FILTERING
305
+ var light: vec3f=vec3f(0.0);if (pdf>1e-6) {light=vec3f(1.0)/vec3f(pdf)*c;}
306
+ result+=NoL*diffuseRoughnessTerm*light;
307
+ #else
308
+ result+=c*diffuseRoughnessTerm;
309
+ #endif
310
+ }}
311
+ result=result*NUM_SAMPLES_FLOAT_INVERSED;
312
+ #if BASE_DIFFUSE_MODEL==BRDF_DIFFUSE_MODEL_EON
313
+ result=result/clampedAlbedo;
314
+ #endif
315
+ return result;}
316
+ fn radiance(alphaG: f32,inputTexture: texture_cube<f32>,inputSampler: sampler,inputN: vec3f,filteringInfo: vec2f)->vec3f
317
+ {var n: vec3f=normalize(inputN);var c: vec3f=textureSample(inputTexture,inputSampler,n).rgb;
318
+ if (alphaG==0.) {
319
+ #ifdef GAMMA_INPUT
320
+ c=toLinearSpace(c);
321
+ #endif
322
+ return c;} else {var result: vec3f= vec3f(0.);var tangent: vec3f=select(vec3f(1.,0.,0.),vec3f(0.,0.,1.),abs(n.z)<0.999);tangent=normalize(cross(tangent,n));var bitangent: vec3f=cross(n,tangent);var tbn: mat3x3f= mat3x3f(tangent,bitangent,n);var maxLevel: f32=filteringInfo.y;var dim0: f32=filteringInfo.x;var omegaP: f32=(4.*PI)/(6.*dim0*dim0);var weight: f32=0.;for(var i: u32=0u; i<NUM_SAMPLES; i++)
323
+ {var Xi: vec2f=hammersley(i,NUM_SAMPLES);var H: vec3f=hemisphereImportanceSampleDggx(Xi,alphaG);var NoV: f32=1.;var NoH: f32=H.z;var NoH2: f32=H.z*H.z;var NoL: f32=2.*NoH2-1.;var L: vec3f= vec3f(2.*NoH*H.x,2.*NoH*H.y,NoL);L=normalize(L);if (NoL>0.) {var pdf_inversed: f32=4./normalDistributionFunction_TrowbridgeReitzGGX(NoH,alphaG);var omegaS: f32=NUM_SAMPLES_FLOAT_INVERSED*pdf_inversed;var l: f32=log4(omegaS)-log4(omegaP)+log4(K);var mipLevel: f32=clamp( f32(l),0.0,maxLevel);weight+=NoL;var c: vec3f=textureSampleLevel(inputTexture,inputSampler,tbn*L,mipLevel).rgb;
324
+ #ifdef GAMMA_INPUT
325
+ c=toLinearSpace(c);
326
+ #endif
327
+ result+=c*NoL;}}
328
+ result=result/weight;return result;}}
329
+ #endif
330
+ #endif
331
+ `;
332
+ e.IncludesShadersStoreWGSL[d] || (e.IncludesShadersStoreWGSL[d] = k);
333
+ const s = "pbrDirectLightingFunctions", z = `#define CLEARCOATREFLECTANCE90 1.0
334
+ struct lightingInfo
335
+ {diffuse: vec3f,
336
+ #ifdef SS_TRANSLUCENCY
337
+ diffuseTransmission: vec3f,
338
+ #endif
339
+ #ifdef SPECULARTERM
340
+ specular: vec3f,
341
+ #endif
342
+ #ifdef CLEARCOAT
343
+ clearCoat: vec4f,
344
+ #endif
345
+ #ifdef SHEEN
346
+ sheen: vec3f
347
+ #endif
348
+ };fn adjustRoughnessFromLightProperties(roughness: f32,lightRadius: f32,lightDistance: f32)->f32 {
349
+ #if defined(USEPHYSICALLIGHTFALLOFF) || defined(USEGLTFLIGHTFALLOFF)
350
+ var lightRoughness: f32=lightRadius/lightDistance;var totalRoughness: f32=saturate(lightRoughness+roughness);return totalRoughness;
351
+ #else
352
+ return roughness;
353
+ #endif
354
+ }
355
+ fn computeHemisphericDiffuseLighting(info: preLightingInfo,lightColor: vec3f,groundColor: vec3f)->vec3f {return mix(groundColor,lightColor,info.NdotL);}
356
+ #if defined(AREALIGHTUSED) && defined(AREALIGHTSUPPORTED)
357
+ fn computeAreaDiffuseLighting(info: preLightingInfo,lightColor: vec3f)->vec3f {return info.areaLightDiffuse*lightColor;}
358
+ #endif
359
+ fn computeDiffuseLighting(info: preLightingInfo,lightColor: vec3f)->vec3f {var diffuseTerm: vec3f=vec3f(1.0/PI);
360
+ #if BASE_DIFFUSE_MODEL==BRDF_DIFFUSE_MODEL_LEGACY
361
+ diffuseTerm=vec3f(diffuseBRDF_Burley(info.NdotL,info.NdotV,info.VdotH,info.roughness));
362
+ #elif BASE_DIFFUSE_MODEL==BRDF_DIFFUSE_MODEL_BURLEY
363
+ diffuseTerm=vec3f(diffuseBRDF_Burley(info.NdotL,info.NdotV,info.VdotH,info.diffuseRoughness));
364
+ #elif BASE_DIFFUSE_MODEL==BRDF_DIFFUSE_MODEL_EON
365
+ var clampedAlbedo: vec3f=clamp(info.surfaceAlbedo,vec3f(0.1),vec3f(1.0));diffuseTerm=diffuseBRDF_EON(clampedAlbedo,info.diffuseRoughness,info.NdotL,info.NdotV,info.LdotV);diffuseTerm/=clampedAlbedo;
366
+ #endif
367
+ return diffuseTerm*info.attenuation*info.NdotL*lightColor;}
368
+ fn computeProjectionTextureDiffuseLighting(projectionLightTexture: texture_2d<f32>,projectionLightSampler: sampler,textureProjectionMatrix: mat4x4f,posW: vec3f)->vec3f{var strq: vec4f=textureProjectionMatrix* vec4f(posW,1.0);strq/=strq.w;var textureColor: vec3f=textureSample(projectionLightTexture,projectionLightSampler,strq.xy).rgb;return toLinearSpaceVec3(textureColor);}
369
+ #ifdef SS_TRANSLUCENCY
370
+ fn computeDiffuseTransmittedLighting(info: preLightingInfo,lightColor: vec3f,transmittance: vec3f)->vec3f {var transmittanceNdotL=vec3f(0.0);var NdotL: f32=absEps(info.NdotLUnclamped);
371
+ #ifndef SS_TRANSLUCENCY_LEGACY
372
+ if (info.NdotLUnclamped<0.0) {
373
+ #endif
374
+ var wrapNdotL: f32=computeWrappedDiffuseNdotL(NdotL,0.02);var trAdapt: f32=step(0.,info.NdotLUnclamped);transmittanceNdotL=mix(transmittance*wrapNdotL, vec3f(wrapNdotL),trAdapt);
375
+ #ifndef SS_TRANSLUCENCY_LEGACY
376
+ }
377
+ var diffuseTerm : vec3f=vec3f(1.0/PI);
378
+ #if BASE_DIFFUSE_MODEL==BRDF_DIFFUSE_MODEL_LEGACY
379
+ diffuseTerm=vec3f(diffuseBRDF_Burley(
380
+ info.NdotL,info.NdotV,info.VdotH,info.roughness));
381
+ #elif BASE_DIFFUSE_MODEL==BRDF_DIFFUSE_MODEL_BURLEY
382
+ diffuseTerm=vec3f(diffuseBRDF_Burley(
383
+ info.NdotL,info.NdotV,info.VdotH,info.diffuseRoughness));
384
+ #elif BASE_DIFFUSE_MODEL==BRDF_DIFFUSE_MODEL_EON
385
+ var clampedAlbedo: vec3f=clamp(info.surfaceAlbedo,vec3f(0.1),vec3f(1.0));diffuseTerm=diffuseBRDF_EON(clampedAlbedo,info.diffuseRoughness,
386
+ info.NdotL,info.NdotV,info.LdotV);diffuseTerm/=clampedAlbedo;
387
+ #endif
388
+ return (transmittanceNdotL*diffuseTerm)*info.attenuation*lightColor;
389
+ #else
390
+ let diffuseTerm=diffuseBRDF_Burley(NdotL,info.NdotV,info.VdotH,info.roughness);return diffuseTerm*transmittanceNdotL*info.attenuation*lightColor;
391
+ #endif
392
+ }
393
+ #endif
394
+ #ifdef SPECULARTERM
395
+ fn computeSpecularLighting(info: preLightingInfo,N: vec3f,reflectance0: vec3f,fresnel: vec3f,geometricRoughnessFactor: f32,lightColor: vec3f)->vec3f {var NdotH: f32=saturateEps(dot(N,info.H));var roughness: f32=max(info.roughness,geometricRoughnessFactor);var alphaG: f32=convertRoughnessToAverageSlope(roughness);
396
+ #ifdef IRIDESCENCE
397
+ fresnel=mix(fresnel,reflectance0,info.iridescenceIntensity);
398
+ #endif
399
+ var distribution: f32=normalDistributionFunction_TrowbridgeReitzGGX(NdotH,alphaG);
400
+ #ifdef BRDF_V_HEIGHT_CORRELATED
401
+ var smithVisibility: f32=smithVisibility_GGXCorrelated(info.NdotL,info.NdotV,alphaG);
402
+ #else
403
+ var smithVisibility: f32=smithVisibility_TrowbridgeReitzGGXFast(info.NdotL,info.NdotV,alphaG);
404
+ #endif
405
+ var specTerm: vec3f=fresnel*distribution*smithVisibility;return specTerm*info.attenuation*info.NdotL*lightColor;}
406
+ #if defined(AREALIGHTUSED) && defined(AREALIGHTSUPPORTED)
407
+ fn computeAreaSpecularLighting(info: preLightingInfo,specularColor: vec3f,reflectance0: vec3f,reflectance90: vec3f)->vec3f {var fresnel:vec3f =reflectance0*specularColor*info.areaLightFresnel.x+( vec3f( 1.0 )-specularColor )*info.areaLightFresnel.y*reflectance90;return specularColor*fresnel*info.areaLightSpecular;}
408
+ #endif
409
+ #endif
410
+ #ifdef ANISOTROPIC
411
+ fn computeAnisotropicSpecularLighting(info: preLightingInfo,V: vec3f,N: vec3f,T: vec3f,B: vec3f,anisotropy: f32,reflectance0: vec3f,reflectance90: vec3f,geometricRoughnessFactor: f32,lightColor: vec3f)->vec3f {var NdotH: f32=saturateEps(dot(N,info.H));var TdotH: f32=dot(T,info.H);var BdotH: f32=dot(B,info.H);var TdotV: f32=dot(T,V);var BdotV: f32=dot(B,V);var TdotL: f32=dot(T,info.L);var BdotL: f32=dot(B,info.L);var alphaG: f32=convertRoughnessToAverageSlope(info.roughness);var alphaTB: vec2f=getAnisotropicRoughness(alphaG,anisotropy);alphaTB=max(alphaTB,vec2f(geometricRoughnessFactor*geometricRoughnessFactor));var fresnel: vec3f=fresnelSchlickGGXVec3(info.VdotH,reflectance0,reflectance90);
412
+ #ifdef IRIDESCENCE
413
+ fresnel=mix(fresnel,reflectance0,info.iridescenceIntensity);
414
+ #endif
415
+ var distribution: f32=normalDistributionFunction_BurleyGGX_Anisotropic(NdotH,TdotH,BdotH,alphaTB);var smithVisibility: f32=smithVisibility_GGXCorrelated_Anisotropic(info.NdotL,info.NdotV,TdotV,BdotV,TdotL,BdotL,alphaTB);var specTerm: vec3f=fresnel*distribution*smithVisibility;return specTerm*info.attenuation*info.NdotL*lightColor;}
416
+ #endif
417
+ #ifdef CLEARCOAT
418
+ fn computeClearCoatLighting(info: preLightingInfo,Ncc: vec3f,geometricRoughnessFactor: f32,clearCoatIntensity: f32,lightColor: vec3f)->vec4f {var NccdotL: f32=saturateEps(dot(Ncc,info.L));var NccdotH: f32=saturateEps(dot(Ncc,info.H));var clearCoatRoughness: f32=max(info.roughness,geometricRoughnessFactor);var alphaG: f32=convertRoughnessToAverageSlope(clearCoatRoughness);var fresnel: f32=fresnelSchlickGGX(info.VdotH,uniforms.vClearCoatRefractionParams.x,CLEARCOATREFLECTANCE90);fresnel*=clearCoatIntensity;var distribution: f32=normalDistributionFunction_TrowbridgeReitzGGX(NccdotH,alphaG);var kelemenVisibility: f32=visibility_Kelemen(info.VdotH);var clearCoatTerm: f32=fresnel*distribution*kelemenVisibility;return vec4f(
419
+ clearCoatTerm*info.attenuation*NccdotL*lightColor,
420
+ 1.0-fresnel
421
+ );}
422
+ fn computeClearCoatLightingAbsorption(NdotVRefract: f32,L: vec3f,Ncc: vec3f,clearCoatColor: vec3f,clearCoatThickness: f32,clearCoatIntensity: f32)->vec3f {var LRefract: vec3f=-refract(L,Ncc,uniforms.vClearCoatRefractionParams.y);var NdotLRefract: f32=saturateEps(dot(Ncc,LRefract));var absorption: vec3f=computeClearCoatAbsorption(NdotVRefract,NdotLRefract,clearCoatColor,clearCoatThickness,clearCoatIntensity);return absorption;}
423
+ #endif
424
+ #ifdef SHEEN
425
+ fn computeSheenLighting(info: preLightingInfo,N: vec3f,reflectance0: vec3f,reflectance90: vec3f,geometricRoughnessFactor: f32,lightColor: vec3f)->vec3f {var NdotH: f32=saturateEps(dot(N,info.H));var roughness: f32=max(info.roughness,geometricRoughnessFactor);var alphaG: f32=convertRoughnessToAverageSlope(roughness);var fresnel: f32=1.;var distribution: f32=normalDistributionFunction_CharlieSheen(NdotH,alphaG);/*#ifdef SHEEN_SOFTER
426
+ var visibility: f32=visibility_CharlieSheen(info.NdotL,info.NdotV,alphaG);
427
+ #else */
428
+ var visibility: f32=visibility_Ashikhmin(info.NdotL,info.NdotV);/* #endif */
429
+ var sheenTerm: f32=fresnel*distribution*visibility;return sheenTerm*info.attenuation*info.NdotL*lightColor;}
430
+ #endif
431
+ `;
432
+ e.IncludesShadersStoreWGSL[s] || (e.IncludesShadersStoreWGSL[s] = z);
433
+ const E = "pbrIBLFunctions", K = `#if defined(REFLECTION) || defined(SS_REFRACTION)
434
+ fn getLodFromAlphaG(cubeMapDimensionPixels: f32,microsurfaceAverageSlope: f32)->f32 {var microsurfaceAverageSlopeTexels: f32=cubeMapDimensionPixels*microsurfaceAverageSlope;var lod: f32=log2(microsurfaceAverageSlopeTexels);return lod;}
435
+ fn getLinearLodFromRoughness(cubeMapDimensionPixels: f32,roughness: f32)->f32 {var lod: f32=log2(cubeMapDimensionPixels)*roughness;return lod;}
436
+ #endif
437
+ #if defined(ENVIRONMENTBRDF) && defined(RADIANCEOCCLUSION)
438
+ fn environmentRadianceOcclusion(ambientOcclusion: f32,NdotVUnclamped: f32)->f32 {var temp: f32=NdotVUnclamped+ambientOcclusion;return saturate(temp*temp-1.0+ambientOcclusion);}
439
+ #endif
440
+ #if defined(ENVIRONMENTBRDF) && defined(HORIZONOCCLUSION)
441
+ fn environmentHorizonOcclusion(view: vec3f,normal: vec3f,geometricNormal: vec3f)->f32 {var reflection: vec3f=reflect(view,normal);var temp: f32=saturate(1.0+1.1*dot(reflection,geometricNormal));return temp*temp;}
442
+ #endif
443
+ #if defined(LODINREFLECTIONALPHA) || defined(SS_LODINREFRACTIONALPHA)
444
+ fn UNPACK_LOD(x: f32)->f32 {return (1.0-x)*255.0;}
445
+ fn getLodFromAlphaGNdotV(cubeMapDimensionPixels: f32,alphaG: f32,NdotV: f32)->f32 {var microsurfaceAverageSlope: f32=alphaG;microsurfaceAverageSlope*=sqrt(abs(NdotV));return getLodFromAlphaG(cubeMapDimensionPixels,microsurfaceAverageSlope);}
446
+ #endif
447
+ `;
448
+ e.IncludesShadersStoreWGSL[E] || (e.IncludesShadersStoreWGSL[E] = K);
449
+ const S = "pbrBlockAlbedoOpacity", $ = `struct albedoOpacityOutParams
450
+ {surfaceAlbedo: vec3f,
451
+ alpha: f32};
452
+ #define pbr_inline
453
+ fn albedoOpacityBlock(
454
+ vAlbedoColor: vec4f
455
+ #ifdef ALBEDO
456
+ ,albedoTexture: vec4f
457
+ ,albedoInfos: vec2f
458
+ #endif
459
+ ,baseWeight: f32
460
+ #ifdef BASE_WEIGHT
461
+ ,baseWeightTexture: vec4f
462
+ ,vBaseWeightInfos: vec2f
463
+ #endif
464
+ #ifdef OPACITY
465
+ ,opacityMap: vec4f
466
+ ,vOpacityInfos: vec2f
467
+ #endif
468
+ #ifdef DETAIL
469
+ ,detailColor: vec4f
470
+ ,vDetailInfos: vec4f
471
+ #endif
472
+ #ifdef DECAL
473
+ ,decalColor: vec4f
474
+ ,vDecalInfos: vec4f
475
+ #endif
476
+ )->albedoOpacityOutParams
477
+ {var outParams: albedoOpacityOutParams;var surfaceAlbedo: vec3f=vAlbedoColor.rgb;var alpha: f32=vAlbedoColor.a;
478
+ #ifdef ALBEDO
479
+ #if defined(ALPHAFROMALBEDO) || defined(ALPHATEST)
480
+ alpha*=albedoTexture.a;
481
+ #endif
482
+ #ifdef GAMMAALBEDO
483
+ surfaceAlbedo*=toLinearSpaceVec3(albedoTexture.rgb);
484
+ #else
485
+ surfaceAlbedo*=albedoTexture.rgb;
486
+ #endif
487
+ surfaceAlbedo*=albedoInfos.y;
488
+ #endif
489
+ #ifndef DECAL_AFTER_DETAIL
490
+ #include<decalFragment>
491
+ #endif
492
+ #if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)
493
+ surfaceAlbedo*=fragmentInputs.vColor.rgb;
494
+ #endif
495
+ #ifdef DETAIL
496
+ var detailAlbedo: f32=2.0*mix(0.5,detailColor.r,vDetailInfos.y);surfaceAlbedo=surfaceAlbedo.rgb*detailAlbedo*detailAlbedo;
497
+ #endif
498
+ #ifdef DECAL_AFTER_DETAIL
499
+ #include<decalFragment>
500
+ #endif
501
+ #define CUSTOM_FRAGMENT_UPDATE_ALBEDO
502
+ surfaceAlbedo*=baseWeight;
503
+ #ifdef BASE_WEIGHT
504
+ surfaceAlbedo*=baseWeightTexture.r;
505
+ #endif
506
+ #ifdef OPACITY
507
+ #ifdef OPACITYRGB
508
+ alpha=getLuminance(opacityMap.rgb);
509
+ #else
510
+ alpha*=opacityMap.a;
511
+ #endif
512
+ alpha*=vOpacityInfos.y;
513
+ #endif
514
+ #if defined(VERTEXALPHA) || defined(INSTANCESCOLOR) && defined(INSTANCES)
515
+ alpha*=fragmentInputs.vColor.a;
516
+ #endif
517
+ #if !defined(SS_LINKREFRACTIONTOTRANSPARENCY) && !defined(ALPHAFRESNEL)
518
+ #ifdef ALPHATEST
519
+ #if DEBUGMODE != 88
520
+ if (alpha<ALPHATESTVALUE) {discard;}
521
+ #endif
522
+ #ifndef ALPHABLEND
523
+ alpha=1.0;
524
+ #endif
525
+ #endif
526
+ #endif
527
+ outParams.surfaceAlbedo=surfaceAlbedo;outParams.alpha=alpha;return outParams;}
528
+ `;
529
+ e.IncludesShadersStoreWGSL[S] || (e.IncludesShadersStoreWGSL[S] = $);
530
+ const m = "pbrBlockReflectivity", q = `struct reflectivityOutParams
531
+ {microSurface: f32,
532
+ roughness: f32,
533
+ diffuseRoughness: f32,
534
+ reflectanceF0: f32,
535
+ reflectanceF90: vec3f,
536
+ colorReflectanceF0: vec3f,
537
+ colorReflectanceF90: vec3f,
538
+ #ifdef METALLICWORKFLOW
539
+ surfaceAlbedo: vec3f,
540
+ metallic: f32,
541
+ specularWeight: f32,
542
+ dielectricColorF0: vec3f,
543
+ #endif
544
+ #if defined(METALLICWORKFLOW) && defined(REFLECTIVITY) && defined(AOSTOREINMETALMAPRED)
545
+ ambientOcclusionColor: vec3f,
546
+ #endif
547
+ #if DEBUGMODE>0
548
+ #ifdef METALLICWORKFLOW
549
+ #ifdef REFLECTIVITY
550
+ surfaceMetallicColorMap: vec4f,
551
+ #endif
552
+ metallicF0: vec3f,
553
+ #else
554
+ #ifdef REFLECTIVITY
555
+ surfaceReflectivityColorMap: vec4f,
556
+ #endif
557
+ #endif
558
+ #endif
559
+ };
560
+ #define pbr_inline
561
+ fn reflectivityBlock(
562
+ reflectivityColor: vec4f
563
+ #ifdef METALLICWORKFLOW
564
+ ,surfaceAlbedo: vec3f
565
+ ,metallicReflectanceFactors: vec4f
566
+ #endif
567
+ ,baseDiffuseRoughness: f32
568
+ #ifdef BASE_DIFFUSE_ROUGHNESS
569
+ ,baseDiffuseRoughnessTexture: f32
570
+ ,baseDiffuseRoughnessInfos: vec2f
571
+ #endif
572
+ #ifdef REFLECTIVITY
573
+ ,reflectivityInfos: vec3f
574
+ ,surfaceMetallicOrReflectivityColorMap: vec4f
575
+ #endif
576
+ #if defined(METALLICWORKFLOW) && defined(REFLECTIVITY) && defined(AOSTOREINMETALMAPRED)
577
+ ,ambientOcclusionColorIn: vec3f
578
+ #endif
579
+ #ifdef MICROSURFACEMAP
580
+ ,microSurfaceTexel: vec4f
581
+ #endif
582
+ #ifdef DETAIL
583
+ ,detailColor: vec4f
584
+ ,vDetailInfos: vec4f
585
+ #endif
586
+ )->reflectivityOutParams
587
+ {var outParams: reflectivityOutParams;var microSurface: f32=reflectivityColor.a;var surfaceReflectivityColor: vec3f=reflectivityColor.rgb;
588
+ #ifdef METALLICWORKFLOW
589
+ var metallicRoughness: vec2f=surfaceReflectivityColor.rg;var ior: f32=surfaceReflectivityColor.b;
590
+ #ifdef REFLECTIVITY
591
+ #if DEBUGMODE>0
592
+ outParams.surfaceMetallicColorMap=surfaceMetallicOrReflectivityColorMap;
593
+ #endif
594
+ #ifdef AOSTOREINMETALMAPRED
595
+ var aoStoreInMetalMap: vec3f= vec3f(surfaceMetallicOrReflectivityColorMap.r,surfaceMetallicOrReflectivityColorMap.r,surfaceMetallicOrReflectivityColorMap.r);outParams.ambientOcclusionColor=mix(ambientOcclusionColorIn,aoStoreInMetalMap,reflectivityInfos.z);
596
+ #endif
597
+ #ifdef METALLNESSSTOREINMETALMAPBLUE
598
+ metallicRoughness.r*=surfaceMetallicOrReflectivityColorMap.b;
599
+ #else
600
+ metallicRoughness.r*=surfaceMetallicOrReflectivityColorMap.r;
601
+ #endif
602
+ #ifdef ROUGHNESSSTOREINMETALMAPALPHA
603
+ metallicRoughness.g*=surfaceMetallicOrReflectivityColorMap.a;
604
+ #else
605
+ #ifdef ROUGHNESSSTOREINMETALMAPGREEN
606
+ metallicRoughness.g*=surfaceMetallicOrReflectivityColorMap.g;
607
+ #endif
608
+ #endif
609
+ #endif
610
+ #ifdef DETAIL
611
+ var detailRoughness: f32=mix(0.5,detailColor.b,vDetailInfos.w);var loLerp: f32=mix(0.,metallicRoughness.g,detailRoughness*2.);var hiLerp: f32=mix(metallicRoughness.g,1.,(detailRoughness-0.5)*2.);metallicRoughness.g=mix(loLerp,hiLerp,step(detailRoughness,0.5));
612
+ #endif
613
+ #ifdef MICROSURFACEMAP
614
+ metallicRoughness.g*=microSurfaceTexel.r;
615
+ #endif
616
+ #define CUSTOM_FRAGMENT_UPDATE_METALLICROUGHNESS
617
+ microSurface=1.0-metallicRoughness.g;var baseColor: vec3f=surfaceAlbedo;outParams.metallic=metallicRoughness.r;outParams.specularWeight=metallicReflectanceFactors.a;var dielectricF0 : f32=reflectivityColor.a*outParams.specularWeight;surfaceReflectivityColor=metallicReflectanceFactors.rgb;
618
+ #if DEBUGMODE>0
619
+ outParams.metallicF0=dielectricF0*surfaceReflectivityColor;
620
+ #endif
621
+ #ifdef LEGACY_SPECULAR_ENERGY_CONSERVATION
622
+ outParams.surfaceAlbedo=baseColor.rgb*(vec3f(1.0)-vec3f(dielectricF0)*surfaceReflectivityColor)*(1.0-outParams.metallic);
623
+ #else
624
+ outParams.surfaceAlbedo=baseColor.rgb;
625
+ #endif
626
+ #ifdef LEGACY_SPECULAR_ENERGY_CONSERVATION
627
+ {let reflectivityColor: vec3f=mix(dielectricF0*surfaceReflectivityColor,baseColor.rgb,outParams.metallic);outParams.reflectanceF0=max(reflectivityColor.r,max(reflectivityColor.g,reflectivityColor.b));}
628
+ #else
629
+ #if DIELECTRIC_SPECULAR_MODEL==DIELECTRIC_SPECULAR_MODEL_GLTF
630
+ let maxF0: f32=max(surfaceReflectivityColor.r,max(surfaceReflectivityColor.g,surfaceReflectivityColor.b));outParams.reflectanceF0=mix(dielectricF0*maxF0,1.0f,outParams.metallic);
631
+ #else
632
+ outParams.reflectanceF0=mix(dielectricF0,1.0,outParams.metallic);
633
+ #endif
634
+ #endif
635
+ #ifdef LEGACY_SPECULAR_ENERGY_CONSERVATION
636
+ outParams.reflectanceF90=vec3(outParams.specularWeight);var f90Scale: f32=1.0;
637
+ #else
638
+ var f90Scale: f32=clamp(2.0*(ior-1.0),0.0,1.0);outParams.reflectanceF90=vec3(mix(
639
+ outParams.specularWeight*f90Scale,1.0,outParams.metallic));
640
+ #endif
641
+ outParams.dielectricColorF0=vec3f(dielectricF0*surfaceReflectivityColor);var metallicColorF0: vec3f=baseColor.rgb;outParams.colorReflectanceF0=mix(outParams.dielectricColorF0,metallicColorF0,outParams.metallic);
642
+ #if (DIELECTRIC_SPECULAR_MODEL==DIELECTRIC_SPECULAR_MODEL_OPENPBR)
643
+ let dielectricColorF90
644
+ : vec3f=surfaceReflectivityColor *
645
+ vec3f(outParams.specularWeight*f90Scale);
646
+ #else
647
+ let dielectricColorF90
648
+ : vec3f=vec3f(outParams.specularWeight*f90Scale);
649
+ #endif
650
+ #if (CONDUCTOR_SPECULAR_MODEL==CONDUCTOR_SPECULAR_MODEL_OPENPBR)
651
+ let conductorColorF90: vec3f=surfaceReflectivityColor;
652
+ #else
653
+ #ifdef LEGACY_SPECULAR_ENERGY_CONSERVATION
654
+ let conductorColorF90: vec3f=outParams.reflectanceF90;
655
+ #else
656
+ let conductorColorF90: vec3f=vec3f(1.0f);
657
+ #endif
658
+ #endif
659
+ outParams.colorReflectanceF90=mix(dielectricColorF90,conductorColorF90,outParams.metallic);
660
+ #else
661
+ #ifdef REFLECTIVITY
662
+ surfaceReflectivityColor*=surfaceMetallicOrReflectivityColorMap.rgb;
663
+ #if DEBUGMODE>0
664
+ outParams.surfaceReflectivityColorMap=surfaceMetallicOrReflectivityColorMap;
665
+ #endif
666
+ #ifdef MICROSURFACEFROMREFLECTIVITYMAP
667
+ microSurface*=surfaceMetallicOrReflectivityColorMap.a;microSurface*=reflectivityInfos.z;
668
+ #else
669
+ #ifdef MICROSURFACEAUTOMATIC
670
+ microSurface*=computeDefaultMicroSurface(microSurface,surfaceReflectivityColor);
671
+ #endif
672
+ #ifdef MICROSURFACEMAP
673
+ microSurface*=microSurfaceTexel.r;
674
+ #endif
675
+ #define CUSTOM_FRAGMENT_UPDATE_MICROSURFACE
676
+ #endif
677
+ #endif
678
+ outParams.colorReflectanceF0=surfaceReflectivityColor;outParams.reflectanceF0=max(surfaceReflectivityColor.r,max(surfaceReflectivityColor.g,surfaceReflectivityColor.b));outParams.reflectanceF90=vec3f(1.0);
679
+ #if (DIELECTRIC_SPECULAR_MODEL==DIELECTRIC_SPECULAR_MODEL_OPENPBR)
680
+ outParams.colorReflectanceF90=surfaceReflectivityColor;
681
+ #else
682
+ outParams.colorReflectanceF90=vec3(1.0);
683
+ #endif
684
+ #endif
685
+ microSurface=saturate(microSurface);var roughness: f32=1.-microSurface;var diffuseRoughness: f32=baseDiffuseRoughness;
686
+ #ifdef BASE_DIFFUSE_ROUGHNESS
687
+ diffuseRoughness*=baseDiffuseRoughnessTexture*baseDiffuseRoughnessInfos.y;
688
+ #endif
689
+ outParams.microSurface=microSurface;outParams.roughness=roughness;outParams.diffuseRoughness=diffuseRoughness;return outParams;}
690
+ `;
691
+ e.IncludesShadersStoreWGSL[m] || (e.IncludesShadersStoreWGSL[m] = q);
692
+ const u = "pbrBlockAmbientOcclusion", Z = `struct ambientOcclusionOutParams
693
+ {ambientOcclusionColor: vec3f,
694
+ #if DEBUGMODE>0 && defined(AMBIENT)
695
+ ambientOcclusionColorMap: vec3f
696
+ #endif
697
+ };
698
+ #define pbr_inline
699
+ fn ambientOcclusionBlock(
700
+ #ifdef AMBIENT
701
+ ambientOcclusionColorMap_: vec3f,
702
+ vAmbientInfos: vec4f
703
+ #endif
704
+ )->ambientOcclusionOutParams
705
+ {
706
+ var outParams: ambientOcclusionOutParams;var ambientOcclusionColor: vec3f= vec3f(1.,1.,1.);
707
+ #ifdef AMBIENT
708
+ var ambientOcclusionColorMap: vec3f=ambientOcclusionColorMap_*vAmbientInfos.y;
709
+ #ifdef AMBIENTINGRAYSCALE
710
+ ambientOcclusionColorMap= vec3f(ambientOcclusionColorMap.r,ambientOcclusionColorMap.r,ambientOcclusionColorMap.r);
711
+ #endif
712
+ ambientOcclusionColor=mix(ambientOcclusionColor,ambientOcclusionColorMap,vAmbientInfos.z);
713
+ #if DEBUGMODE>0
714
+ outParams.ambientOcclusionColorMap=ambientOcclusionColorMap;
715
+ #endif
716
+ #endif
717
+ outParams.ambientOcclusionColor=ambientOcclusionColor;return outParams;}
718
+ `;
719
+ e.IncludesShadersStoreWGSL[u] || (e.IncludesShadersStoreWGSL[u] = Z);
720
+ const R = "pbrBlockAlphaFresnel", j = `#ifdef ALPHAFRESNEL
721
+ #if defined(ALPHATEST) || defined(ALPHABLEND)
722
+ struct alphaFresnelOutParams
723
+ {alpha: f32};fn faceforward(N: vec3<f32>,I: vec3<f32>,Nref: vec3<f32>)->vec3<f32> {return select(N,-N,dot(Nref,I)>0.0);}
724
+ #define pbr_inline
725
+ fn alphaFresnelBlock(
726
+ normalW: vec3f,
727
+ viewDirectionW: vec3f,
728
+ alpha: f32,
729
+ microSurface: f32
730
+ )->alphaFresnelOutParams
731
+ {var outParams: alphaFresnelOutParams;var opacityPerceptual: f32=alpha;
732
+ #ifdef LINEARALPHAFRESNEL
733
+ var opacity0: f32=opacityPerceptual;
734
+ #else
735
+ var opacity0: f32=opacityPerceptual*opacityPerceptual;
736
+ #endif
737
+ var opacity90: f32=fresnelGrazingReflectance(opacity0);var normalForward: vec3f=faceforward(normalW,-viewDirectionW,normalW);outParams.alpha=getReflectanceFromAnalyticalBRDFLookup_Jones(saturate(dot(viewDirectionW,normalForward)), vec3f(opacity0), vec3f(opacity90),sqrt(microSurface)).x;
738
+ #ifdef ALPHATEST
739
+ if (outParams.alpha<ALPHATESTVALUE) {discard;}
740
+ #ifndef ALPHABLEND
741
+ outParams.alpha=1.0;
742
+ #endif
743
+ #endif
744
+ return outParams;}
745
+ #endif
746
+ #endif
747
+ `;
748
+ e.IncludesShadersStoreWGSL[R] || (e.IncludesShadersStoreWGSL[R] = j);
749
+ const v = "pbrBlockAnisotropic", J = `#ifdef ANISOTROPIC
750
+ struct anisotropicOutParams
751
+ {anisotropy: f32,
752
+ anisotropicTangent: vec3f,
753
+ anisotropicBitangent: vec3f,
754
+ anisotropicNormal: vec3f,
755
+ #if DEBUGMODE>0 && defined(ANISOTROPIC_TEXTURE)
756
+ anisotropyMapData: vec3f
757
+ #endif
758
+ };
759
+ #define pbr_inline
760
+ fn anisotropicBlock(
761
+ vAnisotropy: vec3f,
762
+ roughness: f32,
763
+ #ifdef ANISOTROPIC_TEXTURE
764
+ anisotropyMapData: vec3f,
765
+ #endif
766
+ TBN: mat3x3f,
767
+ normalW: vec3f,
768
+ viewDirectionW: vec3f
769
+ )->anisotropicOutParams
770
+ {
771
+ var outParams: anisotropicOutParams;var anisotropy: f32=vAnisotropy.b;var anisotropyDirection: vec3f= vec3f(vAnisotropy.xy,0.);
772
+ #ifdef ANISOTROPIC_TEXTURE
773
+ var amd=anisotropyMapData.rg;anisotropy*=anisotropyMapData.b;
774
+ #if DEBUGMODE>0
775
+ outParams.anisotropyMapData=anisotropyMapData;
776
+ #endif
777
+ amd=amd*2.0-1.0;
778
+ #ifdef ANISOTROPIC_LEGACY
779
+ anisotropyDirection=vec3f(anisotropyDirection.xy*amd,anisotropyDirection.z);
780
+ #else
781
+ anisotropyDirection=vec3f(mat2x2f(anisotropyDirection.x,anisotropyDirection.y,-anisotropyDirection.y,anisotropyDirection.x)*normalize(amd),anisotropyDirection.z);
782
+ #endif
783
+ #endif
784
+ var anisoTBN: mat3x3f= mat3x3f(normalize(TBN[0]),normalize(TBN[1]),normalize(TBN[2]));var anisotropicTangent: vec3f=normalize(anisoTBN*anisotropyDirection);var anisotropicBitangent: vec3f=normalize(cross(anisoTBN[2],anisotropicTangent));outParams.anisotropy=anisotropy;outParams.anisotropicTangent=anisotropicTangent;outParams.anisotropicBitangent=anisotropicBitangent;outParams.anisotropicNormal=getAnisotropicBentNormals(anisotropicTangent,anisotropicBitangent,normalW,viewDirectionW,anisotropy,roughness);return outParams;}
785
+ #endif
786
+ `;
787
+ e.IncludesShadersStoreWGSL[v] || (e.IncludesShadersStoreWGSL[v] = J);
788
+ const C = "pbrBlockReflection", Q = `#ifdef REFLECTION
789
+ struct reflectionOutParams
790
+ {environmentRadiance: vec4f
791
+ ,environmentIrradiance: vec3f
792
+ #ifdef REFLECTIONMAP_3D
793
+ ,reflectionCoords: vec3f
794
+ #else
795
+ ,reflectionCoords: vec2f
796
+ #endif
797
+ #ifdef SS_TRANSLUCENCY
798
+ #ifdef USESPHERICALFROMREFLECTIONMAP
799
+ #if !defined(NORMAL) || !defined(USESPHERICALINVERTEX)
800
+ ,irradianceVector: vec3f
801
+ #endif
802
+ #endif
803
+ #endif
804
+ };
805
+ #define pbr_inline
806
+ #ifdef REFLECTIONMAP_3D
807
+ fn createReflectionCoords(
808
+ vPositionW: vec3f,
809
+ normalW: vec3f,
810
+ #ifdef ANISOTROPIC
811
+ anisotropicOut: anisotropicOutParams,
812
+ #endif
813
+ )->vec3f
814
+ {var reflectionCoords: vec3f;
815
+ #else
816
+ fn createReflectionCoords(
817
+ vPositionW: vec3f,
818
+ normalW: vec3f,
819
+ #ifdef ANISOTROPIC
820
+ anisotropicOut: anisotropicOutParams,
821
+ #endif
822
+ )->vec2f
823
+ {
824
+ var reflectionCoords: vec2f;
825
+ #endif
826
+ #ifdef ANISOTROPIC
827
+ var reflectionVector: vec3f=computeReflectionCoords( vec4f(vPositionW,1.0),anisotropicOut.anisotropicNormal);
828
+ #else
829
+ var reflectionVector: vec3f=computeReflectionCoords( vec4f(vPositionW,1.0),normalW);
830
+ #endif
831
+ #ifdef REFLECTIONMAP_OPPOSITEZ
832
+ reflectionVector.z*=-1.0;
833
+ #endif
834
+ #ifdef REFLECTIONMAP_3D
835
+ reflectionCoords=reflectionVector;
836
+ #else
837
+ reflectionCoords=reflectionVector.xy;
838
+ #ifdef REFLECTIONMAP_PROJECTION
839
+ reflectionCoords/=reflectionVector.z;
840
+ #endif
841
+ reflectionCoords.y=1.0-reflectionCoords.y;
842
+ #endif
843
+ return reflectionCoords;}
844
+ #define pbr_inline
845
+ fn sampleReflectionTexture(
846
+ alphaG: f32
847
+ ,vReflectionMicrosurfaceInfos: vec3f
848
+ ,vReflectionInfos: vec2f
849
+ ,vReflectionColor: vec3f
850
+ #if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)
851
+ ,NdotVUnclamped: f32
852
+ #endif
853
+ #ifdef LINEARSPECULARREFLECTION
854
+ ,roughness: f32
855
+ #endif
856
+ #ifdef REFLECTIONMAP_3D
857
+ ,reflectionSampler: texture_cube<f32>
858
+ ,reflectionSamplerSampler: sampler
859
+ ,reflectionCoords: vec3f
860
+ #else
861
+ ,reflectionSampler: texture_2d<f32>
862
+ ,reflectionSamplerSampler: sampler
863
+ ,reflectionCoords: vec2f
864
+ #endif
865
+ #ifndef LODBASEDMICROSFURACE
866
+ #ifdef REFLECTIONMAP_3D
867
+ ,reflectionLowSampler: texture_cube<f32>
868
+ ,reflectionLowSamplerSampler: sampler
869
+ ,reflectionHighSampler: texture_cube<f32>
870
+ ,reflectionHighSamplerSampler: sampler
871
+ #else
872
+ ,reflectionLowSampler: texture_2d<f32>
873
+ ,reflectionLowSamplerSampler: sampler
874
+ ,reflectionHighSampler: texture_2d<f32>
875
+ ,reflectionHighSamplerSampler: sampler
876
+ #endif
877
+ #endif
878
+ #ifdef REALTIME_FILTERING
879
+ ,vReflectionFilteringInfo: vec2f
880
+ #endif
881
+ )->vec4f
882
+ {var environmentRadiance: vec4f;
883
+ #if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)
884
+ var reflectionLOD: f32=getLodFromAlphaGNdotV(vReflectionMicrosurfaceInfos.x,alphaG,NdotVUnclamped);
885
+ #elif defined(LINEARSPECULARREFLECTION)
886
+ var reflectionLOD: f32=getLinearLodFromRoughness(vReflectionMicrosurfaceInfos.x,roughness);
887
+ #else
888
+ var reflectionLOD: f32=getLodFromAlphaG(vReflectionMicrosurfaceInfos.x,alphaG);
889
+ #endif
890
+ #ifdef LODBASEDMICROSFURACE
891
+ reflectionLOD=reflectionLOD*vReflectionMicrosurfaceInfos.y+vReflectionMicrosurfaceInfos.z;
892
+ #ifdef LODINREFLECTIONALPHA
893
+ var automaticReflectionLOD: f32=UNPACK_LOD(textureSample(reflectionSampler,reflectionSamplerSampler,reflectionCoords).a);var requestedReflectionLOD: f32=max(automaticReflectionLOD,reflectionLOD);
894
+ #else
895
+ var requestedReflectionLOD: f32=reflectionLOD;
896
+ #endif
897
+ #ifdef REALTIME_FILTERING
898
+ environmentRadiance= vec4f(radiance(alphaG,reflectionSampler,reflectionSamplerSampler,reflectionCoords,vReflectionFilteringInfo),1.0);
899
+ #else
900
+ environmentRadiance=textureSampleLevel(reflectionSampler,reflectionSamplerSampler,reflectionCoords,reflectionLOD);
901
+ #endif
902
+ #else
903
+ var lodReflectionNormalized: f32=saturate(reflectionLOD/log2(vReflectionMicrosurfaceInfos.x));var lodReflectionNormalizedDoubled: f32=lodReflectionNormalized*2.0;var environmentMid: vec4f=textureSample(reflectionSampler,reflectionSamplerSampler,reflectionCoords);if (lodReflectionNormalizedDoubled<1.0){environmentRadiance=mix(
904
+ textureSample(reflectionHighSampler,reflectionHighSamplerSampler,reflectionCoords),
905
+ environmentMid,
906
+ lodReflectionNormalizedDoubled
907
+ );} else {environmentRadiance=mix(
908
+ environmentMid,
909
+ textureSample(reflectionLowSampler,reflectionLowSamplerSampler,reflectionCoords),
910
+ lodReflectionNormalizedDoubled-1.0
911
+ );}
912
+ #endif
913
+ var envRadiance=environmentRadiance.rgb;
914
+ #ifdef RGBDREFLECTION
915
+ envRadiance=fromRGBD(environmentRadiance);
916
+ #endif
917
+ #ifdef GAMMAREFLECTION
918
+ envRadiance=toLinearSpaceVec3(environmentRadiance.rgb);
919
+ #endif
920
+ envRadiance*=vReflectionInfos.x;envRadiance*=vReflectionColor.rgb;return vec4f(envRadiance,environmentRadiance.a);}
921
+ #define pbr_inline
922
+ fn reflectionBlock(
923
+ vPositionW: vec3f
924
+ ,normalW: vec3f
925
+ ,alphaG: f32
926
+ ,vReflectionMicrosurfaceInfos: vec3f
927
+ ,vReflectionInfos: vec2f
928
+ ,vReflectionColor: vec3f
929
+ #ifdef ANISOTROPIC
930
+ ,anisotropicOut: anisotropicOutParams
931
+ #endif
932
+ #if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)
933
+ ,NdotVUnclamped: f32
934
+ #endif
935
+ #ifdef LINEARSPECULARREFLECTION
936
+ ,roughness: f32
937
+ #endif
938
+ #ifdef REFLECTIONMAP_3D
939
+ ,reflectionSampler: texture_cube<f32>
940
+ ,reflectionSamplerSampler: sampler
941
+ #else
942
+ ,reflectionSampler: texture_2d<f32>
943
+ ,reflectionSamplerSampler: sampler
944
+ #endif
945
+ #if defined(NORMAL) && defined(USESPHERICALINVERTEX)
946
+ ,vEnvironmentIrradiance: vec3f
947
+ #endif
948
+ #if (defined(USESPHERICALFROMREFLECTIONMAP) && (!defined(NORMAL) || !defined(USESPHERICALINVERTEX))) || (defined(USEIRRADIANCEMAP) && defined(REFLECTIONMAP_3D))
949
+ ,reflectionMatrix: mat4x4f
950
+ #endif
951
+ #ifdef USEIRRADIANCEMAP
952
+ #ifdef REFLECTIONMAP_3D
953
+ ,irradianceSampler: texture_cube<f32>
954
+ ,irradianceSamplerSampler: sampler
955
+ #else
956
+ ,irradianceSampler: texture_2d<f32>
957
+ ,irradianceSamplerSampler: sampler
958
+ #endif
959
+ #ifdef USE_IRRADIANCE_DOMINANT_DIRECTION
960
+ ,reflectionDominantDirection: vec3f
961
+ #endif
962
+ #endif
963
+ #ifndef LODBASEDMICROSFURACE
964
+ #ifdef REFLECTIONMAP_3D
965
+ ,reflectionLowSampler: texture_cube<f32>
966
+ ,reflectionLowSamplerSampler: sampler
967
+ ,reflectionHighSampler: texture_cube<f32>
968
+ ,reflectionHighSamplerSampler: sampler
969
+ #else
970
+ ,reflectionLowSampler: texture_2d<f32>
971
+ ,reflectionLowSamplerSampler: sampler
972
+ ,reflectionHighSampler: texture_2d<f32>
973
+ ,reflectionHighSamplerSampler: sampler
974
+ #endif
975
+ #endif
976
+ #ifdef REALTIME_FILTERING
977
+ ,vReflectionFilteringInfo: vec2f
978
+ #ifdef IBL_CDF_FILTERING
979
+ ,icdfSampler: texture_2d<f32>
980
+ ,icdfSamplerSampler: sampler
981
+ #endif
982
+ #endif
983
+ ,viewDirectionW: vec3f
984
+ ,diffuseRoughness: f32
985
+ ,surfaceAlbedo: vec3f
986
+ )->reflectionOutParams
987
+ {var outParams: reflectionOutParams;var environmentRadiance: vec4f= vec4f(0.,0.,0.,0.);
988
+ #ifdef REFLECTIONMAP_3D
989
+ var reflectionCoords: vec3f= vec3f(0.);
990
+ #else
991
+ var reflectionCoords: vec2f= vec2f(0.);
992
+ #endif
993
+ reflectionCoords=createReflectionCoords(
994
+ vPositionW,
995
+ normalW,
996
+ #ifdef ANISOTROPIC
997
+ anisotropicOut,
998
+ #endif
999
+ );environmentRadiance=sampleReflectionTexture(
1000
+ alphaG
1001
+ ,vReflectionMicrosurfaceInfos
1002
+ ,vReflectionInfos
1003
+ ,vReflectionColor
1004
+ #if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)
1005
+ ,NdotVUnclamped
1006
+ #endif
1007
+ #ifdef LINEARSPECULARREFLECTION
1008
+ ,roughness
1009
+ #endif
1010
+ #ifdef REFLECTIONMAP_3D
1011
+ ,reflectionSampler
1012
+ ,reflectionSamplerSampler
1013
+ ,reflectionCoords
1014
+ #else
1015
+ ,reflectionSampler
1016
+ ,reflectionSamplerSampler
1017
+ ,reflectionCoords
1018
+ #endif
1019
+ #ifndef LODBASEDMICROSFURACE
1020
+ ,reflectionLowSampler
1021
+ ,reflectionLowSamplerSampler
1022
+ ,reflectionHighSampler
1023
+ ,reflectionHighSamplerSampler
1024
+ #endif
1025
+ #ifdef REALTIME_FILTERING
1026
+ ,vReflectionFilteringInfo
1027
+ #endif
1028
+ );var environmentIrradiance: vec3f= vec3f(0.,0.,0.);
1029
+ #if (defined(USESPHERICALFROMREFLECTIONMAP) && (!defined(NORMAL) || !defined(USESPHERICALINVERTEX))) || (defined(USEIRRADIANCEMAP) && defined(REFLECTIONMAP_3D))
1030
+ #ifdef ANISOTROPIC
1031
+ var irradianceVector: vec3f= (reflectionMatrix* vec4f(anisotropicOut.anisotropicNormal,0)).xyz;
1032
+ #else
1033
+ var irradianceVector: vec3f= (reflectionMatrix* vec4f(normalW,0)).xyz;
1034
+ #endif
1035
+ var irradianceView: vec3f= (reflectionMatrix* vec4f(viewDirectionW,0)).xyz;
1036
+ #if !defined(USE_IRRADIANCE_DOMINANT_DIRECTION) && !defined(REALTIME_FILTERING)
1037
+ #if BASE_DIFFUSE_MODEL != BRDF_DIFFUSE_MODEL_LAMBERT && BASE_DIFFUSE_MODEL != BRDF_DIFFUSE_MODEL_LEGACY
1038
+ var NdotV: f32=max(dot(normalW,viewDirectionW),0.0);irradianceVector=mix(irradianceVector,irradianceView,(0.5*(1.0-NdotV))*diffuseRoughness);
1039
+ #endif
1040
+ #endif
1041
+ #ifdef REFLECTIONMAP_OPPOSITEZ
1042
+ irradianceVector.z*=-1.0;
1043
+ #endif
1044
+ #ifdef INVERTCUBICMAP
1045
+ irradianceVector.y*=-1.0;
1046
+ #endif
1047
+ #endif
1048
+ #ifdef USESPHERICALFROMREFLECTIONMAP
1049
+ #if defined(NORMAL) && defined(USESPHERICALINVERTEX)
1050
+ environmentIrradiance=vEnvironmentIrradiance;
1051
+ #else
1052
+ #if defined(REALTIME_FILTERING)
1053
+ environmentIrradiance=irradiance(reflectionSampler,reflectionSamplerSampler,irradianceVector,vReflectionFilteringInfo,diffuseRoughness,surfaceAlbedo,irradianceView
1054
+ #ifdef IBL_CDF_FILTERING
1055
+ ,icdfSampler
1056
+ ,icdfSamplerSampler
1057
+ #endif
1058
+ );
1059
+ #else
1060
+ environmentIrradiance=computeEnvironmentIrradiance(irradianceVector);
1061
+ #endif
1062
+ #ifdef SS_TRANSLUCENCY
1063
+ outParams.irradianceVector=irradianceVector;
1064
+ #endif
1065
+ #endif
1066
+ #elif defined(USEIRRADIANCEMAP)
1067
+ #ifdef REFLECTIONMAP_3D
1068
+ var environmentIrradiance4: vec4f=textureSample(irradianceSampler,irradianceSamplerSampler,irradianceVector);
1069
+ #else
1070
+ var environmentIrradiance4: vec4f=textureSample(irradianceSampler,irradianceSamplerSampler,reflectionCoords);
1071
+ #endif
1072
+ #ifdef USE_IRRADIANCE_DOMINANT_DIRECTION
1073
+ var Ls: vec3f=normalize(reflectionDominantDirection);var NoL: f32=dot(irradianceVector,Ls);var NoV: f32=dot(irradianceVector,irradianceView);var diffuseRoughnessTerm: vec3f=vec3f(1.0);
1074
+ #if BASE_DIFFUSE_MODEL==BRDF_DIFFUSE_MODEL_EON
1075
+ var LoV: f32=dot(Ls,irradianceView);var mag: f32=length(reflectionDominantDirection)*2.0f;var clampedAlbedo: vec3f=clamp(surfaceAlbedo,vec3f(0.1),vec3f(1.0));diffuseRoughnessTerm=diffuseBRDF_EON(clampedAlbedo,diffuseRoughness,NoL,NoV,LoV)*PI;diffuseRoughnessTerm=diffuseRoughnessTerm/clampedAlbedo;diffuseRoughnessTerm=mix(vec3f(1.0),diffuseRoughnessTerm,sqrt(clamp(mag*NoV,0.0,1.0f)));
1076
+ #elif BASE_DIFFUSE_MODEL==BRDF_DIFFUSE_MODEL_BURLEY
1077
+ var H: vec3f=(irradianceView+Ls)*0.5f;var VoH: f32=dot(irradianceView,H);diffuseRoughnessTerm=vec3f(diffuseBRDF_Burley(NoL,NoV,VoH,diffuseRoughness)*PI);
1078
+ #endif
1079
+ environmentIrradiance=environmentIrradiance4.rgb*diffuseRoughnessTerm;
1080
+ #else
1081
+ environmentIrradiance=environmentIrradiance4.rgb;
1082
+ #endif
1083
+ #ifdef RGBDREFLECTION
1084
+ environmentIrradiance=fromRGBD(environmentIrradiance4);
1085
+ #endif
1086
+ #ifdef GAMMAREFLECTION
1087
+ environmentIrradiance=toLinearSpaceVec3(environmentIrradiance.rgb);
1088
+ #endif
1089
+ #endif
1090
+ environmentIrradiance*=vReflectionColor.rgb*vReflectionInfos.x;
1091
+ #ifdef MIX_IBL_RADIANCE_WITH_IRRADIANCE
1092
+ outParams.environmentRadiance=vec4f(mix(environmentRadiance.rgb,environmentIrradiance,alphaG),environmentRadiance.a);
1093
+ #else
1094
+ outParams.environmentRadiance=environmentRadiance;
1095
+ #endif
1096
+ outParams.environmentIrradiance=environmentIrradiance;outParams.reflectionCoords=reflectionCoords;return outParams;}
1097
+ #endif
1098
+ `;
1099
+ e.IncludesShadersStoreWGSL[C] || (e.IncludesShadersStoreWGSL[C] = Q);
1100
+ const p = "pbrBlockSheen", ee = `#ifdef SHEEN
1101
+ struct sheenOutParams
1102
+ {sheenIntensity: f32
1103
+ ,sheenColor: vec3f
1104
+ ,sheenRoughness: f32
1105
+ #ifdef SHEEN_LINKWITHALBEDO
1106
+ ,surfaceAlbedo: vec3f
1107
+ #endif
1108
+ #if defined(ENVIRONMENTBRDF) && defined(SHEEN_ALBEDOSCALING)
1109
+ ,sheenAlbedoScaling: f32
1110
+ #endif
1111
+ #if defined(REFLECTION) && defined(ENVIRONMENTBRDF)
1112
+ ,finalSheenRadianceScaled: vec3f
1113
+ #endif
1114
+ #if DEBUGMODE>0
1115
+ #ifdef SHEEN_TEXTURE
1116
+ ,sheenMapData: vec4f
1117
+ #endif
1118
+ #if defined(REFLECTION) && defined(ENVIRONMENTBRDF)
1119
+ ,sheenEnvironmentReflectance: vec3f
1120
+ #endif
1121
+ #endif
1122
+ };
1123
+ #define pbr_inline
1124
+ fn sheenBlock(
1125
+ vSheenColor: vec4f
1126
+ #ifdef SHEEN_ROUGHNESS
1127
+ ,vSheenRoughness: f32
1128
+ #if defined(SHEEN_TEXTURE_ROUGHNESS) && !defined(SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE)
1129
+ ,sheenMapRoughnessData: vec4f
1130
+ #endif
1131
+ #endif
1132
+ ,roughness: f32
1133
+ #ifdef SHEEN_TEXTURE
1134
+ ,sheenMapData: vec4f
1135
+ ,sheenMapLevel: f32
1136
+ #endif
1137
+ ,reflectance: f32
1138
+ #ifdef SHEEN_LINKWITHALBEDO
1139
+ ,baseColor: vec3f
1140
+ ,surfaceAlbedo: vec3f
1141
+ #endif
1142
+ #ifdef ENVIRONMENTBRDF
1143
+ ,NdotV: f32
1144
+ ,environmentBrdf: vec3f
1145
+ #endif
1146
+ #if defined(REFLECTION) && defined(ENVIRONMENTBRDF)
1147
+ ,AARoughnessFactors: vec2f
1148
+ ,vReflectionMicrosurfaceInfos: vec3f
1149
+ ,vReflectionInfos: vec2f
1150
+ ,vReflectionColor: vec3f
1151
+ ,vLightingIntensity: vec4f
1152
+ #ifdef REFLECTIONMAP_3D
1153
+ ,reflectionSampler: texture_cube<f32>
1154
+ ,reflectionSamplerSampler: sampler
1155
+ ,reflectionCoords: vec3f
1156
+ #else
1157
+ ,reflectionSampler: texture_2d<f32>
1158
+ ,reflectionSamplerSampler: sampler
1159
+ ,reflectionCoords: vec2f
1160
+ #endif
1161
+ ,NdotVUnclamped: f32
1162
+ #ifndef LODBASEDMICROSFURACE
1163
+ #ifdef REFLECTIONMAP_3D
1164
+ ,reflectionLowSampler: texture_cube<f32>
1165
+ ,reflectionLowSamplerSampler: sampler
1166
+ ,reflectionHighSampler: texture_cube<f32>
1167
+ ,reflectionHighSamplerSampler: sampler
1168
+ #else
1169
+ ,reflectionLowSampler: texture_2d<f32>
1170
+ ,reflectionLowSamplerSampler: sampler
1171
+ ,reflectionHighSampler: texture_2d<f32>
1172
+ ,reflectionHighSamplerSampler: sampler
1173
+ #endif
1174
+ #endif
1175
+ #ifdef REALTIME_FILTERING
1176
+ ,vReflectionFilteringInfo: vec2f
1177
+ #endif
1178
+ #if !defined(REFLECTIONMAP_SKYBOX) && defined(RADIANCEOCCLUSION)
1179
+ ,seo: f32
1180
+ #endif
1181
+ #if !defined(REFLECTIONMAP_SKYBOX) && defined(HORIZONOCCLUSION) && defined(BUMP) && defined(REFLECTIONMAP_3D)
1182
+ ,eho: f32
1183
+ #endif
1184
+ #endif
1185
+ )->sheenOutParams
1186
+ {var outParams: sheenOutParams;var sheenIntensity: f32=vSheenColor.a;
1187
+ #ifdef SHEEN_TEXTURE
1188
+ #if DEBUGMODE>0
1189
+ outParams.sheenMapData=sheenMapData;
1190
+ #endif
1191
+ #endif
1192
+ #ifdef SHEEN_LINKWITHALBEDO
1193
+ var sheenFactor: f32=pow5(1.0-sheenIntensity);var sheenColor: vec3f=baseColor.rgb*(1.0-sheenFactor);var sheenRoughness: f32=sheenIntensity;outParams.surfaceAlbedo=surfaceAlbedo*sheenFactor;
1194
+ #ifdef SHEEN_TEXTURE
1195
+ sheenIntensity*=sheenMapData.a;
1196
+ #endif
1197
+ #else
1198
+ var sheenColor: vec3f=vSheenColor.rgb;
1199
+ #ifdef SHEEN_TEXTURE
1200
+ #ifdef SHEEN_GAMMATEXTURE
1201
+ sheenColor*=toLinearSpaceVec3(sheenMapData.rgb);
1202
+ #else
1203
+ sheenColor*=sheenMapData.rgb;
1204
+ #endif
1205
+ sheenColor*=sheenMapLevel;
1206
+ #endif
1207
+ #ifdef SHEEN_ROUGHNESS
1208
+ var sheenRoughness: f32=vSheenRoughness;
1209
+ #ifdef SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE
1210
+ #if defined(SHEEN_TEXTURE)
1211
+ sheenRoughness*=sheenMapData.a;
1212
+ #endif
1213
+ #elif defined(SHEEN_TEXTURE_ROUGHNESS)
1214
+ sheenRoughness*=sheenMapRoughnessData.a;
1215
+ #endif
1216
+ #else
1217
+ var sheenRoughness: f32=roughness;
1218
+ #ifdef SHEEN_TEXTURE
1219
+ sheenIntensity*=sheenMapData.a;
1220
+ #endif
1221
+ #endif
1222
+ #if !defined(SHEEN_ALBEDOSCALING)
1223
+ sheenIntensity*=(1.-reflectance);
1224
+ #endif
1225
+ sheenColor*=sheenIntensity;
1226
+ #endif
1227
+ #ifdef ENVIRONMENTBRDF
1228
+ /*#ifdef SHEEN_SOFTER
1229
+ var environmentSheenBrdf: vec3f= vec3f(0.,0.,getBRDFLookupCharlieSheen(NdotV,sheenRoughness));
1230
+ #else*/
1231
+ #ifdef SHEEN_ROUGHNESS
1232
+ var environmentSheenBrdf: vec3f=getBRDFLookup(NdotV,sheenRoughness);
1233
+ #else
1234
+ var environmentSheenBrdf: vec3f=environmentBrdf;
1235
+ #endif
1236
+ /*#endif*/
1237
+ #endif
1238
+ #if defined(REFLECTION) && defined(ENVIRONMENTBRDF)
1239
+ var sheenAlphaG: f32=convertRoughnessToAverageSlope(sheenRoughness);
1240
+ #ifdef SPECULARAA
1241
+ sheenAlphaG+=AARoughnessFactors.y;
1242
+ #endif
1243
+ var environmentSheenRadiance: vec4f= vec4f(0.,0.,0.,0.);environmentSheenRadiance=sampleReflectionTexture(
1244
+ sheenAlphaG
1245
+ ,vReflectionMicrosurfaceInfos
1246
+ ,vReflectionInfos
1247
+ ,vReflectionColor
1248
+ #if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)
1249
+ ,NdotVUnclamped
1250
+ #endif
1251
+ #ifdef LINEARSPECULARREFLECTION
1252
+ ,sheenRoughness
1253
+ #endif
1254
+ ,reflectionSampler
1255
+ ,reflectionSamplerSampler
1256
+ ,reflectionCoords
1257
+ #ifndef LODBASEDMICROSFURACE
1258
+ ,reflectionLowSampler
1259
+ ,reflectionLowSamplerSampler
1260
+ ,reflectionHighSampler
1261
+ ,reflectionHighSamplerSampler
1262
+ #endif
1263
+ #ifdef REALTIME_FILTERING
1264
+ ,vReflectionFilteringInfo
1265
+ #endif
1266
+ );var sheenEnvironmentReflectance: vec3f=getSheenReflectanceFromBRDFLookup(sheenColor,environmentSheenBrdf);
1267
+ #if !defined(REFLECTIONMAP_SKYBOX) && defined(RADIANCEOCCLUSION)
1268
+ sheenEnvironmentReflectance*=seo;
1269
+ #endif
1270
+ #if !defined(REFLECTIONMAP_SKYBOX) && defined(HORIZONOCCLUSION) && defined(BUMP) && defined(REFLECTIONMAP_3D)
1271
+ sheenEnvironmentReflectance*=eho;
1272
+ #endif
1273
+ #if DEBUGMODE>0
1274
+ outParams.sheenEnvironmentReflectance=sheenEnvironmentReflectance;
1275
+ #endif
1276
+ outParams.finalSheenRadianceScaled=
1277
+ environmentSheenRadiance.rgb *
1278
+ sheenEnvironmentReflectance *
1279
+ vLightingIntensity.z;
1280
+ #endif
1281
+ #if defined(ENVIRONMENTBRDF) && defined(SHEEN_ALBEDOSCALING)
1282
+ outParams.sheenAlbedoScaling=1.0-sheenIntensity*max(max(sheenColor.r,sheenColor.g),sheenColor.b)*environmentSheenBrdf.b;
1283
+ #endif
1284
+ outParams.sheenIntensity=sheenIntensity;outParams.sheenColor=sheenColor;outParams.sheenRoughness=sheenRoughness;return outParams;}
1285
+ #endif
1286
+ `;
1287
+ e.IncludesShadersStoreWGSL[p] || (e.IncludesShadersStoreWGSL[p] = ee);
1288
+ const A = "pbrBlockClearcoat", ie = `struct clearcoatOutParams
1289
+ {specularEnvironmentR0: vec3f,
1290
+ conservationFactor: f32,
1291
+ clearCoatNormalW: vec3f,
1292
+ clearCoatAARoughnessFactors: vec2f,
1293
+ clearCoatIntensity: f32,
1294
+ clearCoatRoughness: f32,
1295
+ #ifdef REFLECTION
1296
+ finalClearCoatRadianceScaled: vec3f,
1297
+ #endif
1298
+ #ifdef CLEARCOAT_TINT
1299
+ absorption: vec3f,
1300
+ clearCoatNdotVRefract: f32,
1301
+ clearCoatColor: vec3f,
1302
+ clearCoatThickness: f32,
1303
+ #endif
1304
+ #if defined(ENVIRONMENTBRDF) && defined(MS_BRDF_ENERGY_CONSERVATION)
1305
+ energyConservationFactorClearCoat: vec3f,
1306
+ #endif
1307
+ #if DEBUGMODE>0
1308
+ #ifdef CLEARCOAT_BUMP
1309
+ TBNClearCoat: mat3x3f,
1310
+ #endif
1311
+ #ifdef CLEARCOAT_TEXTURE
1312
+ clearCoatMapData: vec2f,
1313
+ #endif
1314
+ #if defined(CLEARCOAT_TINT) && defined(CLEARCOAT_TINT_TEXTURE)
1315
+ clearCoatTintMapData: vec4f,
1316
+ #endif
1317
+ #ifdef REFLECTION
1318
+ environmentClearCoatRadiance: vec4f,
1319
+ clearCoatEnvironmentReflectance: vec3f,
1320
+ #endif
1321
+ clearCoatNdotV: f32
1322
+ #endif
1323
+ };
1324
+ #ifdef CLEARCOAT
1325
+ #define pbr_inline
1326
+ fn clearcoatBlock(
1327
+ vPositionW: vec3f
1328
+ ,geometricNormalW: vec3f
1329
+ ,viewDirectionW: vec3f
1330
+ ,vClearCoatParams: vec2f
1331
+ #if defined(CLEARCOAT_TEXTURE_ROUGHNESS) && !defined(CLEARCOAT_TEXTURE_ROUGHNESS_IDENTICAL) && !defined(CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE)
1332
+ ,clearCoatMapRoughnessData: vec4f
1333
+ #endif
1334
+ ,specularEnvironmentR0: vec3f
1335
+ #ifdef CLEARCOAT_TEXTURE
1336
+ ,clearCoatMapData: vec2f
1337
+ #endif
1338
+ #ifdef CLEARCOAT_TINT
1339
+ ,vClearCoatTintParams: vec4f
1340
+ ,clearCoatColorAtDistance: f32
1341
+ ,vClearCoatRefractionParams: vec4f
1342
+ #ifdef CLEARCOAT_TINT_TEXTURE
1343
+ ,clearCoatTintMapData: vec4f
1344
+ #endif
1345
+ #endif
1346
+ #ifdef CLEARCOAT_BUMP
1347
+ ,vClearCoatBumpInfos: vec2f
1348
+ ,clearCoatBumpMapData: vec4f
1349
+ ,vClearCoatBumpUV: vec2f
1350
+ #if defined(TANGENT) && defined(NORMAL)
1351
+ ,vTBN: mat3x3f
1352
+ #else
1353
+ ,vClearCoatTangentSpaceParams: vec2f
1354
+ #endif
1355
+ #ifdef OBJECTSPACE_NORMALMAP
1356
+ ,normalMatrix: mat4x4f
1357
+ #endif
1358
+ #endif
1359
+ #if defined(FORCENORMALFORWARD) && defined(NORMAL)
1360
+ ,faceNormal: vec3f
1361
+ #endif
1362
+ #ifdef REFLECTION
1363
+ ,vReflectionMicrosurfaceInfos: vec3f
1364
+ ,vReflectionInfos: vec2f
1365
+ ,vReflectionColor: vec3f
1366
+ ,vLightingIntensity: vec4f
1367
+ #ifdef REFLECTIONMAP_3D
1368
+ ,reflectionSampler: texture_cube<f32>
1369
+ ,reflectionSamplerSampler: sampler
1370
+ #else
1371
+ ,reflectionSampler: texture_2d<f32>
1372
+ ,reflectionSamplerSampler: sampler
1373
+ #endif
1374
+ #ifndef LODBASEDMICROSFURACE
1375
+ #ifdef REFLECTIONMAP_3D
1376
+ ,reflectionLowSampler: texture_cube<f32>
1377
+ ,reflectionLowSamplerSampler: sampler
1378
+ ,reflectionHighSampler: texture_cube<f32>
1379
+ ,reflectionHighSamplerSampler: sampler
1380
+ #else
1381
+ ,reflectionLowSampler: texture_2d<f32>
1382
+ ,reflectionLowSamplerSampler: sampler
1383
+ ,reflectionHighSampler: texture_2d<f32>
1384
+ ,reflectionHighSamplerSampler: sampler
1385
+ #endif
1386
+ #endif
1387
+ #ifdef REALTIME_FILTERING
1388
+ ,vReflectionFilteringInfo: vec2f
1389
+ #endif
1390
+ #endif
1391
+ #if defined(CLEARCOAT_BUMP) || defined(TWOSIDEDLIGHTING)
1392
+ ,frontFacingMultiplier: f32
1393
+ #endif
1394
+ )->clearcoatOutParams
1395
+ {var outParams: clearcoatOutParams;var clearCoatIntensity: f32=vClearCoatParams.x;var clearCoatRoughness: f32=vClearCoatParams.y;
1396
+ #ifdef CLEARCOAT_TEXTURE
1397
+ clearCoatIntensity*=clearCoatMapData.x;
1398
+ #ifdef CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE
1399
+ clearCoatRoughness*=clearCoatMapData.y;
1400
+ #endif
1401
+ #if DEBUGMODE>0
1402
+ outParams.clearCoatMapData=clearCoatMapData;
1403
+ #endif
1404
+ #endif
1405
+ #if defined(CLEARCOAT_TEXTURE_ROUGHNESS) && !defined(CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE)
1406
+ clearCoatRoughness*=clearCoatMapRoughnessData.y;
1407
+ #endif
1408
+ outParams.clearCoatIntensity=clearCoatIntensity;outParams.clearCoatRoughness=clearCoatRoughness;
1409
+ #ifdef CLEARCOAT_TINT
1410
+ var clearCoatColor: vec3f=vClearCoatTintParams.rgb;var clearCoatThickness: f32=vClearCoatTintParams.a;
1411
+ #ifdef CLEARCOAT_TINT_TEXTURE
1412
+ #ifdef CLEARCOAT_TINT_GAMMATEXTURE
1413
+ clearCoatColor*=toLinearSpaceVec3(clearCoatTintMapData.rgb);
1414
+ #else
1415
+ clearCoatColor*=clearCoatTintMapData.rgb;
1416
+ #endif
1417
+ clearCoatThickness*=clearCoatTintMapData.a;
1418
+ #if DEBUGMODE>0
1419
+ outParams.clearCoatTintMapData=clearCoatTintMapData;
1420
+ #endif
1421
+ #endif
1422
+ outParams.clearCoatColor=computeColorAtDistanceInMedia(clearCoatColor,clearCoatColorAtDistance);outParams.clearCoatThickness=clearCoatThickness;
1423
+ #endif
1424
+ #ifdef CLEARCOAT_REMAP_F0
1425
+ var specularEnvironmentR0Updated: vec3f=getR0RemappedForClearCoat(specularEnvironmentR0);
1426
+ #else
1427
+ var specularEnvironmentR0Updated: vec3f=specularEnvironmentR0;
1428
+ #endif
1429
+ outParams.specularEnvironmentR0=mix(specularEnvironmentR0,specularEnvironmentR0Updated,clearCoatIntensity);var clearCoatNormalW: vec3f=geometricNormalW;
1430
+ #ifdef CLEARCOAT_BUMP
1431
+ #ifdef NORMALXYSCALE
1432
+ var clearCoatNormalScale: f32=1.0;
1433
+ #else
1434
+ var clearCoatNormalScale: f32=vClearCoatBumpInfos.y;
1435
+ #endif
1436
+ #if defined(TANGENT) && defined(NORMAL)
1437
+ var TBNClearCoat: mat3x3f=vTBN;
1438
+ #else
1439
+ var TBNClearCoatUV: vec2f=vClearCoatBumpUV*frontFacingMultiplier;var TBNClearCoat: mat3x3f=cotangent_frame(clearCoatNormalW*clearCoatNormalScale,vPositionW,TBNClearCoatUV,vClearCoatTangentSpaceParams);
1440
+ #endif
1441
+ #if DEBUGMODE>0
1442
+ outParams.TBNClearCoat=TBNClearCoat;
1443
+ #endif
1444
+ #ifdef OBJECTSPACE_NORMALMAP
1445
+ clearCoatNormalW=normalize(clearCoatBumpMapData.xyz *2.0-1.0);clearCoatNormalW=normalize( mat3x3f(normalMatrix[0].xyz,normalMatrix[1].xyz,normalMatrix[2].xyz)*clearCoatNormalW);
1446
+ #else
1447
+ clearCoatNormalW=perturbNormal(TBNClearCoat,clearCoatBumpMapData.xyz,vClearCoatBumpInfos.y);
1448
+ #endif
1449
+ #endif
1450
+ #if defined(FORCENORMALFORWARD) && defined(NORMAL)
1451
+ clearCoatNormalW*=sign(dot(clearCoatNormalW,faceNormal));
1452
+ #endif
1453
+ #if defined(TWOSIDEDLIGHTING) && defined(NORMAL)
1454
+ clearCoatNormalW=clearCoatNormalW*frontFacingMultiplier;
1455
+ #endif
1456
+ outParams.clearCoatNormalW=clearCoatNormalW;outParams.clearCoatAARoughnessFactors=getAARoughnessFactors(clearCoatNormalW.xyz);var clearCoatNdotVUnclamped: f32=dot(clearCoatNormalW,viewDirectionW);var clearCoatNdotV: f32=absEps(clearCoatNdotVUnclamped);
1457
+ #if DEBUGMODE>0
1458
+ outParams.clearCoatNdotV=clearCoatNdotV;
1459
+ #endif
1460
+ #ifdef CLEARCOAT_TINT
1461
+ var clearCoatVRefract: vec3f=refract(-viewDirectionW,clearCoatNormalW,vClearCoatRefractionParams.y);outParams.clearCoatNdotVRefract=absEps(dot(clearCoatNormalW,clearCoatVRefract));
1462
+ #endif
1463
+ #if defined(ENVIRONMENTBRDF) && (!defined(REFLECTIONMAP_SKYBOX) || defined(MS_BRDF_ENERGY_CONSERVATION))
1464
+ var environmentClearCoatBrdf: vec3f=getBRDFLookup(clearCoatNdotV,clearCoatRoughness);
1465
+ #endif
1466
+ #if defined(REFLECTION)
1467
+ var clearCoatAlphaG: f32=convertRoughnessToAverageSlope(clearCoatRoughness);
1468
+ #ifdef SPECULARAA
1469
+ clearCoatAlphaG+=outParams.clearCoatAARoughnessFactors.y;
1470
+ #endif
1471
+ var environmentClearCoatRadiance: vec4f= vec4f(0.,0.,0.,0.);var clearCoatReflectionVector: vec3f=computeReflectionCoords( vec4f(vPositionW,1.0),clearCoatNormalW);
1472
+ #ifdef REFLECTIONMAP_OPPOSITEZ
1473
+ clearCoatReflectionVector.z*=-1.0;
1474
+ #endif
1475
+ #ifdef REFLECTIONMAP_3D
1476
+ var clearCoatReflectionCoords: vec3f=clearCoatReflectionVector;
1477
+ #else
1478
+ var clearCoatReflectionCoords: vec2f=clearCoatReflectionVector.xy;
1479
+ #ifdef REFLECTIONMAP_PROJECTION
1480
+ clearCoatReflectionCoords/=clearCoatReflectionVector.z;
1481
+ #endif
1482
+ clearCoatReflectionCoords.y=1.0-clearCoatReflectionCoords.y;
1483
+ #endif
1484
+ environmentClearCoatRadiance=sampleReflectionTexture(
1485
+ clearCoatAlphaG
1486
+ ,vReflectionMicrosurfaceInfos
1487
+ ,vReflectionInfos
1488
+ ,vReflectionColor
1489
+ #if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)
1490
+ ,clearCoatNdotVUnclamped
1491
+ #endif
1492
+ #ifdef LINEARSPECULARREFLECTION
1493
+ ,clearCoatRoughness
1494
+ #endif
1495
+ ,reflectionSampler
1496
+ ,reflectionSamplerSampler
1497
+ ,clearCoatReflectionCoords
1498
+ #ifndef LODBASEDMICROSFURACE
1499
+ ,reflectionLowSampler
1500
+ ,reflectionLowSamplerSampler
1501
+ ,reflectionHighSampler
1502
+ ,reflectionHighSamplerSampler
1503
+ #endif
1504
+ #ifdef REALTIME_FILTERING
1505
+ ,vReflectionFilteringInfo
1506
+ #endif
1507
+ );
1508
+ #if DEBUGMODE>0
1509
+ outParams.environmentClearCoatRadiance=environmentClearCoatRadiance;
1510
+ #endif
1511
+ #if defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)
1512
+ var clearCoatEnvironmentReflectance: vec3f=getReflectanceFromBRDFLookup(vec3f(uniforms.vClearCoatRefractionParams.x),environmentClearCoatBrdf);
1513
+ #ifdef HORIZONOCCLUSION
1514
+ #ifdef BUMP
1515
+ #ifdef REFLECTIONMAP_3D
1516
+ var clearCoatEho: f32=environmentHorizonOcclusion(-viewDirectionW,clearCoatNormalW,geometricNormalW);clearCoatEnvironmentReflectance*=clearCoatEho;
1517
+ #endif
1518
+ #endif
1519
+ #endif
1520
+ #else
1521
+ var clearCoatEnvironmentReflectance: vec3f=getReflectanceFromAnalyticalBRDFLookup_Jones(clearCoatNdotV, vec3f(1.), vec3f(1.),sqrt(1.-clearCoatRoughness));
1522
+ #endif
1523
+ clearCoatEnvironmentReflectance*=clearCoatIntensity;
1524
+ #if DEBUGMODE>0
1525
+ outParams.clearCoatEnvironmentReflectance=clearCoatEnvironmentReflectance;
1526
+ #endif
1527
+ outParams.finalClearCoatRadianceScaled=
1528
+ environmentClearCoatRadiance.rgb *
1529
+ clearCoatEnvironmentReflectance *
1530
+ vLightingIntensity.z;
1531
+ #endif
1532
+ #if defined(CLEARCOAT_TINT)
1533
+ outParams.absorption=computeClearCoatAbsorption(outParams.clearCoatNdotVRefract,outParams.clearCoatNdotVRefract,outParams.clearCoatColor,clearCoatThickness,clearCoatIntensity);
1534
+ #endif
1535
+ var fresnelIBLClearCoat: f32=fresnelSchlickGGX(clearCoatNdotV,uniforms.vClearCoatRefractionParams.x,CLEARCOATREFLECTANCE90);fresnelIBLClearCoat*=clearCoatIntensity;outParams.conservationFactor=(1.-fresnelIBLClearCoat);
1536
+ #if defined(ENVIRONMENTBRDF) && defined(MS_BRDF_ENERGY_CONSERVATION)
1537
+ outParams.energyConservationFactorClearCoat=getEnergyConservationFactor(outParams.specularEnvironmentR0,environmentClearCoatBrdf);
1538
+ #endif
1539
+ return outParams;}
1540
+ #endif
1541
+ `;
1542
+ e.IncludesShadersStoreWGSL[A] || (e.IncludesShadersStoreWGSL[A] = ie);
1543
+ const I = "pbrBlockIridescence", re = `struct iridescenceOutParams
1544
+ {iridescenceIntensity: f32,
1545
+ iridescenceIOR: f32,
1546
+ iridescenceThickness: f32,
1547
+ specularEnvironmentR0: vec3f};
1548
+ #ifdef IRIDESCENCE
1549
+ fn iridescenceBlock(
1550
+ vIridescenceParams: vec4f
1551
+ ,viewAngle_: f32
1552
+ ,specularEnvironmentR0: vec3f
1553
+ #ifdef IRIDESCENCE_TEXTURE
1554
+ ,iridescenceMapData: vec2f
1555
+ #endif
1556
+ #ifdef IRIDESCENCE_THICKNESS_TEXTURE
1557
+ ,iridescenceThicknessMapData: vec2f
1558
+ #endif
1559
+ #ifdef CLEARCOAT
1560
+ ,NdotVUnclamped: f32
1561
+ ,vClearCoatParams: vec2f
1562
+ #ifdef CLEARCOAT_TEXTURE
1563
+ ,clearCoatMapData: vec2f
1564
+ #endif
1565
+ #endif
1566
+ )->iridescenceOutParams
1567
+ {var outParams: iridescenceOutParams;var iridescenceIntensity: f32=vIridescenceParams.x;var iridescenceIOR: f32=vIridescenceParams.y;var iridescenceThicknessMin: f32=vIridescenceParams.z;var iridescenceThicknessMax: f32=vIridescenceParams.w;var iridescenceThicknessWeight: f32=1.;var viewAngle=viewAngle_;
1568
+ #ifdef IRIDESCENCE_TEXTURE
1569
+ iridescenceIntensity*=iridescenceMapData.x;
1570
+ #endif
1571
+ #if defined(IRIDESCENCE_THICKNESS_TEXTURE)
1572
+ iridescenceThicknessWeight=iridescenceThicknessMapData.g;
1573
+ #endif
1574
+ var iridescenceThickness: f32=mix(iridescenceThicknessMin,iridescenceThicknessMax,iridescenceThicknessWeight);var topIor: f32=1.;
1575
+ #ifdef CLEARCOAT
1576
+ var clearCoatIntensity: f32=vClearCoatParams.x;
1577
+ #ifdef CLEARCOAT_TEXTURE
1578
+ clearCoatIntensity*=clearCoatMapData.x;
1579
+ #endif
1580
+ topIor=mix(1.0,uniforms.vClearCoatRefractionParams.w-1.,clearCoatIntensity);viewAngle=sqrt(1.0+((1.0/topIor)*(1.0/topIor))*((NdotVUnclamped*NdotVUnclamped)-1.0));
1581
+ #endif
1582
+ var iridescenceFresnel: vec3f=evalIridescence(topIor,iridescenceIOR,viewAngle,iridescenceThickness,specularEnvironmentR0);outParams.specularEnvironmentR0=mix(specularEnvironmentR0,iridescenceFresnel,iridescenceIntensity);outParams.iridescenceIntensity=iridescenceIntensity;outParams.iridescenceThickness=iridescenceThickness;outParams.iridescenceIOR=iridescenceIOR;return outParams;}
1583
+ #endif
1584
+ `;
1585
+ e.IncludesShadersStoreWGSL[I] || (e.IncludesShadersStoreWGSL[I] = re);
1586
+ const N = "pbrBlockSubSurface", ae = `struct subSurfaceOutParams
1587
+ {specularEnvironmentReflectance: vec3f,
1588
+ #ifdef SS_REFRACTION
1589
+ finalRefraction: vec3f,
1590
+ surfaceAlbedo: vec3f,
1591
+ #ifdef SS_LINKREFRACTIONTOTRANSPARENCY
1592
+ alpha: f32,
1593
+ #endif
1594
+ refractionOpacity: f32,
1595
+ #endif
1596
+ #ifdef SS_TRANSLUCENCY
1597
+ transmittance: vec3f,
1598
+ translucencyIntensity: f32,
1599
+ #ifdef REFLECTION
1600
+ refractionIrradiance: vec3f,
1601
+ #endif
1602
+ #endif
1603
+ #if DEBUGMODE>0
1604
+ #ifdef SS_THICKNESSANDMASK_TEXTURE
1605
+ thicknessMap: vec4f,
1606
+ #endif
1607
+ #ifdef SS_REFRACTION
1608
+ environmentRefraction: vec4f,
1609
+ refractionTransmittance: vec3f
1610
+ #endif
1611
+ #endif
1612
+ };
1613
+ #ifdef SUBSURFACE
1614
+ #ifdef SS_REFRACTION
1615
+ #define pbr_inline
1616
+ fn sampleEnvironmentRefraction(
1617
+ ior: f32
1618
+ ,thickness: f32
1619
+ ,refractionLOD: f32
1620
+ ,normalW: vec3f
1621
+ ,vPositionW: vec3f
1622
+ ,viewDirectionW: vec3f
1623
+ ,view: mat4x4f
1624
+ ,vRefractionInfos: vec4f
1625
+ ,refractionMatrix: mat4x4f
1626
+ ,vRefractionMicrosurfaceInfos: vec4f
1627
+ ,alphaG: f32
1628
+ #ifdef SS_REFRACTIONMAP_3D
1629
+ ,refractionSampler: texture_cube<f32>
1630
+ ,refractionSamplerSampler: sampler
1631
+ #ifndef LODBASEDMICROSFURACE
1632
+ ,refractionLowSampler: texture_cube<f32>
1633
+ ,refractionLowSamplerSampler: sampler
1634
+ ,refractionHighSampler: texture_cube<f32>
1635
+ ,refractionHighSamplerSampler: sampler
1636
+ #endif
1637
+ #else
1638
+ ,refractionSampler: texture_2d<f32>
1639
+ ,refractionSamplerSampler: sampler
1640
+ #ifndef LODBASEDMICROSFURACE
1641
+ ,refractionLowSampler: texture_2d<f32>
1642
+ ,refractionLowSamplerSampler: sampler
1643
+ ,refractionHighSampler: texture_2d<f32>
1644
+ ,refractionHighSamplerSampler: sampler
1645
+ #endif
1646
+ #endif
1647
+ #ifdef ANISOTROPIC
1648
+ ,anisotropicOut: anisotropicOutParams
1649
+ #endif
1650
+ #ifdef REALTIME_FILTERING
1651
+ ,vRefractionFilteringInfo: vec2f
1652
+ #endif
1653
+ #ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC
1654
+ ,refractionPosition: vec3f
1655
+ ,refractionSize: vec3f
1656
+ #endif
1657
+ )->vec4f {var environmentRefraction: vec4f= vec4f(0.,0.,0.,0.);
1658
+ #ifdef ANISOTROPIC
1659
+ var refractionVector: vec3f=refract(-viewDirectionW,anisotropicOut.anisotropicNormal,ior);
1660
+ #else
1661
+ var refractionVector: vec3f=refract(-viewDirectionW,normalW,ior);
1662
+ #endif
1663
+ #ifdef SS_REFRACTIONMAP_OPPOSITEZ
1664
+ refractionVector.z*=-1.0;
1665
+ #endif
1666
+ #ifdef SS_REFRACTIONMAP_3D
1667
+ #ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC
1668
+ refractionVector=parallaxCorrectNormal(vPositionW,refractionVector,refractionSize,refractionPosition);
1669
+ #endif
1670
+ refractionVector.y=refractionVector.y*vRefractionInfos.w;var refractionCoords: vec3f=refractionVector;refractionCoords= (refractionMatrix* vec4f(refractionCoords,0)).xyz;
1671
+ #else
1672
+ #ifdef SS_USE_THICKNESS_AS_DEPTH
1673
+ var vRefractionUVW: vec3f= (refractionMatrix*(view* vec4f(vPositionW+refractionVector*thickness,1.0))).xyz;
1674
+ #else
1675
+ var vRefractionUVW: vec3f= (refractionMatrix*(view* vec4f(vPositionW+refractionVector*vRefractionInfos.z,1.0))).xyz;
1676
+ #endif
1677
+ var refractionCoords: vec2f=vRefractionUVW.xy/vRefractionUVW.z;refractionCoords.y=1.0-refractionCoords.y;
1678
+ #endif
1679
+ #ifdef LODBASEDMICROSFURACE
1680
+ var lod=refractionLOD*vRefractionMicrosurfaceInfos.y+vRefractionMicrosurfaceInfos.z;
1681
+ #ifdef SS_LODINREFRACTIONALPHA
1682
+ var automaticRefractionLOD: f32=UNPACK_LOD(textureSample(refractionSampler,refractionSamplerSampler,refractionCoords).a);var requestedRefractionLOD: f32=max(automaticRefractionLOD,lod);
1683
+ #else
1684
+ var requestedRefractionLOD: f32=lod;
1685
+ #endif
1686
+ #if defined(REALTIME_FILTERING) && defined(SS_REFRACTIONMAP_3D)
1687
+ environmentRefraction= vec4f(radiance(alphaG,refractionSampler,refractionSamplerSampler,refractionCoords,vRefractionFilteringInfo),1.0);
1688
+ #else
1689
+ environmentRefraction=textureSampleLevel(refractionSampler,refractionSamplerSampler,refractionCoords,requestedRefractionLOD);
1690
+ #endif
1691
+ #else
1692
+ var lodRefractionNormalized: f32=saturate(refractionLOD/log2(vRefractionMicrosurfaceInfos.x));var lodRefractionNormalizedDoubled: f32=lodRefractionNormalized*2.0;var environmentRefractionMid: vec4f=textureSample(refractionSampler,refractionSamplerSampler,refractionCoords);if (lodRefractionNormalizedDoubled<1.0){environmentRefraction=mix(
1693
+ textureSample(refractionHighSampler,refractionHighSamplerSampler,refractionCoords),
1694
+ environmentRefractionMid,
1695
+ lodRefractionNormalizedDoubled
1696
+ );} else {environmentRefraction=mix(
1697
+ environmentRefractionMid,
1698
+ textureSample(refractionLowSampler,refractionLowSamplerSampler,refractionCoords),
1699
+ lodRefractionNormalizedDoubled-1.0
1700
+ );}
1701
+ #endif
1702
+ var refraction=environmentRefraction.rgb;
1703
+ #ifdef SS_RGBDREFRACTION
1704
+ refraction=fromRGBD(environmentRefraction);
1705
+ #endif
1706
+ #ifdef SS_GAMMAREFRACTION
1707
+ refraction=toLinearSpaceVec3(environmentRefraction.rgb);
1708
+ #endif
1709
+ return vec4f(refraction,environmentRefraction.a);}
1710
+ #endif
1711
+ #define pbr_inline
1712
+ fn subSurfaceBlock(
1713
+ vSubSurfaceIntensity: vec3f
1714
+ ,vThicknessParam: vec2f
1715
+ ,vTintColor: vec4f
1716
+ ,normalW: vec3f
1717
+ ,specularEnvironmentReflectance: vec3f
1718
+ #ifdef SS_THICKNESSANDMASK_TEXTURE
1719
+ ,thicknessMap: vec4f
1720
+ #endif
1721
+ #ifdef SS_REFRACTIONINTENSITY_TEXTURE
1722
+ ,refractionIntensityMap: vec4f
1723
+ #endif
1724
+ #ifdef SS_TRANSLUCENCYINTENSITY_TEXTURE
1725
+ ,translucencyIntensityMap: vec4f
1726
+ #endif
1727
+ #ifdef REFLECTION
1728
+ #ifdef SS_TRANSLUCENCY
1729
+ ,reflectionMatrix: mat4x4f
1730
+ #ifdef USESPHERICALFROMREFLECTIONMAP
1731
+ #if !defined(NORMAL) || !defined(USESPHERICALINVERTEX)
1732
+ ,irradianceVector_: vec3f
1733
+ #endif
1734
+ #if defined(REALTIME_FILTERING)
1735
+ ,reflectionSampler: texture_cube<f32>
1736
+ ,reflectionSamplerSampler: sampler
1737
+ ,vReflectionFilteringInfo: vec2f
1738
+ #ifdef IBL_CDF_FILTERING
1739
+ ,icdfSampler: texture_2d<f32>
1740
+ ,icdfSamplerSampler: sampler
1741
+ #endif
1742
+ #endif
1743
+ #endif
1744
+ #ifdef USEIRRADIANCEMAP
1745
+ #ifdef REFLECTIONMAP_3D
1746
+ ,irradianceSampler: texture_cube<f32>
1747
+ ,irradianceSamplerSampler: sampler
1748
+ #else
1749
+ ,irradianceSampler: texture_2d<f32>
1750
+ ,irradianceSamplerSampler: sampler
1751
+ #endif
1752
+ #endif
1753
+ #endif
1754
+ #endif
1755
+ #if defined(SS_REFRACTION) || defined(SS_TRANSLUCENCY)
1756
+ ,surfaceAlbedo: vec3f
1757
+ #endif
1758
+ #ifdef SS_REFRACTION
1759
+ ,vPositionW: vec3f
1760
+ ,viewDirectionW: vec3f
1761
+ ,view: mat4x4f
1762
+ ,vRefractionInfos: vec4f
1763
+ ,refractionMatrix: mat4x4f
1764
+ ,vRefractionMicrosurfaceInfos: vec4f
1765
+ ,vLightingIntensity: vec4f
1766
+ #ifdef SS_LINKREFRACTIONTOTRANSPARENCY
1767
+ ,alpha: f32
1768
+ #endif
1769
+ #ifdef SS_LODINREFRACTIONALPHA
1770
+ ,NdotVUnclamped: f32
1771
+ #endif
1772
+ #ifdef SS_LINEARSPECULARREFRACTION
1773
+ ,roughness: f32
1774
+ #endif
1775
+ ,alphaG: f32
1776
+ #ifdef SS_REFRACTIONMAP_3D
1777
+ ,refractionSampler: texture_cube<f32>
1778
+ ,refractionSamplerSampler: sampler
1779
+ #ifndef LODBASEDMICROSFURACE
1780
+ ,refractionLowSampler: texture_cube<f32>
1781
+ ,refractionLowSamplerSampler: sampler
1782
+ ,refractionHighSampler: texture_cube<f32>
1783
+ ,refractionHighSamplerSampler: sampler
1784
+ #endif
1785
+ #else
1786
+ ,refractionSampler: texture_2d<f32>
1787
+ ,refractionSamplerSampler: sampler
1788
+ #ifndef LODBASEDMICROSFURACE
1789
+ ,refractionLowSampler: texture_2d<f32>
1790
+ ,refractionLowSamplerSampler: sampler
1791
+ ,refractionHighSampler: texture_2d<f32>
1792
+ ,refractionHighSamplerSampler: sampler
1793
+ #endif
1794
+ #endif
1795
+ #ifdef ANISOTROPIC
1796
+ ,anisotropicOut: anisotropicOutParams
1797
+ #endif
1798
+ #ifdef REALTIME_FILTERING
1799
+ ,vRefractionFilteringInfo: vec2f
1800
+ #endif
1801
+ #ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC
1802
+ ,refractionPosition: vec3f
1803
+ ,refractionSize: vec3f
1804
+ #endif
1805
+ #ifdef SS_DISPERSION
1806
+ ,dispersion: f32
1807
+ #endif
1808
+ #endif
1809
+ #ifdef SS_TRANSLUCENCY
1810
+ ,vDiffusionDistance: vec3f
1811
+ ,vTranslucencyColor: vec4f
1812
+ #ifdef SS_TRANSLUCENCYCOLOR_TEXTURE
1813
+ ,translucencyColorMap: vec4f
1814
+ #endif
1815
+ #endif
1816
+ )->subSurfaceOutParams
1817
+ {var outParams: subSurfaceOutParams;outParams.specularEnvironmentReflectance=specularEnvironmentReflectance;
1818
+ #ifdef SS_REFRACTION
1819
+ var refractionIntensity: f32=vSubSurfaceIntensity.x;
1820
+ #ifdef SS_LINKREFRACTIONTOTRANSPARENCY
1821
+ refractionIntensity*=(1.0-alpha);outParams.alpha=1.0;
1822
+ #endif
1823
+ #endif
1824
+ #ifdef SS_TRANSLUCENCY
1825
+ var translucencyIntensity: f32=vSubSurfaceIntensity.y;
1826
+ #endif
1827
+ #ifdef SS_THICKNESSANDMASK_TEXTURE
1828
+ #ifdef SS_USE_GLTF_TEXTURES
1829
+ var thickness: f32=thicknessMap.g*vThicknessParam.y+vThicknessParam.x;
1830
+ #else
1831
+ var thickness: f32=thicknessMap.r*vThicknessParam.y+vThicknessParam.x;
1832
+ #endif
1833
+ #if DEBUGMODE>0
1834
+ outParams.thicknessMap=thicknessMap;
1835
+ #endif
1836
+ #if defined(SS_REFRACTION) && defined(SS_REFRACTION_USE_INTENSITY_FROM_THICKNESS)
1837
+ #ifdef SS_USE_GLTF_TEXTURES
1838
+ refractionIntensity*=thicknessMap.r;
1839
+ #else
1840
+ refractionIntensity*=thicknessMap.g;
1841
+ #endif
1842
+ #endif
1843
+ #if defined(SS_TRANSLUCENCY) && defined(SS_TRANSLUCENCY_USE_INTENSITY_FROM_THICKNESS)
1844
+ #ifdef SS_USE_GLTF_TEXTURES
1845
+ translucencyIntensity*=thicknessMap.a;
1846
+ #else
1847
+ translucencyIntensity*=thicknessMap.b;
1848
+ #endif
1849
+ #endif
1850
+ #else
1851
+ var thickness: f32=vThicknessParam.y;
1852
+ #endif
1853
+ #if defined(SS_REFRACTION) && defined(SS_REFRACTIONINTENSITY_TEXTURE)
1854
+ #ifdef SS_USE_GLTF_TEXTURES
1855
+ refractionIntensity*=refractionIntensityMap.r;
1856
+ #else
1857
+ refractionIntensity*=refractionIntensityMap.g;
1858
+ #endif
1859
+ #endif
1860
+ #if defined(SS_TRANSLUCENCY) && defined(SS_TRANSLUCENCYINTENSITY_TEXTURE)
1861
+ #ifdef SS_USE_GLTF_TEXTURES
1862
+ translucencyIntensity*=translucencyIntensityMap.a;
1863
+ #else
1864
+ translucencyIntensity*=translucencyIntensityMap.b;
1865
+ #endif
1866
+ #endif
1867
+ #ifdef SS_TRANSLUCENCY
1868
+ thickness=maxEps(thickness);var translucencyColor: vec4f=vTranslucencyColor;
1869
+ #ifdef SS_TRANSLUCENCYCOLOR_TEXTURE
1870
+ translucencyColor*=translucencyColorMap;
1871
+ #endif
1872
+ var transmittance: vec3f=transmittanceBRDF_Burley(translucencyColor.rgb,vDiffusionDistance,thickness);transmittance*=translucencyIntensity;outParams.transmittance=transmittance;outParams.translucencyIntensity=translucencyIntensity;
1873
+ #endif
1874
+ #ifdef SS_REFRACTION
1875
+ var environmentRefraction: vec4f= vec4f(0.,0.,0.,0.);
1876
+ #ifdef SS_HAS_THICKNESS
1877
+ var ior: f32=vRefractionInfos.y;
1878
+ #else
1879
+ var ior: f32=vRefractionMicrosurfaceInfos.w;
1880
+ #endif
1881
+ #ifdef SS_LODINREFRACTIONALPHA
1882
+ var refractionAlphaG: f32=alphaG;refractionAlphaG=mix(alphaG,0.0,clamp(ior*3.0-2.0,0.0,1.0));var refractionLOD: f32=getLodFromAlphaGNdotV(vRefractionMicrosurfaceInfos.x,refractionAlphaG,NdotVUnclamped);
1883
+ #elif defined(SS_LINEARSPECULARREFRACTION)
1884
+ var refractionRoughness: f32=alphaG;refractionRoughness=mix(alphaG,0.0,clamp(ior*3.0-2.0,0.0,1.0));var refractionLOD: f32=getLinearLodFromRoughness(vRefractionMicrosurfaceInfos.x,refractionRoughness);
1885
+ #else
1886
+ var refractionAlphaG: f32=alphaG;refractionAlphaG=mix(alphaG,0.0,clamp(ior*3.0-2.0,0.0,1.0));var refractionLOD: f32=getLodFromAlphaG(vRefractionMicrosurfaceInfos.x,refractionAlphaG);
1887
+ #endif
1888
+ var refraction_ior: f32=vRefractionInfos.y;
1889
+ #ifdef SS_DISPERSION
1890
+ var realIOR: f32=1.0/refraction_ior;var iorDispersionSpread: f32=0.04*dispersion*(realIOR-1.0);var iors: vec3f= vec3f(1.0/(realIOR-iorDispersionSpread),refraction_ior,1.0/(realIOR+iorDispersionSpread));for (var i: i32=0; i<3; i++) {refraction_ior=iors[i];
1891
+ #endif
1892
+ var envSample: vec4f=sampleEnvironmentRefraction(refraction_ior,thickness,refractionLOD,normalW,vPositionW,viewDirectionW,view,vRefractionInfos,refractionMatrix,vRefractionMicrosurfaceInfos,alphaG
1893
+ #ifdef SS_REFRACTIONMAP_3D
1894
+ ,refractionSampler
1895
+ ,refractionSamplerSampler
1896
+ #ifndef LODBASEDMICROSFURACE
1897
+ ,refractionLowSampler
1898
+ ,refractionLowSamplerSampler
1899
+ ,refractionHighSampler
1900
+ ,refractionHighSamplerSampler
1901
+ #endif
1902
+ #else
1903
+ ,refractionSampler
1904
+ ,refractionSamplerSampler
1905
+ #ifndef LODBASEDMICROSFURACE
1906
+ ,refractionLowSampler
1907
+ ,refractionLowSamplerSampler
1908
+ ,refractionHighSampler
1909
+ ,refractionHighSamplerSampler
1910
+ #endif
1911
+ #endif
1912
+ #ifdef ANISOTROPIC
1913
+ ,anisotropicOut
1914
+ #endif
1915
+ #ifdef REALTIME_FILTERING
1916
+ ,vRefractionFilteringInfo
1917
+ #endif
1918
+ #ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC
1919
+ ,refractionPosition
1920
+ ,refractionSize
1921
+ #endif
1922
+ );
1923
+ #ifdef SS_DISPERSION
1924
+ environmentRefraction[i]=envSample[i];}
1925
+ #else
1926
+ environmentRefraction=envSample;
1927
+ #endif
1928
+ environmentRefraction=vec4f(environmentRefraction.rgb*vRefractionInfos.x,environmentRefraction.a);
1929
+ #endif
1930
+ #ifdef SS_REFRACTION
1931
+ var refractionTransmittance: vec3f= vec3f(refractionIntensity);
1932
+ #ifdef SS_THICKNESSANDMASK_TEXTURE
1933
+ var volumeAlbedo: vec3f=computeColorAtDistanceInMedia(vTintColor.rgb,vTintColor.w);refractionTransmittance*=cocaLambertVec3(volumeAlbedo,thickness);
1934
+ #elif defined(SS_LINKREFRACTIONTOTRANSPARENCY)
1935
+ var maxChannel: f32=max(max(surfaceAlbedo.r,surfaceAlbedo.g),surfaceAlbedo.b);var volumeAlbedo: vec3f=saturateVec3(maxChannel*surfaceAlbedo);environmentRefraction=vec4f(environmentRefraction.rgb*volumeAlbedo,environmentRefraction.a);
1936
+ #else
1937
+ var volumeAlbedo: vec3f=computeColorAtDistanceInMedia(vTintColor.rgb,vTintColor.w);refractionTransmittance*=cocaLambertVec3(volumeAlbedo,vThicknessParam.y);
1938
+ #endif
1939
+ #ifdef SS_ALBEDOFORREFRACTIONTINT
1940
+ environmentRefraction=vec4f(environmentRefraction.rgb*surfaceAlbedo.rgb,environmentRefraction.a);
1941
+ #endif
1942
+ #ifdef LEGACY_SPECULAR_ENERGY_CONSERVATION
1943
+ outParams.surfaceAlbedo=surfaceAlbedo*(1.-refractionIntensity);outParams.refractionOpacity=1.0;
1944
+ #else
1945
+ outParams.surfaceAlbedo=surfaceAlbedo;outParams.refractionOpacity=(1.-refractionIntensity);
1946
+ #endif
1947
+ #ifdef UNUSED_MULTIPLEBOUNCES
1948
+ var bounceSpecularEnvironmentReflectance: vec3f=(2.0*specularEnvironmentReflectance)/(1.0+specularEnvironmentReflectance);outParams.specularEnvironmentReflectance=mix(bounceSpecularEnvironmentReflectance,specularEnvironmentReflectance,refractionIntensity);
1949
+ #endif
1950
+ #if DEBUGMODE>0
1951
+ outParams.refractionTransmittance=refractionTransmittance;
1952
+ #endif
1953
+ outParams.finalRefraction=environmentRefraction.rgb*refractionTransmittance*vLightingIntensity.z;outParams.finalRefraction*=vec3f(1.0)-specularEnvironmentReflectance;
1954
+ #if DEBUGMODE>0
1955
+ outParams.environmentRefraction=environmentRefraction;
1956
+ #endif
1957
+ #endif
1958
+ #if defined(REFLECTION) && defined(SS_TRANSLUCENCY)
1959
+ #if defined(NORMAL) && defined(USESPHERICALINVERTEX) || !defined(USESPHERICALFROMREFLECTIONMAP)
1960
+ var irradianceVector: vec3f= (reflectionMatrix* vec4f(normalW,0)).xyz;
1961
+ #ifdef REFLECTIONMAP_OPPOSITEZ
1962
+ irradianceVector.z*=-1.0;
1963
+ #endif
1964
+ #ifdef INVERTCUBICMAP
1965
+ irradianceVector.y*=-1.0;
1966
+ #endif
1967
+ #else
1968
+ var irradianceVector: vec3f=irradianceVector_;
1969
+ #endif
1970
+ #if defined(USESPHERICALFROMREFLECTIONMAP)
1971
+ #if defined(REALTIME_FILTERING)
1972
+ var refractionIrradiance: vec3f=irradiance(reflectionSampler,reflectionSamplerSampler,-irradianceVector,vReflectionFilteringInfo,0.0,surfaceAlbedo,irradianceVector
1973
+ #ifdef IBL_CDF_FILTERING
1974
+ ,icdfSampler
1975
+ ,icdfSamplerSampler
1976
+ #endif
1977
+ );
1978
+ #else
1979
+ var refractionIrradiance: vec3f=computeEnvironmentIrradiance(-irradianceVector);
1980
+ #endif
1981
+ #elif defined(USEIRRADIANCEMAP)
1982
+ #ifdef REFLECTIONMAP_3D
1983
+ var irradianceCoords: vec3f=irradianceVector;
1984
+ #else
1985
+ var irradianceCoords: vec2f=irradianceVector.xy;
1986
+ #ifdef REFLECTIONMAP_PROJECTION
1987
+ irradianceCoords/=irradianceVector.z;
1988
+ #endif
1989
+ irradianceCoords.y=1.0-irradianceCoords.y;
1990
+ #endif
1991
+ var temp: vec4f=textureSample(irradianceSampler,irradianceSamplerSampler,-irradianceCoords);var refractionIrradiance=temp.rgb;
1992
+ #ifdef RGBDREFLECTION
1993
+ refractionIrradiance=fromRGBD(temp).rgb;
1994
+ #endif
1995
+ #ifdef GAMMAREFLECTION
1996
+ refractionIrradiance=toLinearSpaceVec3(refractionIrradiance);
1997
+ #endif
1998
+ #else
1999
+ var refractionIrradiance: vec3f= vec3f(0.);
2000
+ #endif
2001
+ refractionIrradiance*=transmittance;
2002
+ #ifdef SS_ALBEDOFORTRANSLUCENCYTINT
2003
+ refractionIrradiance*=surfaceAlbedo.rgb;
2004
+ #endif
2005
+ outParams.refractionIrradiance=refractionIrradiance;
2006
+ #endif
2007
+ return outParams;}
2008
+ #endif
2009
+ `;
2010
+ e.IncludesShadersStoreWGSL[N] || (e.IncludesShadersStoreWGSL[N] = ae);
2011
+ const O = "pbrBlockNormalGeometric", ne = `var viewDirectionW: vec3f=normalize(scene.vEyePosition.xyz-input.vPositionW);
2012
+ #ifdef NORMAL
2013
+ var normalW: vec3f=normalize(input.vNormalW);
2014
+ #else
2015
+ var normalW: vec3f=normalize(cross(dpdx(input.vPositionW),dpdy(input.vPositionW)))*scene.vEyePosition.w;
2016
+ #endif
2017
+ var geometricNormalW: vec3f=normalW;
2018
+ #if defined(TWOSIDEDLIGHTING) && defined(NORMAL)
2019
+ geometricNormalW=select(-geometricNormalW,geometricNormalW,fragmentInputs.frontFacing);
2020
+ #endif
2021
+ `;
2022
+ e.IncludesShadersStoreWGSL[O] || (e.IncludesShadersStoreWGSL[O] = ne);
2023
+ const L = "pbrBlockNormalFinal", fe = `#if defined(FORCENORMALFORWARD) && defined(NORMAL)
2024
+ var faceNormal: vec3f=normalize(cross(dpdx(fragmentInputs.vPositionW),dpdy(fragmentInputs.vPositionW)))*scene.vEyePosition.w;
2025
+ #if defined(TWOSIDEDLIGHTING)
2026
+ faceNormal=select(-faceNormal,faceNormal,fragmentInputs.frontFacing);
2027
+ #endif
2028
+ normalW*=sign(dot(normalW,faceNormal));
2029
+ #endif
2030
+ #if defined(TWOSIDEDLIGHTING) && defined(NORMAL)
2031
+ #if defined(MIRRORED)
2032
+ normalW=select(normalW,-normalW,fragmentInputs.frontFacing);
2033
+ #else
2034
+ normalW=select(-normalW,normalW,fragmentInputs.frontFacing);
2035
+ #endif
2036
+ #endif
2037
+ `;
2038
+ e.IncludesShadersStoreWGSL[L] || (e.IncludesShadersStoreWGSL[L] = fe);
2039
+ const T = "pbrBlockLightmapInit", te = `#ifdef LIGHTMAP
2040
+ var lightmapColor: vec4f=textureSample(lightmapSampler,lightmapSamplerSampler,fragmentInputs.vLightmapUV+uvOffset);
2041
+ #ifdef RGBDLIGHTMAP
2042
+ lightmapColor=vec4f(fromRGBD(lightmapColor),lightmapColor.a);
2043
+ #endif
2044
+ #ifdef GAMMALIGHTMAP
2045
+ lightmapColor=vec4f(toLinearSpaceVec3(lightmapColor.rgb),lightmapColor.a);
2046
+ #endif
2047
+ lightmapColor=vec4f(lightmapColor.rgb*uniforms.vLightmapInfos.y,lightmapColor.a);
2048
+ #endif
2049
+ `;
2050
+ e.IncludesShadersStoreWGSL[T] || (e.IncludesShadersStoreWGSL[T] = te);
2051
+ const _ = "pbrBlockGeometryInfo", oe = `var NdotVUnclamped: f32=dot(normalW,viewDirectionW);var NdotV: f32=absEps(NdotVUnclamped);var alphaG: f32=convertRoughnessToAverageSlope(roughness);var AARoughnessFactors: vec2f=getAARoughnessFactors(normalW.xyz);
2052
+ #ifdef SPECULARAA
2053
+ alphaG+=AARoughnessFactors.y;
2054
+ #endif
2055
+ #if defined(ENVIRONMENTBRDF)
2056
+ var environmentBrdf: vec3f=getBRDFLookup(NdotV,roughness);
2057
+ #endif
2058
+ #if defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)
2059
+ #ifdef RADIANCEOCCLUSION
2060
+ #ifdef AMBIENTINGRAYSCALE
2061
+ var ambientMonochrome: f32=aoOut.ambientOcclusionColor.r;
2062
+ #else
2063
+ var ambientMonochrome: f32=getLuminance(aoOut.ambientOcclusionColor);
2064
+ #endif
2065
+ var seo: f32=environmentRadianceOcclusion(ambientMonochrome,NdotVUnclamped);
2066
+ #endif
2067
+ #ifdef HORIZONOCCLUSION
2068
+ #ifdef BUMP
2069
+ #ifdef REFLECTIONMAP_3D
2070
+ var eho: f32=environmentHorizonOcclusion(-viewDirectionW,normalW,geometricNormalW);
2071
+ #endif
2072
+ #endif
2073
+ #endif
2074
+ #endif
2075
+ `;
2076
+ e.IncludesShadersStoreWGSL[_] || (e.IncludesShadersStoreWGSL[_] = oe);
2077
+ const D = "pbrBlockReflectance0", ce = `var reflectanceF0: f32=reflectivityOut.reflectanceF0;var specularEnvironmentR0: vec3f=reflectivityOut.colorReflectanceF0;var specularEnvironmentR90: vec3f= reflectivityOut.reflectanceF90;
2078
+ #ifdef ALPHAFRESNEL
2079
+ var reflectance90: f32=fresnelGrazingReflectance(reflectanceF0);specularEnvironmentR90=specularEnvironmentR90*reflectance90;
2080
+ #endif
2081
+ `;
2082
+ e.IncludesShadersStoreWGSL[D] || (e.IncludesShadersStoreWGSL[D] = ce);
2083
+ const g = "pbrBlockReflectance", le = `#if defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)
2084
+ var baseSpecularEnvironmentReflectance: vec3f=getReflectanceFromBRDFWithEnvLookup(vec3f(reflectanceF0),vec3f(reflectivityOut.reflectanceF90),environmentBrdf);
2085
+ #if (CONDUCTOR_SPECULAR_MODEL==CONDUCTOR_SPECULAR_MODEL_OPENPBR)
2086
+ let metalEnvironmentReflectance: vec3f=vec3f(reflectivityOut.specularWeight)*getF82Specular(NdotV,clearcoatOut.specularEnvironmentR0,reflectivityOut.colorReflectanceF90,reflectivityOut.roughness);let dielectricEnvironmentReflectance=getReflectanceFromBRDFWithEnvLookup(reflectivityOut.dielectricColorF0,reflectivityOut.colorReflectanceF90,environmentBrdf);var colorSpecularEnvironmentReflectance: vec3f=mix(dielectricEnvironmentReflectance,metalEnvironmentReflectance,reflectivityOut.metallic);
2087
+ #else
2088
+ var colorSpecularEnvironmentReflectance=getReflectanceFromBRDFWithEnvLookup(clearcoatOut.specularEnvironmentR0,reflectivityOut.colorReflectanceF90,environmentBrdf);
2089
+ #endif
2090
+ #ifdef RADIANCEOCCLUSION
2091
+ colorSpecularEnvironmentReflectance*=seo;
2092
+ #endif
2093
+ #ifdef HORIZONOCCLUSION
2094
+ #ifdef BUMP
2095
+ #ifdef REFLECTIONMAP_3D
2096
+ colorSpecularEnvironmentReflectance*=eho;
2097
+ #endif
2098
+ #endif
2099
+ #endif
2100
+ #else
2101
+ var colorSpecularEnvironmentReflectance: vec3f=getReflectanceFromAnalyticalBRDFLookup_Jones(NdotV,clearcoatOut.specularEnvironmentR0,specularEnvironmentR90,sqrt(microSurface));var baseSpecularEnvironmentReflectance: vec3f=getReflectanceFromAnalyticalBRDFLookup_Jones(NdotV,vec3f(reflectanceF0),vec3f(reflectivityOut.reflectanceF90),sqrt(microSurface));
2102
+ #endif
2103
+ #ifdef CLEARCOAT
2104
+ colorSpecularEnvironmentReflectance*=clearcoatOut.conservationFactor;
2105
+ #if defined(CLEARCOAT_TINT)
2106
+ colorSpecularEnvironmentReflectance*=clearcoatOut.absorption;
2107
+ #endif
2108
+ #endif
2109
+ `;
2110
+ e.IncludesShadersStoreWGSL[g] || (e.IncludesShadersStoreWGSL[g] = le);
2111
+ const M = "pbrBlockDirectLighting", de = `var diffuseBase: vec3f=vec3f(0.,0.,0.);
2112
+ #ifdef SS_TRANSLUCENCY
2113
+ var diffuseTransmissionBase: vec3f=vec3f(0.,0.,0.);
2114
+ #endif
2115
+ #ifdef SPECULARTERM
2116
+ var specularBase: vec3f=vec3f(0.,0.,0.);
2117
+ #endif
2118
+ #ifdef CLEARCOAT
2119
+ var clearCoatBase: vec3f=vec3f(0.,0.,0.);
2120
+ #endif
2121
+ #ifdef SHEEN
2122
+ var sheenBase: vec3f=vec3f(0.,0.,0.);
2123
+ #endif
2124
+ #if defined(SPECULARTERM) && defined(LIGHT0)
2125
+ var coloredFresnel: vec3f=vec3f(0.,0.,0.);
2126
+ #endif
2127
+ var preInfo: preLightingInfo;var info: lightingInfo;var shadow: f32=1.;
2128
+ var aggShadow: f32=0.;var numLights: f32=0.;
2129
+ #if defined(CLEARCOAT) && defined(CLEARCOAT_TINT)
2130
+ var absorption: vec3f=vec3f(0.);
2131
+ #endif
2132
+ `;
2133
+ e.IncludesShadersStoreWGSL[M] || (e.IncludesShadersStoreWGSL[M] = de);
2134
+ const h = "pbrBlockFinalLitComponents", se = `aggShadow=aggShadow/numLights;
2135
+ #if defined(ENVIRONMENTBRDF)
2136
+ #ifdef MS_BRDF_ENERGY_CONSERVATION
2137
+ var baseSpecularEnergyConservationFactor: vec3f=getEnergyConservationFactor(vec3f(reflectanceF0),environmentBrdf);var coloredEnergyConservationFactor: vec3f=getEnergyConservationFactor(clearcoatOut.specularEnvironmentR0,environmentBrdf);
2138
+ #endif
2139
+ #endif
2140
+ #if defined(SHEEN) && defined(SHEEN_ALBEDOSCALING) && defined(ENVIRONMENTBRDF)
2141
+ surfaceAlbedo=sheenOut.sheenAlbedoScaling*surfaceAlbedo.rgb;
2142
+ #endif
2143
+ #ifdef LEGACY_SPECULAR_ENERGY_CONSERVATION
2144
+ #ifndef METALLICWORKFLOW
2145
+ #ifdef SPECULAR_GLOSSINESS_ENERGY_CONSERVATION
2146
+ surfaceAlbedo=vec3f(1.-reflectanceF0)*surfaceAlbedo.rgb;
2147
+ #endif
2148
+ #endif
2149
+ #endif
2150
+ #ifdef REFLECTION
2151
+ var finalIrradiance: vec3f=reflectionOut.environmentIrradiance;
2152
+ #ifndef LEGACY_SPECULAR_ENERGY_CONSERVATION
2153
+ #if defined(METALLICWORKFLOW) || defined(SPECULAR_GLOSSINESS_ENERGY_CONSERVATION)
2154
+ var baseSpecularEnergy: vec3f=vec3f(baseSpecularEnvironmentReflectance);
2155
+ #if defined(ENVIRONMENTBRDF)
2156
+ #ifdef MS_BRDF_ENERGY_CONSERVATION
2157
+ baseSpecularEnergy*=baseSpecularEnergyConservationFactor;
2158
+ #endif
2159
+ #endif
2160
+ finalIrradiance*=clamp(vec3f(1.0)-baseSpecularEnergy,vec3f(0.0),vec3f(1.0));
2161
+ #endif
2162
+ #endif
2163
+ #if defined(CLEARCOAT)
2164
+ finalIrradiance*=clearcoatOut.conservationFactor;
2165
+ #if defined(CLEARCOAT_TINT)
2166
+ finalIrradiance*=clearcoatOut.absorption;
2167
+ #endif
2168
+ #endif
2169
+ #ifndef SS_APPLY_ALBEDO_AFTER_SUBSURFACE
2170
+ finalIrradiance*=surfaceAlbedo.rgb;
2171
+ #endif
2172
+ #if defined(SS_REFRACTION)
2173
+ finalIrradiance*=subSurfaceOut.refractionOpacity;
2174
+ #endif
2175
+ #if defined(SS_TRANSLUCENCY)
2176
+ finalIrradiance*=(1.0-subSurfaceOut.translucencyIntensity);finalIrradiance+=subSurfaceOut.refractionIrradiance;
2177
+ #endif
2178
+ #ifdef SS_APPLY_ALBEDO_AFTER_SUBSURFACE
2179
+ finalIrradiance*=surfaceAlbedo.rgb;
2180
+ #endif
2181
+ finalIrradiance*=uniforms.vLightingIntensity.z;finalIrradiance*=aoOut.ambientOcclusionColor;
2182
+ #endif
2183
+ #ifdef SPECULARTERM
2184
+ var finalSpecular: vec3f=specularBase;finalSpecular=max(finalSpecular,vec3f(0.0));var finalSpecularScaled: vec3f=finalSpecular*uniforms.vLightingIntensity.x*uniforms.vLightingIntensity.w;
2185
+ #if defined(ENVIRONMENTBRDF) && defined(MS_BRDF_ENERGY_CONSERVATION)
2186
+ finalSpecularScaled*=coloredEnergyConservationFactor;
2187
+ #endif
2188
+ #if defined(SHEEN) && defined(ENVIRONMENTBRDF) && defined(SHEEN_ALBEDOSCALING)
2189
+ finalSpecularScaled*=sheenOut.sheenAlbedoScaling;
2190
+ #endif
2191
+ #endif
2192
+ #ifdef REFLECTION
2193
+ var finalRadiance: vec3f=reflectionOut.environmentRadiance.rgb;finalRadiance*=colorSpecularEnvironmentReflectance;;var finalRadianceScaled: vec3f=finalRadiance*uniforms.vLightingIntensity.z;
2194
+ #if defined(ENVIRONMENTBRDF) && defined(MS_BRDF_ENERGY_CONSERVATION)
2195
+ finalRadianceScaled*=coloredEnergyConservationFactor;
2196
+ #endif
2197
+ #if defined(SHEEN) && defined(ENVIRONMENTBRDF) && defined(SHEEN_ALBEDOSCALING)
2198
+ finalRadianceScaled*=sheenOut.sheenAlbedoScaling;
2199
+ #endif
2200
+ #endif
2201
+ #ifdef SHEEN
2202
+ var finalSheen: vec3f=sheenBase*sheenOut.sheenColor;finalSheen=max(finalSheen,vec3f(0.0));var finalSheenScaled: vec3f=finalSheen*uniforms.vLightingIntensity.x*uniforms.vLightingIntensity.w;
2203
+ #if defined(CLEARCOAT) && defined(REFLECTION) && defined(ENVIRONMENTBRDF)
2204
+ sheenOut.finalSheenRadianceScaled*=clearcoatOut.conservationFactor;
2205
+ #if defined(CLEARCOAT_TINT)
2206
+ sheenOut.finalSheenRadianceScaled*=clearcoatOut.absorption;
2207
+ #endif
2208
+ #endif
2209
+ #endif
2210
+ #ifdef CLEARCOAT
2211
+ var finalClearCoat: vec3f=clearCoatBase;finalClearCoat=max(finalClearCoat,vec3f(0.0));var finalClearCoatScaled: vec3f=finalClearCoat*uniforms.vLightingIntensity.x*uniforms.vLightingIntensity.w;
2212
+ #if defined(ENVIRONMENTBRDF) && defined(MS_BRDF_ENERGY_CONSERVATION)
2213
+ finalClearCoatScaled*=clearcoatOut.energyConservationFactorClearCoat;
2214
+ #endif
2215
+ #ifdef SS_REFRACTION
2216
+ subSurfaceOut.finalRefraction*=clearcoatOut.conservationFactor;
2217
+ #ifdef CLEARCOAT_TINT
2218
+ subSurfaceOut.finalRefraction*=clearcoatOut.absorption;
2219
+ #endif
2220
+ #endif
2221
+ #endif
2222
+ #ifdef ALPHABLEND
2223
+ var luminanceOverAlpha: f32=0.0;
2224
+ #if defined(REFLECTION) && defined(RADIANCEOVERALPHA)
2225
+ luminanceOverAlpha+=getLuminance(finalRadianceScaled);
2226
+ #if defined(CLEARCOAT)
2227
+ luminanceOverAlpha+=getLuminance(clearcoatOut.finalClearCoatRadianceScaled);
2228
+ #endif
2229
+ #endif
2230
+ #if defined(SPECULARTERM) && defined(SPECULAROVERALPHA)
2231
+ luminanceOverAlpha+=getLuminance(finalSpecularScaled);
2232
+ #endif
2233
+ #if defined(CLEARCOAT) && defined(CLEARCOATOVERALPHA)
2234
+ luminanceOverAlpha+=getLuminance(finalClearCoatScaled);
2235
+ #endif
2236
+ #if defined(RADIANCEOVERALPHA) || defined(SPECULAROVERALPHA) || defined(CLEARCOATOVERALPHA)
2237
+ alpha=saturate(alpha+luminanceOverAlpha*luminanceOverAlpha);
2238
+ #endif
2239
+ #endif
2240
+ `;
2241
+ e.IncludesShadersStoreWGSL[h] || (e.IncludesShadersStoreWGSL[h] = se);
2242
+ const F = "pbrBlockFinalUnlitComponents", Ee = `var finalDiffuse: vec3f=diffuseBase;finalDiffuse*=surfaceAlbedo;
2243
+ #if defined(SS_REFRACTION) && !defined(UNLIT)
2244
+ finalDiffuse*=subSurfaceOut.refractionOpacity;
2245
+ #endif
2246
+ #if defined(SS_TRANSLUCENCY) && !defined(UNLIT)
2247
+ finalDiffuse+=diffuseTransmissionBase;
2248
+ #endif
2249
+ finalDiffuse=max(finalDiffuse,vec3f(0.0));finalDiffuse*=uniforms.vLightingIntensity.x;var finalAmbient: vec3f=uniforms.vAmbientColor;finalAmbient*=surfaceAlbedo.rgb;var finalEmissive: vec3f=uniforms.vEmissiveColor;
2250
+ #ifdef EMISSIVE
2251
+ var emissiveColorTex: vec3f=textureSample(emissiveSampler,emissiveSamplerSampler,fragmentInputs.vEmissiveUV+uvOffset).rgb;
2252
+ #ifdef GAMMAEMISSIVE
2253
+ finalEmissive*=toLinearSpaceVec3(emissiveColorTex.rgb);
2254
+ #else
2255
+ finalEmissive*=emissiveColorTex.rgb;
2256
+ #endif
2257
+ finalEmissive*= uniforms.vEmissiveInfos.y;
2258
+ #endif
2259
+ finalEmissive*=uniforms.vLightingIntensity.y;
2260
+ #ifdef AMBIENT
2261
+ var ambientOcclusionForDirectDiffuse: vec3f=mix( vec3f(1.),aoOut.ambientOcclusionColor,uniforms.vAmbientInfos.w);
2262
+ #else
2263
+ var ambientOcclusionForDirectDiffuse: vec3f=aoOut.ambientOcclusionColor;
2264
+ #endif
2265
+ finalAmbient*=aoOut.ambientOcclusionColor;finalDiffuse*=ambientOcclusionForDirectDiffuse;
2266
+ `;
2267
+ e.IncludesShadersStoreWGSL[F] || (e.IncludesShadersStoreWGSL[F] = Ee);
2268
+ const P = "pbrBlockFinalColorComposition", Se = `var finalColor: vec4f= vec4f(
2269
+ #ifndef UNLIT
2270
+ #ifdef REFLECTION
2271
+ finalIrradiance +
2272
+ #endif
2273
+ #ifdef SPECULARTERM
2274
+ finalSpecularScaled +
2275
+ #endif
2276
+ #ifdef SHEEN
2277
+ finalSheenScaled +
2278
+ #endif
2279
+ #ifdef CLEARCOAT
2280
+ finalClearCoatScaled +
2281
+ #endif
2282
+ #ifdef REFLECTION
2283
+ finalRadianceScaled +
2284
+ #if defined(SHEEN) && defined(ENVIRONMENTBRDF)
2285
+ sheenOut.finalSheenRadianceScaled +
2286
+ #endif
2287
+ #ifdef CLEARCOAT
2288
+ clearcoatOut.finalClearCoatRadianceScaled +
2289
+ #endif
2290
+ #endif
2291
+ #ifdef SS_REFRACTION
2292
+ subSurfaceOut.finalRefraction +
2293
+ #endif
2294
+ #endif
2295
+ finalAmbient +
2296
+ finalDiffuse,
2297
+ alpha);
2298
+ #ifdef LIGHTMAP
2299
+ #ifndef LIGHTMAPEXCLUDED
2300
+ #ifdef USELIGHTMAPASSHADOWMAP
2301
+ finalColor=vec4f(finalColor.rgb*lightmapColor.rgb,finalColor.a);
2302
+ #else
2303
+ finalColor=vec4f(finalColor.rgb+lightmapColor.rgb,finalColor.a);
2304
+ #endif
2305
+ #endif
2306
+ #endif
2307
+ finalColor=vec4f(finalColor.rgb+finalEmissive,finalColor.a);
2308
+ #define CUSTOM_FRAGMENT_BEFORE_FOG
2309
+ finalColor=max(finalColor,vec4f(0.0));
2310
+ `;
2311
+ e.IncludesShadersStoreWGSL[P] || (e.IncludesShadersStoreWGSL[P] = Se);
2312
+ const U = "pbrBlockImageProcessing", me = `#if defined(IMAGEPROCESSINGPOSTPROCESS) || defined(SS_SCATTERING)
2313
+ #if !defined(SKIPFINALCOLORCLAMP)
2314
+ finalColor=vec4f(clamp(finalColor.rgb,vec3f(0.),vec3f(30.0)),finalColor.a);
2315
+ #endif
2316
+ #else
2317
+ finalColor=applyImageProcessing(finalColor);
2318
+ #endif
2319
+ finalColor=vec4f(finalColor.rgb,finalColor.a*mesh.visibility);
2320
+ #ifdef PREMULTIPLYALPHA
2321
+ finalColor=vec4f(finalColor.rgb*finalColor.a,finalColor.a);;
2322
+ #endif
2323
+ `;
2324
+ e.IncludesShadersStoreWGSL[U] || (e.IncludesShadersStoreWGSL[U] = me);
2325
+ const b = "pbrBlockPrePass", ue = `var writeGeometryInfo: f32=select(0.0,1.0,finalColor.a>ALPHATESTVALUE);var fragData: array<vec4<f32>,SCENE_MRT_COUNT>;
2326
+ #ifdef PREPASS_POSITION
2327
+ fragData[PREPASS_POSITION_INDEX]= vec4f(fragmentInputs.vPositionW,writeGeometryInfo);
2328
+ #endif
2329
+ #ifdef PREPASS_LOCAL_POSITION
2330
+ fragData[PREPASS_LOCAL_POSITION_INDEX]=vec4f(fragmentInputs.vPosition,writeGeometryInfo);
2331
+ #endif
2332
+ #ifdef PREPASS_VELOCITY
2333
+ var a: vec2f=(fragmentInputs.vCurrentPosition.xy/fragmentInputs.vCurrentPosition.w)*0.5+0.5;var b: vec2f=(fragmentInputs.vPreviousPosition.xy/fragmentInputs.vPreviousPosition.w)*0.5+0.5;var velocity: vec2f=abs(a-b);velocity= vec2f(pow(velocity.x,1.0/3.0),pow(velocity.y,1.0/3.0))*sign(a-b)*0.5+0.5;fragData[PREPASS_VELOCITY_INDEX]= vec4f(velocity,0.0,writeGeometryInfo);
2334
+ #elif defined(PREPASS_VELOCITY_LINEAR)
2335
+ var velocity : vec2f=vec2f(0.5)*((fragmentInputs.vPreviousPosition.xy/fragmentInputs.vPreviousPosition.w) -
2336
+ (fragmentInputs.vCurrentPosition.xy/fragmentInputs.vCurrentPosition.w));fragData[PREPASS_VELOCITY_LINEAR_INDEX]=vec4f(velocity,0.0,writeGeometryInfo);
2337
+ #endif
2338
+ #ifdef PREPASS_ALBEDO
2339
+ fragData[PREPASS_ALBEDO_INDEX]=vec4f(surfaceAlbedo,writeGeometryInfo);
2340
+ #endif
2341
+ #ifdef PREPASS_ALBEDO_SQRT
2342
+ var sqAlbedo : vec3f=sqrt(surfaceAlbedo);
2343
+ #endif
2344
+ #ifdef PREPASS_IRRADIANCE
2345
+ var irradiance : vec3f=finalDiffuse;
2346
+ #ifndef UNLIT
2347
+ #ifdef REFLECTION
2348
+ irradiance+=finalIrradiance;
2349
+ #endif
2350
+ #endif
2351
+ #ifdef SS_SCATTERING
2352
+ #ifdef PREPASS_COLOR
2353
+ fragData[PREPASS_COLOR_INDEX]=vec4f(finalColor.rgb-irradiance,finalColor.a);
2354
+ #endif
2355
+ irradiance/=sqAlbedo;fragData[PREPASS_IRRADIANCE_INDEX]=vec4f(clamp(irradiance,vec3f(0.),vec3f(1.)),writeGeometryInfo*uniforms.scatteringDiffusionProfile/255.);
2356
+ #else
2357
+ #ifdef PREPASS_COLOR
2358
+ fragData[PREPASS_COLOR_INDEX]=finalColor;
2359
+ #endif
2360
+ fragData[PREPASS_IRRADIANCE_INDEX]=vec4f(clamp(irradiance,vec3f(0.),vec3f(1.)),writeGeometryInfo);
2361
+ #endif
2362
+ #elif defined(PREPASS_COLOR)
2363
+ fragData[PREPASS_COLOR_INDEX]=vec4f(finalColor.rgb,finalColor.a);
2364
+ #endif
2365
+ #ifdef PREPASS_DEPTH
2366
+ fragData[PREPASS_DEPTH_INDEX]=vec4f(fragmentInputs.vViewPos.z,0.0,0.0,writeGeometryInfo);
2367
+ #endif
2368
+ #ifdef PREPASS_SCREENSPACE_DEPTH
2369
+ fragData[PREPASS_SCREENSPACE_DEPTH_INDEX]=vec4f(fragmentInputs.position.z,0.0,0.0,writeGeometryInfo);
2370
+ #endif
2371
+ #ifdef PREPASS_NORMALIZED_VIEW_DEPTH
2372
+ fragData[PREPASS_NORMALIZED_VIEW_DEPTH_INDEX]=vec4f(fragmentInputs.vNormViewDepth,0.0,0.0,writeGeometryInfo);
2373
+ #endif
2374
+ #ifdef PREPASS_NORMAL
2375
+ #ifdef PREPASS_NORMAL_WORLDSPACE
2376
+ fragData[PREPASS_NORMAL_INDEX]=vec4f(normalW,writeGeometryInfo);
2377
+ #else
2378
+ fragData[PREPASS_NORMAL_INDEX]=vec4f(normalize((scene.view*vec4f(normalW,0.0)).rgb),writeGeometryInfo);
2379
+ #endif
2380
+ #endif
2381
+ #ifdef PREPASS_WORLD_NORMAL
2382
+ fragData[PREPASS_WORLD_NORMAL_INDEX]=vec4f(normalW*0.5+0.5,writeGeometryInfo);
2383
+ #endif
2384
+ #ifdef PREPASS_ALBEDO_SQRT
2385
+ fragData[PREPASS_ALBEDO_SQRT_INDEX]=vec4f(sqAlbedo,writeGeometryInfo);
2386
+ #endif
2387
+ #ifdef PREPASS_REFLECTIVITY
2388
+ #ifndef UNLIT
2389
+ fragData[PREPASS_REFLECTIVITY_INDEX]=vec4f(specularEnvironmentR0,microSurface)*writeGeometryInfo;
2390
+ #else
2391
+ fragData[PREPASS_REFLECTIVITY_INDEX]=vec4f(0.0,0.0,0.0,1.0)*writeGeometryInfo;
2392
+ #endif
2393
+ #endif
2394
+ #if SCENE_MRT_COUNT>0
2395
+ fragmentOutputs.fragData0=fragData[0];
2396
+ #endif
2397
+ #if SCENE_MRT_COUNT>1
2398
+ fragmentOutputs.fragData1=fragData[1];
2399
+ #endif
2400
+ #if SCENE_MRT_COUNT>2
2401
+ fragmentOutputs.fragData2=fragData[2];
2402
+ #endif
2403
+ #if SCENE_MRT_COUNT>3
2404
+ fragmentOutputs.fragData3=fragData[3];
2405
+ #endif
2406
+ #if SCENE_MRT_COUNT>4
2407
+ fragmentOutputs.fragData4=fragData[4];
2408
+ #endif
2409
+ #if SCENE_MRT_COUNT>5
2410
+ fragmentOutputs.fragData5=fragData[5];
2411
+ #endif
2412
+ #if SCENE_MRT_COUNT>6
2413
+ fragmentOutputs.fragData6=fragData[6];
2414
+ #endif
2415
+ #if SCENE_MRT_COUNT>7
2416
+ fragmentOutputs.fragData7=fragData[7];
2417
+ #endif
2418
+ `;
2419
+ e.IncludesShadersStoreWGSL[b] || (e.IncludesShadersStoreWGSL[b] = ue);
2420
+ const B = "pbrDebug", Re = `#if DEBUGMODE>0
2421
+ if (input.vClipSpacePosition.x/input.vClipSpacePosition.w>=uniforms.vDebugMode.x) {var color: vec3f;
2422
+ #if DEBUGMODE==1
2423
+ color=fragmentInputs.vPositionW.rgb;
2424
+ #define DEBUGMODE_NORMALIZE
2425
+ #elif DEBUGMODE==2 && defined(NORMAL)
2426
+ color=fragmentInputs.vNormalW.rgb;
2427
+ #define DEBUGMODE_NORMALIZE
2428
+ #elif DEBUGMODE==3 && defined(BUMP) || DEBUGMODE==3 && defined(PARALLAX) || DEBUGMODE==3 && defined(ANISOTROPIC)
2429
+ color=TBN[0];
2430
+ #define DEBUGMODE_NORMALIZE
2431
+ #elif DEBUGMODE==4 && defined(BUMP) || DEBUGMODE==4 && defined(PARALLAX) || DEBUGMODE==4 && defined(ANISOTROPIC)
2432
+ color=TBN[1];
2433
+ #define DEBUGMODE_NORMALIZE
2434
+ #elif DEBUGMODE==5
2435
+ color=normalW;
2436
+ #define DEBUGMODE_NORMALIZE
2437
+ #elif DEBUGMODE==6 && defined(MAINUV1)
2438
+ color= vec3f(input.vMainUV1,0.0);
2439
+ #elif DEBUGMODE==7 && defined(MAINUV2)
2440
+ color= vec3f(input.vMainUV2,0.0);
2441
+ #elif DEBUGMODE==8 && defined(CLEARCOAT) && defined(CLEARCOAT_BUMP)
2442
+ color=clearcoatOut.TBNClearCoat[0];
2443
+ #define DEBUGMODE_NORMALIZE
2444
+ #elif DEBUGMODE==9 && defined(CLEARCOAT) && defined(CLEARCOAT_BUMP)
2445
+ color=clearcoatOut.TBNClearCoat[1];
2446
+ #define DEBUGMODE_NORMALIZE
2447
+ #elif DEBUGMODE==10 && defined(CLEARCOAT)
2448
+ color=clearcoatOut.clearCoatNormalW;
2449
+ #define DEBUGMODE_NORMALIZE
2450
+ #elif DEBUGMODE==11 && defined(ANISOTROPIC)
2451
+ color=anisotropicOut.anisotropicNormal;
2452
+ #define DEBUGMODE_NORMALIZE
2453
+ #elif DEBUGMODE==12 && defined(ANISOTROPIC)
2454
+ color=anisotropicOut.anisotropicTangent;
2455
+ #define DEBUGMODE_NORMALIZE
2456
+ #elif DEBUGMODE==13 && defined(ANISOTROPIC)
2457
+ color=anisotropicOut.anisotropicBitangent;
2458
+ #define DEBUGMODE_NORMALIZE
2459
+ #elif DEBUGMODE==20 && defined(ALBEDO)
2460
+ color=albedoTexture.rgb;
2461
+ #ifndef GAMMAALBEDO
2462
+ #define DEBUGMODE_GAMMA
2463
+ #endif
2464
+ #elif DEBUGMODE==21 && defined(AMBIENT)
2465
+ color=aoOut.ambientOcclusionColorMap.rgb;
2466
+ #elif DEBUGMODE==22 && defined(OPACITY)
2467
+ color=opacityMap.rgb;
2468
+ #elif DEBUGMODE==23 && defined(EMISSIVE)
2469
+ color=emissiveColorTex.rgb;
2470
+ #ifndef GAMMAEMISSIVE
2471
+ #define DEBUGMODE_GAMMA
2472
+ #endif
2473
+ #elif DEBUGMODE==24 && defined(LIGHTMAP)
2474
+ color=lightmapColor;
2475
+ #ifndef GAMMALIGHTMAP
2476
+ #define DEBUGMODE_GAMMA
2477
+ #endif
2478
+ #elif DEBUGMODE==25 && defined(REFLECTIVITY) && defined(METALLICWORKFLOW)
2479
+ color=reflectivityOut.surfaceMetallicColorMap.rgb;
2480
+ #elif DEBUGMODE==26 && defined(REFLECTIVITY) && !defined(METALLICWORKFLOW)
2481
+ color=reflectivityOut.surfaceReflectivityColorMap.rgb;
2482
+ #define DEBUGMODE_GAMMA
2483
+ #elif DEBUGMODE==27 && defined(CLEARCOAT) && defined(CLEARCOAT_TEXTURE)
2484
+ color= vec3f(clearcoatOut.clearCoatMapData.rg,0.0);
2485
+ #elif DEBUGMODE==28 && defined(CLEARCOAT) && defined(CLEARCOAT_TINT) && defined(CLEARCOAT_TINT_TEXTURE)
2486
+ color=clearcoatOut.clearCoatTintMapData.rgb;
2487
+ #elif DEBUGMODE==29 && defined(SHEEN) && defined(SHEEN_TEXTURE)
2488
+ color=sheenOut.sheenMapData.rgb;
2489
+ #elif DEBUGMODE==30 && defined(ANISOTROPIC) && defined(ANISOTROPIC_TEXTURE)
2490
+ color=anisotropicOut.anisotropyMapData.rgb;
2491
+ #elif DEBUGMODE==31 && defined(SUBSURFACE) && defined(SS_THICKNESSANDMASK_TEXTURE)
2492
+ color=subSurfaceOut.thicknessMap.rgb;
2493
+ #elif DEBUGMODE==32 && defined(BUMP)
2494
+ color=textureSample(bumpSampler,bumpSamplerSampler,fragmentInputs.vBumpUV).rgb;
2495
+ #elif DEBUGMODE==40 && defined(SS_REFRACTION)
2496
+ color=subSurfaceOut.environmentRefraction.rgb;
2497
+ #define DEBUGMODE_GAMMA
2498
+ #elif DEBUGMODE==41 && defined(REFLECTION)
2499
+ color=reflectionOut.environmentRadiance.rgb;
2500
+ #ifndef GAMMAREFLECTION
2501
+ #define DEBUGMODE_GAMMA
2502
+ #endif
2503
+ #elif DEBUGMODE==42 && defined(CLEARCOAT) && defined(REFLECTION)
2504
+ color=clearcoatOut.environmentClearCoatRadiance.rgb;
2505
+ #define DEBUGMODE_GAMMA
2506
+ #elif DEBUGMODE==50
2507
+ color=diffuseBase.rgb;
2508
+ #define DEBUGMODE_GAMMA
2509
+ #elif DEBUGMODE==51 && defined(SPECULARTERM)
2510
+ color=specularBase.rgb;
2511
+ #define DEBUGMODE_GAMMA
2512
+ #elif DEBUGMODE==52 && defined(CLEARCOAT)
2513
+ color=clearCoatBase.rgb;
2514
+ #define DEBUGMODE_GAMMA
2515
+ #elif DEBUGMODE==53 && defined(SHEEN)
2516
+ color=sheenBase.rgb;
2517
+ #define DEBUGMODE_GAMMA
2518
+ #elif DEBUGMODE==54 && defined(REFLECTION)
2519
+ color=reflectionOut.environmentIrradiance.rgb;
2520
+ #ifndef GAMMAREFLECTION
2521
+ #define DEBUGMODE_GAMMA
2522
+ #endif
2523
+ #elif DEBUGMODE==60
2524
+ color=surfaceAlbedo.rgb;
2525
+ #define DEBUGMODE_GAMMA
2526
+ #elif DEBUGMODE==61
2527
+ color=clearcoatOut.specularEnvironmentR0;
2528
+ #define DEBUGMODE_GAMMA
2529
+ #elif DEBUGMODE==62 && defined(METALLICWORKFLOW)
2530
+ color= vec3f(reflectivityOut.metallic);
2531
+ #elif DEBUGMODE==71 && defined(METALLICWORKFLOW)
2532
+ color=reflectivityOut.metallicF0;
2533
+ #elif DEBUGMODE==63
2534
+ color= vec3f(roughness);
2535
+ #elif DEBUGMODE==64
2536
+ color= vec3f(alphaG);
2537
+ #elif DEBUGMODE==65
2538
+ color= vec3f(NdotV);
2539
+ #elif DEBUGMODE==66 && defined(CLEARCOAT) && defined(CLEARCOAT_TINT)
2540
+ color=clearcoatOut.clearCoatColor;
2541
+ #define DEBUGMODE_GAMMA
2542
+ #elif DEBUGMODE==67 && defined(CLEARCOAT)
2543
+ color= vec3f(clearcoatOut.clearCoatRoughness);
2544
+ #elif DEBUGMODE==68 && defined(CLEARCOAT)
2545
+ color= vec3f(clearcoatOut.clearCoatNdotV);
2546
+ #elif DEBUGMODE==69 && defined(SUBSURFACE) && defined(SS_TRANSLUCENCY)
2547
+ color=subSurfaceOut.transmittance;
2548
+ #elif DEBUGMODE==70 && defined(SUBSURFACE) && defined(SS_REFRACTION)
2549
+ color=subSurfaceOut.refractionTransmittance;
2550
+ #elif DEBUGMODE==72
2551
+ color= vec3f(microSurface);
2552
+ #elif DEBUGMODE==73
2553
+ color=uniforms.vAlbedoColor.rgb;
2554
+ #define DEBUGMODE_GAMMA
2555
+ #elif DEBUGMODE==74 && !defined(METALLICWORKFLOW)
2556
+ color=uniforms.vReflectivityColor.rgb;
2557
+ #define DEBUGMODE_GAMMA
2558
+ #elif DEBUGMODE==75
2559
+ color=uniforms.vEmissiveColor;
2560
+ #define DEBUGMODE_GAMMA
2561
+ #elif DEBUGMODE==80 && defined(RADIANCEOCCLUSION)
2562
+ color= vec3f(seo);
2563
+ #elif DEBUGMODE==81 && defined(HORIZONOCCLUSION) && defined(BUMP) && defined(REFLECTIONMAP_3D)
2564
+ color= vec3f(eho);
2565
+ #elif DEBUGMODE==82 && defined(MS_BRDF_ENERGY_CONSERVATION)
2566
+ color= vec3f(energyConservationFactor);
2567
+ #elif DEBUGMODE==83 && defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)
2568
+ color=baseSpecularEnvironmentReflectance;
2569
+ #define DEBUGMODE_GAMMA
2570
+ #elif DEBUGMODE==84 && defined(CLEARCOAT) && defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)
2571
+ color=clearcoatOut.clearCoatEnvironmentReflectance;
2572
+ #define DEBUGMODE_GAMMA
2573
+ #elif DEBUGMODE==85 && defined(SHEEN) && defined(REFLECTION)
2574
+ color=sheenOut.sheenEnvironmentReflectance;
2575
+ #define DEBUGMODE_GAMMA
2576
+ #elif DEBUGMODE==86 && defined(ALPHABLEND)
2577
+ color= vec3f(luminanceOverAlpha);
2578
+ #elif DEBUGMODE==87
2579
+ color= vec3f(alpha);
2580
+ #elif DEBUGMODE==88 && defined(ALBEDO)
2581
+ color= vec3f(albedoTexture.a);
2582
+ #elif DEBUGMODE==89
2583
+ color=aoOut.ambientOcclusionColor;
2584
+ #else
2585
+ var stripeWidth: f32=30.;var stripePos: f32=abs(floor(input.position.x/stripeWidth));var whichColor: f32=((stripePos)%(2.));var color1: vec3f= vec3f(.6,.2,.2);var color2: vec3f= vec3f(.3,.1,.1);color=mix(color1,color2,whichColor);
2586
+ #endif
2587
+ color*=uniforms.vDebugMode.y;
2588
+ #ifdef DEBUGMODE_NORMALIZE
2589
+ color=normalize(color)*0.5+0.5;
2590
+ #endif
2591
+ #ifdef DEBUGMODE_GAMMA
2592
+ color=toGammaSpaceVec3(color);
2593
+ #endif
2594
+ fragmentOutputs.color=vec4f(color,1.0);
2595
+ #ifdef PREPASS
2596
+ fragmentOutputs.fragData0=toLinearSpaceVec3(color);
2597
+ fragmentOutputs.fragData1=vec4f(0.,0.,0.,0.);
2598
+ #endif
2599
+ #ifdef DEBUGMODE_FORCERETURN
2600
+ return fragmentOutputs;
2601
+ #endif
2602
+ }
2603
+ #endif
2604
+ `;
2605
+ e.IncludesShadersStoreWGSL[B] || (e.IncludesShadersStoreWGSL[B] = Re);
2606
+ const i = "pbrPixelShader", G = `#define PBR_FRAGMENT_SHADER
2607
+ #define CUSTOM_FRAGMENT_BEGIN
2608
+ #include<prePassDeclaration>[SCENE_MRT_COUNT]
2609
+ #include<oitDeclaration>
2610
+ #ifndef FROMLINEARSPACE
2611
+ #define FROMLINEARSPACE
2612
+ #endif
2613
+ #include<pbrUboDeclaration>
2614
+ #include<pbrFragmentExtraDeclaration>
2615
+ #include<lightUboDeclaration>[0..maxSimultaneousLights]
2616
+ #include<pbrFragmentSamplersDeclaration>
2617
+ #include<imageProcessingDeclaration>
2618
+ #include<clipPlaneFragmentDeclaration>
2619
+ #include<logDepthDeclaration>
2620
+ #include<fogFragmentDeclaration>
2621
+ #include<helperFunctions>
2622
+ #include<subSurfaceScatteringFunctions>
2623
+ #include<importanceSampling>
2624
+ #include<pbrHelperFunctions>
2625
+ #include<imageProcessingFunctions>
2626
+ #include<shadowsFragmentFunctions>
2627
+ #include<harmonicsFunctions>
2628
+ #include<pbrDirectLightingSetupFunctions>
2629
+ #include<pbrDirectLightingFalloffFunctions>
2630
+ #include<pbrBRDFFunctions>
2631
+ #include<hdrFilteringFunctions>
2632
+ #include<pbrDirectLightingFunctions>
2633
+ #include<pbrIBLFunctions>
2634
+ #include<bumpFragmentMainFunctions>
2635
+ #include<bumpFragmentFunctions>
2636
+ #ifdef REFLECTION
2637
+ #include<reflectionFunction>
2638
+ #endif
2639
+ #define CUSTOM_FRAGMENT_DEFINITIONS
2640
+ #include<pbrBlockAlbedoOpacity>
2641
+ #include<pbrBlockReflectivity>
2642
+ #include<pbrBlockAmbientOcclusion>
2643
+ #include<pbrBlockAlphaFresnel>
2644
+ #include<pbrBlockAnisotropic>
2645
+ #include<pbrBlockReflection>
2646
+ #include<pbrBlockSheen>
2647
+ #include<pbrBlockClearcoat>
2648
+ #include<pbrBlockIridescence>
2649
+ #include<pbrBlockSubSurface>
2650
+ @fragment
2651
+ fn main(input: FragmentInputs)->FragmentOutputs {
2652
+ #define CUSTOM_FRAGMENT_MAIN_BEGIN
2653
+ #include<clipPlaneFragment>
2654
+ #include<pbrBlockNormalGeometric>
2655
+ #include<bumpFragment>
2656
+ #include<pbrBlockNormalFinal>
2657
+ var albedoOpacityOut: albedoOpacityOutParams;
2658
+ #ifdef ALBEDO
2659
+ var albedoTexture: vec4f=textureSample(albedoSampler,albedoSamplerSampler,fragmentInputs.vAlbedoUV+uvOffset);
2660
+ #endif
2661
+ #ifdef BASE_WEIGHT
2662
+ var baseWeightTexture: vec4f=textureSample(baseWeightSampler,baseWeightSamplerSampler,fragmentInputs.vBaseWeightUV+uvOffset);
2663
+ #endif
2664
+ #ifdef OPACITY
2665
+ var opacityMap: vec4f=textureSample(opacitySampler,opacitySamplerSampler,fragmentInputs.vOpacityUV+uvOffset);
2666
+ #endif
2667
+ #ifdef DECAL
2668
+ var decalColor: vec4f=textureSample(decalSampler,decalSamplerSampler,fragmentInputs.vDecalUV+uvOffset);
2669
+ #endif
2670
+ albedoOpacityOut=albedoOpacityBlock(
2671
+ uniforms.vAlbedoColor
2672
+ #ifdef ALBEDO
2673
+ ,albedoTexture
2674
+ ,uniforms.vAlbedoInfos
2675
+ #endif
2676
+ ,uniforms.baseWeight
2677
+ #ifdef BASE_WEIGHT
2678
+ ,baseWeightTexture
2679
+ ,uniforms.vBaseWeightInfos
2680
+ #endif
2681
+ #ifdef OPACITY
2682
+ ,opacityMap
2683
+ ,uniforms.vOpacityInfos
2684
+ #endif
2685
+ #ifdef DETAIL
2686
+ ,detailColor
2687
+ ,uniforms.vDetailInfos
2688
+ #endif
2689
+ #ifdef DECAL
2690
+ ,decalColor
2691
+ ,uniforms.vDecalInfos
2692
+ #endif
2693
+ );var surfaceAlbedo: vec3f=albedoOpacityOut.surfaceAlbedo;var alpha: f32=albedoOpacityOut.alpha;
2694
+ #define CUSTOM_FRAGMENT_UPDATE_ALPHA
2695
+ #include<depthPrePass>
2696
+ #define CUSTOM_FRAGMENT_BEFORE_LIGHTS
2697
+ var aoOut: ambientOcclusionOutParams;
2698
+ #ifdef AMBIENT
2699
+ var ambientOcclusionColorMap: vec3f=textureSample(ambientSampler,ambientSamplerSampler,fragmentInputs.vAmbientUV+uvOffset).rgb;
2700
+ #endif
2701
+ aoOut=ambientOcclusionBlock(
2702
+ #ifdef AMBIENT
2703
+ ambientOcclusionColorMap,
2704
+ uniforms.vAmbientInfos
2705
+ #endif
2706
+ );
2707
+ #include<pbrBlockLightmapInit>
2708
+ #ifdef UNLIT
2709
+ var diffuseBase: vec3f= vec3f(1.,1.,1.);
2710
+ #else
2711
+ var baseColor: vec3f=surfaceAlbedo;var reflectivityOut: reflectivityOutParams;
2712
+ #if defined(REFLECTIVITY)
2713
+ var surfaceMetallicOrReflectivityColorMap: vec4f=textureSample(reflectivitySampler,reflectivitySamplerSampler,fragmentInputs.vReflectivityUV+uvOffset);var baseReflectivity: vec4f=surfaceMetallicOrReflectivityColorMap;
2714
+ #ifndef METALLICWORKFLOW
2715
+ #ifdef REFLECTIVITY_GAMMA
2716
+ surfaceMetallicOrReflectivityColorMap=toLinearSpaceVec4(surfaceMetallicOrReflectivityColorMap);
2717
+ #endif
2718
+ surfaceMetallicOrReflectivityColorMap=vec4f(surfaceMetallicOrReflectivityColorMap.rgb*uniforms.vReflectivityInfos.y,surfaceMetallicOrReflectivityColorMap.a);
2719
+ #endif
2720
+ #endif
2721
+ #if defined(MICROSURFACEMAP)
2722
+ var microSurfaceTexel: vec4f=textureSample(microSurfaceSampler,microSurfaceSamplerSampler,fragmentInputs.vMicroSurfaceSamplerUV+uvOffset)*uniforms.vMicroSurfaceSamplerInfos.y;
2723
+ #endif
2724
+ #ifdef BASE_DIFFUSE_ROUGHNESS
2725
+ var baseDiffuseRoughnessTexture: f32=textureSample(baseDiffuseRoughnessSampler,baseDiffuseRoughnessSamplerSampler,fragmentInputs.vBaseDiffuseRoughnessUV+uvOffset).x;
2726
+ #endif
2727
+ #ifdef METALLICWORKFLOW
2728
+ var metallicReflectanceFactors: vec4f=uniforms.vMetallicReflectanceFactors;
2729
+ #ifdef REFLECTANCE
2730
+ var reflectanceFactorsMap: vec4f=textureSample(reflectanceSampler,reflectanceSamplerSampler,fragmentInputs.vReflectanceUV+uvOffset);
2731
+ #ifdef REFLECTANCE_GAMMA
2732
+ reflectanceFactorsMap=toLinearSpaceVec4(reflectanceFactorsMap);
2733
+ #endif
2734
+ metallicReflectanceFactors=vec4f(metallicReflectanceFactors.rgb*reflectanceFactorsMap.rgb,metallicReflectanceFactors.a);
2735
+ #endif
2736
+ #ifdef METALLIC_REFLECTANCE
2737
+ var metallicReflectanceFactorsMap: vec4f=textureSample(metallicReflectanceSampler,metallicReflectanceSamplerSampler,fragmentInputs.vMetallicReflectanceUV+uvOffset);
2738
+ #ifdef METALLIC_REFLECTANCE_GAMMA
2739
+ metallicReflectanceFactorsMap=toLinearSpaceVec4(metallicReflectanceFactorsMap);
2740
+ #endif
2741
+ #ifndef METALLIC_REFLECTANCE_USE_ALPHA_ONLY
2742
+ metallicReflectanceFactors=vec4f(metallicReflectanceFactors.rgb*metallicReflectanceFactorsMap.rgb,metallicReflectanceFactors.a);
2743
+ #endif
2744
+ metallicReflectanceFactors.a*=metallicReflectanceFactorsMap.a;
2745
+ #endif
2746
+ #endif
2747
+ reflectivityOut=reflectivityBlock(
2748
+ uniforms.vReflectivityColor
2749
+ #ifdef METALLICWORKFLOW
2750
+ ,surfaceAlbedo
2751
+ ,metallicReflectanceFactors
2752
+ #endif
2753
+ ,uniforms.baseDiffuseRoughness
2754
+ #ifdef BASE_DIFFUSE_ROUGHNESS
2755
+ ,baseDiffuseRoughnessTexture
2756
+ ,uniforms.vBaseDiffuseRoughnessInfos
2757
+ #endif
2758
+ #ifdef REFLECTIVITY
2759
+ ,uniforms.vReflectivityInfos
2760
+ ,surfaceMetallicOrReflectivityColorMap
2761
+ #endif
2762
+ #if defined(METALLICWORKFLOW) && defined(REFLECTIVITY) && defined(AOSTOREINMETALMAPRED)
2763
+ ,aoOut.ambientOcclusionColor
2764
+ #endif
2765
+ #ifdef MICROSURFACEMAP
2766
+ ,microSurfaceTexel
2767
+ #endif
2768
+ #ifdef DETAIL
2769
+ ,detailColor
2770
+ ,uniforms.vDetailInfos
2771
+ #endif
2772
+ );var microSurface: f32=reflectivityOut.microSurface;var roughness: f32=reflectivityOut.roughness;var diffuseRoughness: f32=reflectivityOut.diffuseRoughness;
2773
+ #ifdef METALLICWORKFLOW
2774
+ surfaceAlbedo=reflectivityOut.surfaceAlbedo;
2775
+ #endif
2776
+ #if defined(METALLICWORKFLOW) && defined(REFLECTIVITY) && defined(AOSTOREINMETALMAPRED)
2777
+ aoOut.ambientOcclusionColor=reflectivityOut.ambientOcclusionColor;
2778
+ #endif
2779
+ #ifdef ALPHAFRESNEL
2780
+ #if defined(ALPHATEST) || defined(ALPHABLEND)
2781
+ var alphaFresnelOut: alphaFresnelOutParams;alphaFresnelOut=alphaFresnelBlock(
2782
+ normalW,
2783
+ viewDirectionW,
2784
+ alpha,
2785
+ microSurface
2786
+ );alpha=alphaFresnelOut.alpha;
2787
+ #endif
2788
+ #endif
2789
+ #include<pbrBlockGeometryInfo>
2790
+ #ifdef ANISOTROPIC
2791
+ var anisotropicOut: anisotropicOutParams;
2792
+ #ifdef ANISOTROPIC_TEXTURE
2793
+ var anisotropyMapData: vec3f=textureSample(anisotropySampler,anisotropySamplerSampler,fragmentInputs.vAnisotropyUV+uvOffset).rgb*uniforms.vAnisotropyInfos.y;
2794
+ #endif
2795
+ anisotropicOut=anisotropicBlock(
2796
+ uniforms.vAnisotropy,
2797
+ roughness,
2798
+ #ifdef ANISOTROPIC_TEXTURE
2799
+ anisotropyMapData,
2800
+ #endif
2801
+ TBN,
2802
+ normalW,
2803
+ viewDirectionW
2804
+ );
2805
+ #endif
2806
+ #ifdef REFLECTION
2807
+ var reflectionOut: reflectionOutParams;
2808
+ #ifndef USE_CUSTOM_REFLECTION
2809
+ reflectionOut=reflectionBlock(
2810
+ fragmentInputs.vPositionW
2811
+ ,normalW
2812
+ ,alphaG
2813
+ ,uniforms.vReflectionMicrosurfaceInfos
2814
+ ,uniforms.vReflectionInfos
2815
+ ,uniforms.vReflectionColor
2816
+ #ifdef ANISOTROPIC
2817
+ ,anisotropicOut
2818
+ #endif
2819
+ #if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)
2820
+ ,NdotVUnclamped
2821
+ #endif
2822
+ #ifdef LINEARSPECULARREFLECTION
2823
+ ,roughness
2824
+ #endif
2825
+ ,reflectionSampler
2826
+ ,reflectionSamplerSampler
2827
+ #if defined(NORMAL) && defined(USESPHERICALINVERTEX)
2828
+ ,fragmentInputs.vEnvironmentIrradiance
2829
+ #endif
2830
+ #if (defined(USESPHERICALFROMREFLECTIONMAP) && (!defined(NORMAL) || !defined(USESPHERICALINVERTEX))) || (defined(USEIRRADIANCEMAP) && defined(REFLECTIONMAP_3D))
2831
+ ,uniforms.reflectionMatrix
2832
+ #endif
2833
+ #ifdef USEIRRADIANCEMAP
2834
+ ,irradianceSampler
2835
+ ,irradianceSamplerSampler
2836
+ #ifdef USE_IRRADIANCE_DOMINANT_DIRECTION
2837
+ ,uniforms.vReflectionDominantDirection
2838
+ #endif
2839
+ #endif
2840
+ #ifndef LODBASEDMICROSFURACE
2841
+ ,reflectionLowSampler
2842
+ ,reflectionLowSamplerSampler
2843
+ ,reflectionHighSampler
2844
+ ,reflectionHighSamplerSampler
2845
+ #endif
2846
+ #ifdef REALTIME_FILTERING
2847
+ ,uniforms.vReflectionFilteringInfo
2848
+ #ifdef IBL_CDF_FILTERING
2849
+ ,icdfSampler
2850
+ ,icdfSamplerSampler
2851
+ #endif
2852
+ #endif
2853
+ ,viewDirectionW
2854
+ ,diffuseRoughness
2855
+ ,surfaceAlbedo
2856
+ );
2857
+ #else
2858
+ #define CUSTOM_REFLECTION
2859
+ #endif
2860
+ #endif
2861
+ #include<pbrBlockReflectance0>
2862
+ #ifdef SHEEN
2863
+ var sheenOut: sheenOutParams;
2864
+ #ifdef SHEEN_TEXTURE
2865
+ var sheenMapData: vec4f=textureSample(sheenSampler,sheenSamplerSampler,fragmentInputs.vSheenUV+uvOffset);
2866
+ #endif
2867
+ #if defined(SHEEN_ROUGHNESS) && defined(SHEEN_TEXTURE_ROUGHNESS) && !defined(SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE)
2868
+ var sheenMapRoughnessData: vec4f=textureSample(sheenRoughnessSampler,sheenRoughnessSamplerSampler,fragmentInputs.vSheenRoughnessUV+uvOffset)*uniforms.vSheenInfos.w;
2869
+ #endif
2870
+ sheenOut=sheenBlock(
2871
+ uniforms.vSheenColor
2872
+ #ifdef SHEEN_ROUGHNESS
2873
+ ,uniforms.vSheenRoughness
2874
+ #if defined(SHEEN_TEXTURE_ROUGHNESS) && !defined(SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE)
2875
+ ,sheenMapRoughnessData
2876
+ #endif
2877
+ #endif
2878
+ ,roughness
2879
+ #ifdef SHEEN_TEXTURE
2880
+ ,sheenMapData
2881
+ ,uniforms.vSheenInfos.y
2882
+ #endif
2883
+ ,reflectanceF0
2884
+ #ifdef SHEEN_LINKWITHALBEDO
2885
+ ,baseColor
2886
+ ,surfaceAlbedo
2887
+ #endif
2888
+ #ifdef ENVIRONMENTBRDF
2889
+ ,NdotV
2890
+ ,environmentBrdf
2891
+ #endif
2892
+ #if defined(REFLECTION) && defined(ENVIRONMENTBRDF)
2893
+ ,AARoughnessFactors
2894
+ ,uniforms.vReflectionMicrosurfaceInfos
2895
+ ,uniforms.vReflectionInfos
2896
+ ,uniforms.vReflectionColor
2897
+ ,uniforms.vLightingIntensity
2898
+ ,reflectionSampler
2899
+ ,reflectionSamplerSampler
2900
+ ,reflectionOut.reflectionCoords
2901
+ ,NdotVUnclamped
2902
+ #ifndef LODBASEDMICROSFURACE
2903
+ ,reflectionLowSampler
2904
+ ,reflectionLowSamplerSampler
2905
+ ,reflectionHighSampler
2906
+ ,reflectionHighSamplerSampler
2907
+ #endif
2908
+ #ifdef REALTIME_FILTERING
2909
+ ,uniforms.vReflectionFilteringInfo
2910
+ #endif
2911
+ #if !defined(REFLECTIONMAP_SKYBOX) && defined(RADIANCEOCCLUSION)
2912
+ ,seo
2913
+ #endif
2914
+ #if !defined(REFLECTIONMAP_SKYBOX) && defined(HORIZONOCCLUSION) && defined(BUMP) && defined(REFLECTIONMAP_3D)
2915
+ ,eho
2916
+ #endif
2917
+ #endif
2918
+ );
2919
+ #ifdef SHEEN_LINKWITHALBEDO
2920
+ surfaceAlbedo=sheenOut.surfaceAlbedo;
2921
+ #endif
2922
+ #endif
2923
+ #ifdef CLEARCOAT
2924
+ #ifdef CLEARCOAT_TEXTURE
2925
+ var clearCoatMapData: vec2f=textureSample(clearCoatSampler,clearCoatSamplerSampler,fragmentInputs.vClearCoatUV+uvOffset).rg*uniforms.vClearCoatInfos.y;
2926
+ #endif
2927
+ #endif
2928
+ #ifdef IRIDESCENCE
2929
+ var iridescenceOut: iridescenceOutParams;
2930
+ #ifdef IRIDESCENCE_TEXTURE
2931
+ var iridescenceMapData: vec2f=textureSample(iridescenceSampler,iridescenceSamplerSampler,fragmentInputs.vIridescenceUV+uvOffset).rg*uniforms.vIridescenceInfos.y;
2932
+ #endif
2933
+ #ifdef IRIDESCENCE_THICKNESS_TEXTURE
2934
+ var iridescenceThicknessMapData: vec2f=textureSample(iridescenceThicknessSampler,iridescenceThicknessSamplerSampler,fragmentInputs.vIridescenceThicknessUV+uvOffset).rg*uniforms.vIridescenceInfos.w;
2935
+ #endif
2936
+ iridescenceOut=iridescenceBlock(
2937
+ uniforms.vIridescenceParams
2938
+ ,NdotV
2939
+ ,specularEnvironmentR0
2940
+ #ifdef IRIDESCENCE_TEXTURE
2941
+ ,iridescenceMapData
2942
+ #endif
2943
+ #ifdef IRIDESCENCE_THICKNESS_TEXTURE
2944
+ ,iridescenceThicknessMapData
2945
+ #endif
2946
+ #ifdef CLEARCOAT
2947
+ ,NdotVUnclamped
2948
+ ,uniforms.vClearCoatParams
2949
+ #ifdef CLEARCOAT_TEXTURE
2950
+ ,clearCoatMapData
2951
+ #endif
2952
+ #endif
2953
+ );var iridescenceIntensity: f32=iridescenceOut.iridescenceIntensity;specularEnvironmentR0=iridescenceOut.specularEnvironmentR0;
2954
+ #endif
2955
+ var clearcoatOut: clearcoatOutParams;
2956
+ #ifdef CLEARCOAT
2957
+ #if defined(CLEARCOAT_TEXTURE_ROUGHNESS) && !defined(CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE)
2958
+ var clearCoatMapRoughnessData: vec4f=textureSample(clearCoatRoughnessSampler,clearCoatRoughnessSamplerSampler,fragmentInputs.vClearCoatRoughnessUV+uvOffset)*uniforms.vClearCoatInfos.w;
2959
+ #endif
2960
+ #if defined(CLEARCOAT_TINT) && defined(CLEARCOAT_TINT_TEXTURE)
2961
+ var clearCoatTintMapData: vec4f=textureSample(clearCoatTintSampler,clearCoatTintSamplerSampler,fragmentInputs.vClearCoatTintUV+uvOffset);
2962
+ #endif
2963
+ #ifdef CLEARCOAT_BUMP
2964
+ var clearCoatBumpMapData: vec4f=textureSample(clearCoatBumpSampler,clearCoatBumpSamplerSampler,fragmentInputs.vClearCoatBumpUV+uvOffset);
2965
+ #endif
2966
+ clearcoatOut=clearcoatBlock(
2967
+ fragmentInputs.vPositionW
2968
+ ,geometricNormalW
2969
+ ,viewDirectionW
2970
+ ,uniforms.vClearCoatParams
2971
+ #if defined(CLEARCOAT_TEXTURE_ROUGHNESS) && !defined(CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE)
2972
+ ,clearCoatMapRoughnessData
2973
+ #endif
2974
+ ,specularEnvironmentR0
2975
+ #ifdef CLEARCOAT_TEXTURE
2976
+ ,clearCoatMapData
2977
+ #endif
2978
+ #ifdef CLEARCOAT_TINT
2979
+ ,uniforms.vClearCoatTintParams
2980
+ ,uniforms.clearCoatColorAtDistance
2981
+ ,uniforms.vClearCoatRefractionParams
2982
+ #ifdef CLEARCOAT_TINT_TEXTURE
2983
+ ,clearCoatTintMapData
2984
+ #endif
2985
+ #endif
2986
+ #ifdef CLEARCOAT_BUMP
2987
+ ,uniforms.vClearCoatBumpInfos
2988
+ ,clearCoatBumpMapData
2989
+ ,fragmentInputs.vClearCoatBumpUV
2990
+ #if defined(TANGENT) && defined(NORMAL)
2991
+ ,mat3x3<f32>(input.vTBN0,input.vTBN1,input.vTBN2)
2992
+ #else
2993
+ ,uniforms.vClearCoatTangentSpaceParams
2994
+ #endif
2995
+ #ifdef OBJECTSPACE_NORMALMAP
2996
+ ,uniforms.normalMatrix
2997
+ #endif
2998
+ #endif
2999
+ #if defined(FORCENORMALFORWARD) && defined(NORMAL)
3000
+ ,faceNormal
3001
+ #endif
3002
+ #ifdef REFLECTION
3003
+ ,uniforms.vReflectionMicrosurfaceInfos
3004
+ ,uniforms.vReflectionInfos
3005
+ ,uniforms.vReflectionColor
3006
+ ,uniforms.vLightingIntensity
3007
+ ,reflectionSampler
3008
+ ,reflectionSamplerSampler
3009
+ #ifndef LODBASEDMICROSFURACE
3010
+ ,reflectionLowSampler
3011
+ ,reflectionLowSamplerSampler
3012
+ ,reflectionHighSampler
3013
+ ,reflectionHighSamplerSampler
3014
+ #endif
3015
+ #ifdef REALTIME_FILTERING
3016
+ ,uniforms.vReflectionFilteringInfo
3017
+ #endif
3018
+ #endif
3019
+ #if defined(CLEARCOAT_BUMP) || defined(TWOSIDEDLIGHTING)
3020
+ ,select(-1.,1.,fragmentInputs.frontFacing)
3021
+ #endif
3022
+ );
3023
+ #else
3024
+ clearcoatOut.specularEnvironmentR0=specularEnvironmentR0;
3025
+ #endif
3026
+ #include<pbrBlockReflectance>
3027
+ var subSurfaceOut: subSurfaceOutParams;
3028
+ #ifdef SUBSURFACE
3029
+ #ifdef SS_THICKNESSANDMASK_TEXTURE
3030
+ var thicknessMap: vec4f=textureSample(thicknessSampler,thicknessSamplerSampler,fragmentInputs.vThicknessUV+uvOffset);
3031
+ #endif
3032
+ #ifdef SS_REFRACTIONINTENSITY_TEXTURE
3033
+ var refractionIntensityMap: vec4f=textureSample(refractionIntensitySampler,refractionIntensitySamplerSampler,fragmentInputs.vRefractionIntensityUV+uvOffset);
3034
+ #endif
3035
+ #ifdef SS_TRANSLUCENCYINTENSITY_TEXTURE
3036
+ var translucencyIntensityMap: vec4f=textureSample(translucencyIntensitySampler,translucencyIntensitySamplerSampler,fragmentInputs.vTranslucencyIntensityUV+uvOffset);
3037
+ #endif
3038
+ #ifdef SS_TRANSLUCENCYCOLOR_TEXTURE
3039
+ var translucencyColorMap: vec4f=textureSample(translucencyColorSampler,translucencyColorSamplerSampler,fragmentInputs.vTranslucencyColorUV+uvOffset);
3040
+ #ifdef SS_TRANSLUCENCYCOLOR_TEXTURE_GAMMA
3041
+ translucencyColorMap=toLinearSpaceVec4(translucencyColorMap);
3042
+ #endif
3043
+ #endif
3044
+ subSurfaceOut=subSurfaceBlock(
3045
+ uniforms.vSubSurfaceIntensity
3046
+ ,uniforms.vThicknessParam
3047
+ ,uniforms.vTintColor
3048
+ ,normalW
3049
+ #ifdef LEGACY_SPECULAR_ENERGY_CONSERVATION
3050
+ ,vec3f(max(colorSpecularEnvironmentReflectance.r,max(colorSpecularEnvironmentReflectance.g,colorSpecularEnvironmentReflectance.b)))
3051
+ #else
3052
+ ,baseSpecularEnvironmentReflectance
3053
+ #endif
3054
+ #ifdef SS_THICKNESSANDMASK_TEXTURE
3055
+ ,thicknessMap
3056
+ #endif
3057
+ #ifdef SS_REFRACTIONINTENSITY_TEXTURE
3058
+ ,refractionIntensityMap
3059
+ #endif
3060
+ #ifdef SS_TRANSLUCENCYINTENSITY_TEXTURE
3061
+ ,translucencyIntensityMap
3062
+ #endif
3063
+ #ifdef REFLECTION
3064
+ #ifdef SS_TRANSLUCENCY
3065
+ ,uniforms.reflectionMatrix
3066
+ #ifdef USESPHERICALFROMREFLECTIONMAP
3067
+ #if !defined(NORMAL) || !defined(USESPHERICALINVERTEX)
3068
+ ,reflectionOut.irradianceVector
3069
+ #endif
3070
+ #if defined(REALTIME_FILTERING)
3071
+ ,reflectionSampler
3072
+ ,reflectionSamplerSampler
3073
+ ,uniforms.vReflectionFilteringInfo
3074
+ #ifdef IBL_CDF_FILTERING
3075
+ ,icdfSampler
3076
+ ,icdfSamplerSampler
3077
+ #endif
3078
+ #endif
3079
+ #endif
3080
+ #ifdef USEIRRADIANCEMAP
3081
+ ,irradianceSampler
3082
+ ,irradianceSamplerSampler
3083
+ #endif
3084
+ #endif
3085
+ #endif
3086
+ #if defined(SS_REFRACTION) || defined(SS_TRANSLUCENCY)
3087
+ ,surfaceAlbedo
3088
+ #endif
3089
+ #ifdef SS_REFRACTION
3090
+ ,fragmentInputs.vPositionW
3091
+ ,viewDirectionW
3092
+ ,scene.view
3093
+ ,uniforms.vRefractionInfos
3094
+ ,uniforms.refractionMatrix
3095
+ ,uniforms.vRefractionMicrosurfaceInfos
3096
+ ,uniforms.vLightingIntensity
3097
+ #ifdef SS_LINKREFRACTIONTOTRANSPARENCY
3098
+ ,alpha
3099
+ #endif
3100
+ #ifdef SS_LODINREFRACTIONALPHA
3101
+ ,NdotVUnclamped
3102
+ #endif
3103
+ #ifdef SS_LINEARSPECULARREFRACTION
3104
+ ,roughness
3105
+ #endif
3106
+ ,alphaG
3107
+ ,refractionSampler
3108
+ ,refractionSamplerSampler
3109
+ #ifndef LODBASEDMICROSFURACE
3110
+ ,refractionLowSampler
3111
+ ,refractionLowSamplerSampler
3112
+ ,refractionHighSampler
3113
+ ,refractionHighSamplerSampler
3114
+ #endif
3115
+ #ifdef ANISOTROPIC
3116
+ ,anisotropicOut
3117
+ #endif
3118
+ #ifdef REALTIME_FILTERING
3119
+ ,uniforms.vRefractionFilteringInfo
3120
+ #endif
3121
+ #ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC
3122
+ ,uniforms.vRefractionPosition
3123
+ ,uniforms.vRefractionSize
3124
+ #endif
3125
+ #ifdef SS_DISPERSION
3126
+ ,dispersion
3127
+ #endif
3128
+ #endif
3129
+ #ifdef SS_TRANSLUCENCY
3130
+ ,uniforms.vDiffusionDistance
3131
+ ,uniforms.vTranslucencyColor
3132
+ #ifdef SS_TRANSLUCENCYCOLOR_TEXTURE
3133
+ ,translucencyColorMap
3134
+ #endif
3135
+ #endif
3136
+ );
3137
+ #ifdef SS_REFRACTION
3138
+ surfaceAlbedo=subSurfaceOut.surfaceAlbedo;
3139
+ #ifdef SS_LINKREFRACTIONTOTRANSPARENCY
3140
+ alpha=subSurfaceOut.alpha;
3141
+ #endif
3142
+ #endif
3143
+ #else
3144
+ subSurfaceOut.specularEnvironmentReflectance=colorSpecularEnvironmentReflectance;
3145
+ #endif
3146
+ #include<pbrBlockDirectLighting>
3147
+ #include<lightFragment>[0..maxSimultaneousLights]
3148
+ #include<pbrBlockFinalLitComponents>
3149
+ #endif
3150
+ #include<pbrBlockFinalUnlitComponents>
3151
+ #define CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION
3152
+ #include<pbrBlockFinalColorComposition>
3153
+ #include<logDepthFragment>
3154
+ #include<fogFragment>(color,finalColor)
3155
+ #include<pbrBlockImageProcessing>
3156
+ #define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR
3157
+ #ifdef PREPASS
3158
+ #include<pbrBlockPrePass>
3159
+ #endif
3160
+ #if !defined(PREPASS) && !defined(ORDER_INDEPENDENT_TRANSPARENCY)
3161
+ fragmentOutputs.color=finalColor;
3162
+ #endif
3163
+ #include<oitFragment>
3164
+ #if ORDER_INDEPENDENT_TRANSPARENCY
3165
+ if (fragDepth==nearestDepth) {fragmentOutputs.frontColor=vec4f(fragmentOutputs.frontColor.rgb+finalColor.rgb*finalColor.a*alphaMultiplier,1.0-alphaMultiplier*(1.0-finalColor.a));} else {fragmentOutputs.backColor+=finalColor;}
3166
+ #endif
3167
+ #include<pbrDebug>
3168
+ #define CUSTOM_FRAGMENT_MAIN_END
3169
+ }
3170
+ `;
3171
+ e.ShadersStoreWGSL[i] || (e.ShadersStoreWGSL[i] = G);
3172
+ const Ne = { name: i, shader: G };
3173
+ export {
3174
+ Ne as pbrPixelShaderWGSL
3175
+ };
3176
+ //# sourceMappingURL=pbr.fragment-C8Lm3cwF.js.map