PageSourceSearch

https://ds-k.site/_astro/openpbr.fragment.BBXUT7w5.js

js ds-k.site collected 2026-09-24 10:12:50 UTC 58,471 bytes, 1,028 lines download raw bytes

1import{S as e}from"./Layout.astro_astro_type_script_index_0_lang.D7HFstIc.js";import"./oitFragment.DnUuI8rn.js";import"./openpbrUboDeclaration.C2t81ehY.js";import"./pbrDebug.Cqqj_t7A.js";import"./clipPlaneFragment.BPRaAm28.js";import"./logDepthDeclaration.BoY2_7ZG.js";import"./helperFunctions.BQK4OmV-.js";import"./harmonicsFunctions.y2hOnlnn.js";import"./_commonjsHelpers.CqkleIqs.js";import"./meshUboDeclaration.DibNTUJA.js";const r="openpbrFragmentSamplersDeclaration",I=`#include<samplerFragmentDeclaration>(_DEFINENAME_,BASE_COLOR,_VARYINGNAME_,BaseColor,_SAMPLERNAME_,baseColor)
2#include<samplerFragmentDeclaration>(_DEFINENAME_,BASE_WEIGHT,_VARYINGNAME_,BaseWeight,_SAMPLERNAME_,baseWeight)
3#include<samplerFragmentDeclaration>(_DEFINENAME_,BASE_DIFFUSE_ROUGHNESS,_VARYINGNAME_,BaseDiffuseRoughness,_SAMPLERNAME_,baseDiffuseRoughness)
4#include<samplerFragmentDeclaration>(_DEFINENAME_,BASE_METALNESS,_VARYINGNAME_,BaseMetalness,_SAMPLERNAME_,baseMetalness)
5#include<samplerFragmentDeclaration>(_DEFINENAME_,SPECULAR_WEIGHT,_VARYINGNAME_,SpecularWeight,_SAMPLERNAME_,specularWeight)
6#include<samplerFragmentDeclaration>(_DEFINENAME_,SPECULAR_COLOR,_VARYINGNAME_,SpecularColor,_SAMPLERNAME_,specularColor)
7#include<samplerFragmentDeclaration>(_DEFINENAME_,SPECULAR_ROUGHNESS,_VARYINGNAME_,SpecularRoughness,_SAMPLERNAME_,specularRoughness)
8#include<samplerFragmentDeclaration>(_DEFINENAME_,SPECULAR_ROUGHNESS_ANISOTROPY,_VARYINGNAME_,SpecularRoughnessAnisotropy,_SAMPLERNAME_,specularRoughnessAnisotropy)
9#include<samplerFragmentDeclaration>(_DEFINENAME_,COAT_WEIGHT,_VARYINGNAME_,CoatWeight,_SAMPLERNAME_,coatWeight)
10#include<samplerFragmentDeclaration>(_DEFINENAME_,COAT_COLOR,_VARYINGNAME_,CoatColor,_SAMPLERNAME_,coatColor)
11#include<samplerFragmentDeclaration>(_DEFINENAME_,COAT_ROUGHNESS,_VARYINGNAME_,CoatRoughness,_SAMPLERNAME_,coatRoughness)
12#include<samplerFragmentDeclaration>(_DEFINENAME_,COAT_ROUGHNESS_ANISOTROPY,_VARYINGNAME_,CoatRoughnessAnisotropy,_SAMPLERNAME_,coatRoughnessAnisotropy)
13#include<samplerFragmentDeclaration>(_DEFINENAME_,COAT_DARKENING,_VARYINGNAME_,CoatDarkening,_SAMPLERNAME_,coatDarkening)
14#include<samplerFragmentDeclaration>(_DEFINENAME_,GEOMETRY_OPACITY,_VARYINGNAME_,GeometryOpacity,_SAMPLERNAME_,geometryOpacity)
15#include<samplerFragmentDeclaration>(_DEFINENAME_,GEOMETRY_TANGENT,_VARYINGNAME_,GeometryTangent,_SAMPLERNAME_,geometryTangent)
16#include<samplerFragmentDeclaration>(_DEFINENAME_,GEOMETRY_COAT_TANGENT,_VARYINGNAME_,GeometryCoatTangent,_SAMPLERNAME_,geometryCoatTangent)
17#include<samplerFragmentDeclaration>(_DEFINENAME_,EMISSION_COLOR,_VARYINGNAME_,EmissionColor,_SAMPLERNAME_,emissionColor)
18#include<samplerFragmentDeclaration>(_DEFINENAME_,AMBIENT_OCCLUSION,_VARYINGNAME_,AmbientOcclusion,_SAMPLERNAME_,ambientOcclusion)
19#include<samplerFragmentDeclaration>(_DEFINENAME_,DECAL,_VARYINGNAME_,Decal,_SAMPLERNAME_,decal)
20#ifdef REFLECTION
21#ifdef REFLECTIONMAP_3D
22var reflectionSamplerSampler: sampler;var reflectionSampler: texture_cube<f32>;
23#ifdef LODBASEDMICROSFURACE
24#else
25var reflectionLowSamplerSampler: sampler;var reflectionLowSampler: texture_cube<f32>;var reflectionHighSamplerSampler: sampler;var reflectionHighSampler: texture_cube<f32>;
26#endif
27#ifdef USEIRRADIANCEMAP
28var irradianceSamplerSampler: sampler;var irradianceSampler: texture_cube<f32>;
29#endif
30#else
31var reflectionSamplerSampler: sampler;var reflectionSampler: texture_2d<f32>;
32#ifdef LODBASEDMICROSFURACE
33#else
34var reflectionLowSamplerSampler: sampler;var reflectionLowSampler: texture_2d<f32>;var reflectionHighSamplerSampler: sampler;var reflectionHighSampler: texture_2d<f32>;
35#endif
36#ifdef USEIRRADIANCEMAP
37var irradianceSamplerSampler: sampler;var irradianceSampler: texture_2d<f32>;
38#endif
39#endif
40#ifdef REFLECTIONMAP_SKYBOX
41varying vPositionUVW: vec3f;
42#else
43#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)
44varying vDirectionW: vec3f;
45#endif
46#endif
47#endif
48#ifdef ENVIRONMENTBRDF
49var environmentBrdfSamplerSampler: sampler;var environmentBrdfSampler: texture_2d<f32>;
50#endif
51#ifdef ANISOTROPIC
52var blueNoiseSamplerSampler: sampler;var blueNoiseSampler: texture_2d<f32>;
53#endif
54#ifdef IBL_CDF_FILTERING
55var icdfSamplerSampler: sampler;var icdfSampler: texture_2d<f32>;
56#endif
57`;e.IncludesShadersStoreWGSL[r]||(e.IncludesShadersStoreWGSL[r]=I);const o="openpbrNormalMapFragmentMainFunctions",E=`#if defined(GEOMETRY_NORMAL) || defined(CLEARCOAT_BUMP) || defined(ANISOTROPIC) || defined(DETAIL)
58#if defined(TANGENT) && defined(NORMAL) 
59varying vTBN0: vec3f;varying vTBN1: vec3f;varying vTBN2: vec3f;
60#endif
61#ifdef OBJECTSPACE_NORMALMAP
62uniform normalMatrix: mat4x4f;fn toNormalMatrix(m: mat4x4f)->mat4x4f
63{var a00=m[0][0];var a01=m[0][1];var a02=m[0][2];var a03=m[0][3];var a10=m[1][0];var a11=m[1][1];var a12=m[1][2];var a13=m[1][3];var a20=m[2][0]; 
64var a21=m[2][1];var a22=m[2][2];var a23=m[2][3];var a30=m[3][0]; 
65var a31=m[3][1];var a32=m[3][2];var a33=m[3][3];var b00=a00*a11-a01*a10;var b01=a00*a12-a02*a10;var b02=a00*a13-a03*a10;var b03=a01*a12-a02*a11;var b04=a01*a13-a03*a11;var b05=a02*a13-a03*a12;var b06=a20*a31-a21*a30;var b07=a20*a32-a22*a30;var b08=a20*a33-a23*a30;var b09=a21*a32-a22*a31;var b10=a21*a33-a23*a31;var b11=a22*a33-a23*a32;var det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;var mi=mat4x4<f32>(
66(a11*b11-a12*b10+a13*b09)/det,
67(a02*b10-a01*b11-a03*b09)/det,
68(a31*b05-a32*b04+a33*b03)/det,
69(a22*b04-a21*b05-a23*b03)/det,
70(a12*b08-a10*b11-a13*b07)/det,
71(a00*b11-a02*b08+a03*b07)/det,
72(a32*b02-a30*b05-a33*b01)/det,
73(a20*b05-a22*b02+a23*b01)/det,
74(a10*b10-a11*b08+a13*b06)/det,
75(a01*b08-a00*b10-a03*b06)/det,
76(a30*b04-a31*b02+a33*b00)/det,
77(a21*b02-a20*b04-a23*b00)/det,
78(a11*b07-a10*b09-a12*b06)/det,
79(a00*b09-a01*b07+a02*b06)/det,
80(a31*b01-a30*b03-a32*b00)/det,
81(a20*b03-a21*b01+a22*b00)/det);return mat4x4<f32>(mi[0][0],mi[1][0],mi[2][0],mi[3][0],
82mi[0][1],mi[1][1],mi[2][1],mi[3][1],
83mi[0][2],mi[1][2],mi[2][2],mi[3][2],
84mi[0][3],mi[1][3],mi[2][3],mi[3][3]);}
85#endif
86fn perturbNormalBase(cotangentFrame: mat3x3f,normal: vec3f,scale: f32)->vec3f
87{var output=normal;
88#ifdef NORMALXYSCALE
89output=normalize(output* vec3f(scale,scale,1.0));
90#endif
91return normalize(cotangentFrame*output);}
92fn perturbNormal(cotangentFrame: mat3x3f,textureSample: vec3f,scale: f32)->vec3f
93{return perturbNormalBase(cotangentFrame,textureSample*2.0-1.0,scale);}
94fn cotangent_frame(normal: vec3f,p: vec3f,uv: vec2f,tangentSpaceParams: vec2f)->mat3x3f
95{var dp1: vec3f=dpdx(p);var dp2: vec3f=dpdy(p);var duv1: vec2f=dpdx(uv);var duv2: vec2f=dpdy(uv);var dp2perp: vec3f=cross(dp2,normal);var dp1perp: vec3f=cross(normal,dp1);var tangent: vec3f=dp2perp*duv1.x+dp1perp*duv2.x;var bitangent: vec3f=dp2perp*duv1.y+dp1perp*duv2.y;tangent*=tangentSpaceParams.x;bitangent*=tangentSpaceParams.y;var det: f32=max(dot(tangent,tangent),dot(bitangent,bitangent));var invmax: f32=select(inverseSqrt(det),0.0,det==0.0);return mat3x3f(tangent*invmax,bitangent*invmax,normal);}
96#endif
97`;e.IncludesShadersStoreWGSL[o]||(e.IncludesShadersStoreWGSL[o]=E);const n="openpbrNormalMapFragmentFunctions",S=`#if defined(GEOMETRY_NORMAL)
98#include<samplerFragmentDeclaration>(_DEFINENAME_,GEOMETRY_NORMAL,_VARYINGNAME_,GeometryNormal,_SAMPLERNAME_,geometryNormal)
99#endif
100#if defined(GEOMETRY_COAT_NORMAL)
101#include<samplerFragmentDeclaration>(_DEFINENAME_,GEOMETRY_COAT_NORMAL,_VARYINGNAME_,GeometryCoatNormal,_SAMPLERNAME_,geometryCoatNormal)
102#endif
103#if defined(DETAIL)
104#include<samplerFragmentDeclaration>(_DEFINENAME_,DETAIL,_VARYINGNAME_,Detail,_SAMPLERNAME_,detail)
105#endif
106#if defined(GEOMETRY_NORMAL) && defined(PARALLAX)
107const minSamples: f32=4.;const maxSamples: f32=15.;const iMaxSamples: i32=15;fn parallaxOcclusion(vViewDirCoT: vec3f,vNormalCoT: vec3f,texCoord: vec2f,parallaxScale: f32)->vec2f {var parallaxLimit: f32=length(vViewDirCoT.xy)/vViewDirCoT.z;parallaxLimit*=parallaxScale;var vOffsetDir: vec2f=normalize(vViewDirCoT.xy);var vMaxOffset: vec2f=vOffsetDir*parallaxLimit;var numSamples: f32=maxSamples+(dot(vViewDirCoT,vNormalCoT)*(minSamples-maxSamples));var stepSize: f32=1.0/numSamples;var currRayHeight: f32=1.0;var vCurrOffset: vec2f= vec2f(0,0);var vLastOffset: vec2f= vec2f(0,0);var lastSampledHeight: f32=1.0;var currSampledHeight: f32=1.0;var keepWorking: bool=true;for (var i: i32=0; i<iMaxSamples; i++)
108{currSampledHeight=textureSample(geometryNormalSampler,geometryNormalSamplerSampler,texCoord+vCurrOffset).w;if (!keepWorking)
109{}
110else if (currSampledHeight>currRayHeight)
111{var delta1: f32=currSampledHeight-currRayHeight;var delta2: f32=(currRayHeight+stepSize)-lastSampledHeight;var ratio: f32=delta1/(delta1+delta2);vCurrOffset=(ratio)* vLastOffset+(1.0-ratio)*vCurrOffset;keepWorking=false;}
112else
113{currRayHeight-=stepSize;vLastOffset=vCurrOffset;
114#ifdef PARALLAX_RHS
115vCurrOffset-=stepSize*vMaxOffset;
116#else
117vCurrOffset+=stepSize*vMaxOffset;
118#endif
119lastSampledHeight=currSampledHeight;}}
120return vCurrOffset;}
121fn parallaxOffset(viewDir: vec3f,heightScale: f32)->vec2f
122{var height: f32=textureSample(geometryNormalSampler,geometryNormalSamplerSampler,fragmentInputs.vGeometryNormalUV).w;var texCoordOffset: vec2f=heightScale*viewDir.xy*height;
123#ifdef PARALLAX_RHS
124return texCoordOffset;
125#else
126return -texCoordOffset;
127#endif
128}
129#endif
130`;e.IncludesShadersStoreWGSL[n]||(e.IncludesShadersStoreWGSL[n]=S);const t="openpbrDielectricReflectance",R=`struct ReflectanceParams
131{F0: f32,
132F90: f32,
133coloredF0: vec3f,
134coloredF90: vec3f,};
135#define pbr_inline
136fn dielectricReflectance(
137insideIOR: f32,outsideIOR: f32,specularColor: vec3f,specularWeight: f32
138)->ReflectanceParams
139{var outParams: ReflectanceParams;let dielectricF0=pow((insideIOR-outsideIOR)/(insideIOR+outsideIOR),2.0);
140#if DIELECTRIC_SPECULAR_MODEL==DIELECTRIC_SPECULAR_MODEL_GLTF
141let maxF0=max(specularColor.r,max(specularColor.g,specularColor.b));outParams.F0=dielectricF0*maxF0*specularWeight;
142#else
143outParams.F0=dielectricF0*specularWeight;
144#endif
145let f90Scale=clamp(2.0f*abs(insideIOR-outsideIOR),0.0f,1.0f);outParams.F90=f90Scale*specularWeight;outParams.coloredF0=vec3f(dielectricF0*specularWeight)*specularColor.rgb;
146#if (DIELECTRIC_SPECULAR_MODEL==DIELECTRIC_SPECULAR_MODEL_OPENPBR)
147let dielectricColorF90: vec3f=specularColor.rgb*vec3f(f90Scale)*specularWeight;
148#else
149let dielectricColorF90: vec3f=vec3f(f90Scale)*specularWeight;
150#endif
151outParams.coloredF90=dielectricColorF90;return outParams;}
152`;e.IncludesShadersStoreWGSL[t]||(e.IncludesShadersStoreWGSL[t]=R);const i="openpbrConductorReflectance",N=`#define pbr_inline
153fn conductorReflectance(baseColor: vec3f,specularColor: vec3f,specularWeight: f32)->ReflectanceParams
154{var outParams: ReflectanceParams;
155#if (CONDUCTOR_SPECULAR_MODEL==CONDUCTOR_SPECULAR_MODEL_OPENPBR)
156outParams.coloredF0=baseColor*specularWeight;outParams.coloredF90=specularColor*specularWeight;
157#else
158outParams.coloredF0=baseColor;outParams.coloredF90=vec3f(1.0f);
159#endif
160outParams.F0=1.0f;outParams.F90=1.0f;return outParams;}`;e.IncludesShadersStoreWGSL[i]||(e.IncludesShadersStoreWGSL[i]=N);const f="openpbrBlockAmbientOcclusion",A=`struct ambientOcclusionOutParams
161{ambientOcclusionColor: vec3f,
162#if DEBUGMODE>0 && defined(AMBIENT_OCCLUSION)
163ambientOcclusionColorMap: vec3f
164#endif
165};
166#define pbr_inline
167fn ambientOcclusionBlock(
168#ifdef AMBIENT_OCCLUSION
169ambientOcclusionColorMap_: vec3f,
170ambientInfos: vec2f
171#endif
172)->ambientOcclusionOutParams
173{ 
174var outParams: ambientOcclusionOutParams;var ambientOcclusionColor: vec3f= vec3f(1.,1.,1.);
175#ifdef AMBIENT_OCCLUSION
176var ambientOcclusionColorMap: vec3f=ambientOcclusionColorMap_*ambientInfos.y;
177#ifdef AMBIENTINGRAYSCALE
178ambientOcclusionColorMap= vec3f(ambientOcclusionColorMap.r,ambientOcclusionColorMap.r,ambientOcclusionColorMap.r);
179#endif
180#if DEBUGMODE>0
181outParams.ambientOcclusionColorMap=ambientOcclusionColorMap;
182#endif
183#endif
184outParams.ambientOcclusionColor=ambientOcclusionColor;return outParams;}
185`;e.IncludesShadersStoreWGSL[f]||(e.IncludesShadersStoreWGSL[f]=A);const l="openpbrGeometryInfo",h=`struct geometryInfoOutParams
186{NdotV: f32,
187NdotVUnclamped: f32,
188environmentBrdf: vec3f,
189horizonOcclusion: f32};
190#ifdef ANISOTROPIC
191struct geometryInfoAnisoOutParams
192{NdotV: f32,
193NdotVUnclamped: f32,
194environmentBrdf: vec3f,
195horizonOcclusion: f32,
196anisotropy: f32,
197anisotropicTangent: vec3f,
198anisotropicBitangent: vec3f,
199TBN: mat3x3<f32>};
200#endif
201fn geometryInfo(
202normalW: vec3f,viewDirectionW: vec3f,roughness: f32,geometricNormalW: vec3f
203)->geometryInfoOutParams
204{var outParams: geometryInfoOutParams;outParams.NdotVUnclamped=dot(normalW,viewDirectionW);outParams.NdotV=absEps(outParams.NdotVUnclamped);
205#if defined(ENVIRONMENTBRDF)
206outParams.environmentBrdf=getBRDFLookup(outParams.NdotV,roughness);
207#else
208outParams.environmentBrdf=vec3f(0.0);
209#endif
210outParams.horizonOcclusion=1.0f;
211#if defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)
212#ifdef HORIZONOCCLUSION
213#if defined(GEOMETRY_NORMAL) || defined(GEOMETRY_COAT_NORMAL)
214#ifdef REFLECTIONMAP_3D
215outParams.horizonOcclusion=environmentHorizonOcclusion(-viewDirectionW,normalW,geometricNormalW);
216#endif
217#endif
218#endif
219#endif
220return outParams;}
221#ifdef ANISOTROPIC
222fn geometryInfoAniso(
223normalW: vec3f,viewDirectionW: vec3f,roughness: f32,geometricNormalW: vec3f
224,vAnisotropy: vec3f,TBN: mat3x3<f32>
225)->geometryInfoAnisoOutParams
226{let geoInfo: geometryInfoOutParams=geometryInfo(normalW,viewDirectionW,roughness,geometricNormalW);var outParams: geometryInfoAnisoOutParams;outParams.NdotV=geoInfo.NdotV;outParams.NdotVUnclamped=geoInfo.NdotVUnclamped;outParams.environmentBrdf=geoInfo.environmentBrdf;outParams.horizonOcclusion=geoInfo.horizonOcclusion;outParams.anisotropy=vAnisotropy.b;let anisotropyDirection: vec3f=vec3f(vAnisotropy.xy,0.);let anisoTBN: mat3x3<f32>=mat3x3<f32>(normalize(TBN[0]),normalize(TBN[1]),normalize(TBN[2]));outParams.anisotropicTangent=normalize(anisoTBN*anisotropyDirection);outParams.anisotropicBitangent=normalize(cross(anisoTBN[2],outParams.anisotropicTangent));outParams.TBN=TBN;return outParams;}
227#endif
228`;e.IncludesShadersStoreWGSL[l]||(e.IncludesShadersStoreWGSL[l]=h);const c="openpbrIblFunctions",L=`#ifdef REFLECTION
229fn sampleIrradiance(
230surfaceNormal: vec3f
231#if defined(NORMAL) && defined(USESPHERICALINVERTEX)
232,vEnvironmentIrradianceSH: vec3f
233#endif
234#if (defined(USESPHERICALFROMREFLECTIONMAP) && (!defined(NORMAL) || !defined(USESPHERICALINVERTEX))) || (defined(USEIRRADIANCEMAP) && defined(REFLECTIONMAP_3D))
235,iblMatrix: mat4x4f
236#endif
237#ifdef USEIRRADIANCEMAP
238#ifdef REFLECTIONMAP_3D
239,irradianceSampler: texture_cube<f32>
240,irradianceSamplerSampler: sampler
241#else
242,irradianceSampler: texture_2d<f32>
243,irradianceSamplerSampler: sampler
244#endif
245#ifdef USE_IRRADIANCE_DOMINANT_DIRECTION
246,reflectionDominantDirection: vec3f
247#endif
248#endif
249#ifdef REALTIME_FILTERING
250,reflectionFilteringInfo: vec2f
251#ifdef IBL_CDF_FILTERING
252,icdfSampler: texture_2d<f32>
253,icdfSamplerSampler: sampler
254#endif
255#endif
256,reflectionInfos: vec2f
257,viewDirectionW: vec3f
258,diffuseRoughness: f32
259,surfaceAlbedo: vec3f
260)->vec3f {var environmentIrradiance=vec3f(0.,0.,0.);
261#if (defined(USESPHERICALFROMREFLECTIONMAP) && (!defined(NORMAL) || !defined(USESPHERICALINVERTEX))) || (defined(USEIRRADIANCEMAP) && defined(REFLECTIONMAP_3D))
262var irradianceVector=(iblMatrix*vec4f(surfaceNormal,0.0f)).xyz;let irradianceView=(iblMatrix*vec4f(viewDirectionW,0.0f)).xyz;
263#if !defined(USE_IRRADIANCE_DOMINANT_DIRECTION) && !defined(REALTIME_FILTERING)
264#if BASE_DIFFUSE_MODEL != BRDF_DIFFUSE_MODEL_LAMBERT && BASE_DIFFUSE_MODEL != BRDF_DIFFUSE_MODEL_LEGACY
265{let NdotV=max(dot(surfaceNormal,viewDirectionW),0.0f);irradianceVector=mix(irradianceVector,irradianceView,(0.5f*(1.0f-NdotV))*diffuseRoughness);}
266#endif
267#endif
268#ifdef REFLECTIONMAP_OPPOSITEZ
269irradianceVector.z*=-1.0f;
270#endif
271#ifdef INVERTCUBICMAP
272irradianceVector.y*=-1.0f;
273#endif
274#endif
275#ifdef USESPHERICALFROMREFLECTIONMAP
276#if defined(NORMAL) && defined(USESPHERICALINVERTEX)
277environmentIrradiance=vEnvironmentIrradianceSH;
278#else
279#if defined(REALTIME_FILTERING)
280environmentIrradiance=irradiance(reflectionSampler,reflectionSamplerSampler,irradianceVector,reflectionFilteringInfo,diffuseRoughness,surfaceAlbedo,irradianceView
281#ifdef IBL_CDF_FILTERING
282,icdfSampler
283,icdfSamplerSampler
284#endif
285);
286#else
287environmentIrradiance=computeEnvironmentIrradiance(irradianceVector);
288#endif
289#endif
290#elif defined(USEIRRADIANCEMAP)
291#ifdef REFLECTIONMAP_3D
292let environmentIrradianceFromTexture: vec4f=textureSample(irradianceSampler,irradianceSamplerSampler,irradianceVector);
293#else
294let environmentIrradianceFromTexture: vec4f=textureSample(irradianceSampler,irradianceSamplerSampler,reflectionCoords);
295#endif
296environmentIrradiance=environmentIrradianceFromTexture.rgb;
297#ifdef RGBDREFLECTION
298environmentIrradiance.rgb=fromRGBD(environmentIrradianceFromTexture);
299#endif
300#ifdef GAMMAREFLECTION
301environmentIrradiance.rgb=toLinearSpace(environmentIrradiance.rgb);
302#endif
303#ifdef USE_IRRADIANCE_DOMINANT_DIRECTION
304let Ls: vec3f=normalize(reflectionDominantDirection);let NoL: f32=dot(irradianceVector,Ls);let NoV: f32=dot(irradianceVector,irradianceView);var diffuseRoughnessTerm=vec3f(1.0f);
305#if BASE_DIFFUSE_MODEL==BRDF_DIFFUSE_MODEL_EON
306let LoV: f32=dot (Ls,irradianceView);let mag: f32=length(reflectionDominantDirection)*2.0f;let clampedAlbedo: vec3f=clamp(surfaceAlbedo,vec3f(0.1f),vec3f(1.0f));diffuseRoughnessTerm=diffuseBRDF_EON(clampedAlbedo,diffuseRoughness,NoL,NoV,LoV)*PI;diffuseRoughnessTerm=diffuseRoughnessTerm/clampedAlbedo;diffuseRoughnessTerm=mix(vec3f(1.0f),diffuseRoughnessTerm,sqrt(clamp(mag*NoV,0.0f,1.0f)));
307#elif BASE_DIFFUSE_MODEL==BRDF_DIFFUSE_MODEL_BURLEY
308let H: vec3f=(irradianceView+Ls)*0.5f;let VoH: f32=dot(irradianceView,H);diffuseRoughnessTerm=vec3f(diffuseBRDF_Burley(NoL,NoV,VoH,diffuseRoughness)*PI);
309#endif
310environmentIrradiance=environmentIrradiance.rgb*diffuseRoughnessTerm;
311#endif
312#endif
313environmentIrradiance*=reflectionInfos.x;return environmentIrradiance;}
314#ifdef REFLECTIONMAP_3D
315fn createReflectionCoords(vPositionW: vec3f,normalW: vec3f)->vec3f
316#else
317fn createReflectionCoords(vPositionW: vec3f,normalW: vec3f)->vec2f
318#endif
319{var reflectionVector: vec3f=computeReflectionCoords(vec4f(vPositionW,1.0f),normalW);
320#ifdef REFLECTIONMAP_OPPOSITEZ
321reflectionVector.z*=-1.0;
322#endif
323#ifdef REFLECTIONMAP_3D
324var reflectionCoords: vec3f=reflectionVector;
325#else
326var reflectionCoords: vec2f=reflectionVector.xy;
327#ifdef REFLECTIONMAP_PROJECTION
328reflectionCoords/=reflectionVector.z;
329#endif
330reflectionCoords.y=1.0f-reflectionCoords.y;
331#endif
332return reflectionCoords;}
333fn sampleRadiance(
334alphaG: f32
335,reflectionMicrosurfaceInfos: vec3f
336,reflectionInfos: vec2f
337,geoInfo: geometryInfoOutParams
338#ifdef REFLECTIONMAP_3D
339,reflectionSampler: texture_cube<f32>
340,reflectionSamplerSampler: sampler
341,reflectionCoords: vec3f
342#else
343,reflectionSampler: texture_2d<f32>
344,reflectionSamplerSampler: sampler
345,reflectionCoords: vec2f
346#endif
347#ifdef REALTIME_FILTERING
348,reflectionFilteringInfo: vec2f
349#endif
350)->vec3f {var environmentRadiance: vec4f=vec4f(0.f,0.f,0.f,0.f);
351#if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)
352var reflectionLOD: f32=getLodFromAlphaG(reflectionMicrosurfaceInfos.x,alphaG,geoInfo.NdotVUnclamped);
353#elif defined(LINEARSPECULARREFLECTION)
354var reflectionLOD: f32=getLinearLodFromRoughness(reflectionMicrosurfaceInfos.x,roughness);
355#else
356var reflectionLOD: f32=getLodFromAlphaG(reflectionMicrosurfaceInfos.x,alphaG);
357#endif
358reflectionLOD=reflectionLOD*reflectionMicrosurfaceInfos.y+reflectionMicrosurfaceInfos.z;
359#ifdef REALTIME_FILTERING
360environmentRadiance=vec4f(radiance(alphaG,reflectionSampler,reflectionSamplerSampler,reflectionCoords,reflectionFilteringInfo),1.0f);
361#else
362environmentRadiance=textureSampleLevel(reflectionSampler,reflectionSamplerSampler,reflectionCoords,reflectionLOD);
363#endif
364#ifdef RGBDREFLECTION
365environmentRadiance.rgb=fromRGBD(environmentRadiance);
366#endif
367#ifdef GAMMAREFLECTION
368environmentRadiance.rgb=toLinearSpace(environmentRadiance.rgb);
369#endif
370return environmentRadiance.rgb;}
371#if defined(ANISOTROPIC)
372fn sampleRadianceAnisotropic(
373alphaG: f32
374,reflectionMicrosurfaceInfos: vec3f
375,reflectionInfos: vec2f
376,geoInfo: geometryInfoAnisoOutParams
377,normalW: vec3f
378,viewDirectionW: vec3f
379,positionW: vec3f
380,noise: vec3f
381#ifdef REFLECTIONMAP_3D
382,reflectionSampler: texture_cube<f32>
383,reflectionSamplerSampler: sampler
384#else
385,reflectionSampler: texture_2d<f32>
386,reflectionSamplerSampler: sampler
387#endif
388#ifdef REALTIME_FILTERING
389,reflectionFilteringInfo: vec2f
390#endif
391)->vec3f {var environmentRadiance: vec4f=vec4f(0.f,0.f,0.f,0.f);let alphaT=alphaG*sqrt(2.0f/(1.0f+(1.0f-geoInfo.anisotropy)*(1.0f-geoInfo.anisotropy)));let alphaB=(1.0f-geoInfo.anisotropy)*alphaT;let modifiedAlphaG=alphaB;
392#if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)
393var reflectionLOD: f32=getLodFromAlphaG(reflectionMicrosurfaceInfos.x,modifiedAlphaG,geoInfo.NdotVUnclamped);
394#elif defined(LINEARSPECULARREFLECTION)
395var reflectionLOD: f32=getLinearLodFromRoughness(reflectionMicrosurfaceInfos.x,roughness);
396#else
397var reflectionLOD: f32=getLodFromAlphaG(reflectionMicrosurfaceInfos.x,modifiedAlphaG);
398#endif
399reflectionLOD=reflectionLOD*reflectionMicrosurfaceInfos.y+reflectionMicrosurfaceInfos.z;
400#ifdef REALTIME_FILTERING
401var view=(uniforms.reflectionMatrix*vec4f(viewDirectionW,0.0f)).xyz;var tangent=(uniforms.reflectionMatrix*vec4f(geoInfo.anisotropicTangent,0.0f)).xyz;var bitangent=(uniforms.reflectionMatrix*vec4f(geoInfo.anisotropicBitangent,0.0f)).xyz;var normal=(uniforms.reflectionMatrix*vec4f(normalW,0.0f)).xyz;
402#ifdef REFLECTIONMAP_OPPOSITEZ
403view.z*=-1.0f;tangent.z*=-1.0f;bitangent.z*=-1.0f;normal.z*=-1.0f;
404#endif
405environmentRadiance =
406vec4f(radianceAnisotropic(alphaT,alphaB,reflectionSampler,reflectionSamplerSampler,
407view,tangent,
408bitangent,normal,
409reflectionFilteringInfo,noise.xy),
4101.0f);
411#else
412const samples: i32=16;var radianceSample=vec4f(0.0);var accumulatedRadiance=vec3f(0.0);var reflectionCoords=vec3f(0.0);var sample_weight=0.0f;var total_weight=0.0f;let step=1.0f/f32(max(samples-1,1));for (var i: i32=0; i<samples; i++) {var t: f32=mix(-1.0,1.0,f32(i)*step);t+=step*2.0*noise.x;sample_weight=max(1.0-abs(t),0.001);sample_weight*=sample_weight;t*=min(4.0*alphaT*geoInfo.anisotropy,1.0);var bentNormal: vec3f;if (t<0.0) {let blend: f32=t+1.0;bentNormal=normalize(mix(-geoInfo.anisotropicTangent,normalW,blend));} else if (t>0.0) {let blend: f32=t;bentNormal=normalize(mix(normalW,geoInfo.anisotropicTangent,blend));} else {bentNormal=normalW;}
413reflectionCoords=createReflectionCoords(positionW,bentNormal);radianceSample=textureSampleLevel(reflectionSampler,reflectionSamplerSampler,reflectionCoords,reflectionLOD);
414#ifdef RGBDREFLECTION
415accumulatedRadiance+=vec3f(sample_weight)*fromRGBD(radianceSample);
416#elif defined(GAMMAREFLECTION)
417accumulatedRadiance+=vec3f(sample_weight)*toLinearSpace(radianceSample.rgb);
418#else
419accumulatedRadiance+=vec3f(sample_weight)*radianceSample.rgb;
420#endif
421total_weight+=sample_weight;}
422environmentRadiance=vec4f(accumulatedRadiance/vec3f(total_weight),1.0f);
423#endif
424environmentRadiance=vec4f(environmentRadiance.rgb*reflectionInfos.xxx,environmentRadiance.a);return environmentRadiance.rgb;}
425#endif
426fn conductorIblFresnel(reflectance: ReflectanceParams,NdotV: f32,roughness: f32,environmentBrdf: vec3f)->vec3f
427{
428#if (CONDUCTOR_SPECULAR_MODEL==CONDUCTOR_SPECULAR_MODEL_OPENPBR)
429let albedoF0: vec3f=mix(reflectance.coloredF0,pow(reflectance.coloredF0,vec3f(1.4f)),roughness);return getF82Specular(NdotV,albedoF0,reflectance.coloredF90,roughness);
430#else
431return getReflectanceFromBRDFLookup(reflectance.coloredF0,reflectance.coloredF90,environmentBrdf);
432#endif
433}
434#endif
435`;e.IncludesShadersStoreWGSL[c]||(e.IncludesShadersStoreWGSL[c]=L);const s="openpbrNormalMapFragment",O=`var uvOffset: vec2f= vec2f(0.0,0.0);
436#if defined(GEOMETRY_NORMAL) || defined(GEOMETRY_COAT_NORMAL) || defined(PARALLAX) || defined(DETAIL)
437#ifdef NORMALXYSCALE
438var normalScale: f32=1.0;
439#elif defined(GEOMETRY_NORMAL)
440var normalScale: f32=uniforms.vGeometryNormalInfos.y;
441#else
442var normalScale: f32=1.0;
443#endif
444#if defined(TANGENT) && defined(NORMAL)
445var TBN: mat3x3f=mat3x3<f32>(input.vTBN0,input.vTBN1,input.vTBN2); 
446#elif defined(GEOMETRY_NORMAL)
447var TBNUV: vec2f=select(-fragmentInputs.vGeometryNormalUV,fragmentInputs.vGeometryNormalUV,fragmentInputs.frontFacing);var TBN: mat3x3f=cotangent_frame(normalW*normalScale,input.vPositionW,TBNUV,uniforms.vTangentSpaceParams);
448#else
449var TBNUV: vec2f=select(-fragmentInputs.vDetailUV,fragmentInputs.vDetailUV,fragmentInputs.frontFacing);var TBN: mat3x3f=cotangent_frame(normalW*normalScale,input.vPositionW,TBNUV, vec2f(1.,1.));
450#endif
451#elif defined(ANISOTROPIC)
452#if defined(TANGENT) && defined(NORMAL)
453var TBN: mat3x3f=mat3x3<f32>(input.vTBN0,input.vTBN1,input.vTBN2);
454#else
455var TBNUV: vec2f=select( -fragmentInputs.vMainUV1,fragmentInputs.vMainUV1,fragmentInputs.frontFacing);var TBN: mat3x3f=cotangent_frame(normalW,input.vPositionW,TBNUV, vec2f(1.,1.));
456#endif
457#endif
458#ifdef PARALLAX
459var invTBN: mat3x3f=transposeMat3(TBN);
460#ifdef PARALLAXOCCLUSION
461#else
462#endif
463#endif
464#ifdef DETAIL
465var detailColor: vec4f=textureSample(detailSampler,detailSamplerSampler,fragmentInputs.vDetailUV+uvOffset);var detailNormalRG: vec2f=detailColor.wy*2.0-1.0;var detailNormalB: f32=sqrt(1.-saturate(dot(detailNormalRG,detailNormalRG)));var detailNormal: vec3f= vec3f(detailNormalRG,detailNormalB);
466#endif
467#ifdef GEOMETRY_COAT_NORMAL
468coatNormalW=perturbNormal(TBN,textureSample(geometryCoatNormalSampler,geometryCoatNormalSamplerSampler,fragmentInputs.vGeometryCoatNormalUV+uvOffset).xyz,uniforms.vGeometryCoatNormalInfos.y);
469#endif
470#ifdef GEOMETRY_NORMAL
471#ifdef OBJECTSPACE_NORMALMAP
472#define CUSTOM_FRAGMENT_BUMP_FRAGMENT
473normalW=normalize(textureSample(geometryNormalSampler,geometryNormalSamplerSampler,fragmentInputs.vGeometryNormalUV).xyz *2.0-1.0);normalW=normalize(mat3x3f(uniforms.normalMatrix[0].xyz,uniforms.normalMatrix[1].xyz,uniforms.normalMatrix[2].xyz)*normalW);
474#elif !defined(DETAIL)
475normalW=perturbNormal(TBN,textureSample(geometryNormalSampler,geometryNormalSamplerSampler,fragmentInputs.vGeometryNormalUV+uvOffset).xyz,uniforms.vGeometryNormalInfos.y);
476#else
477var sampledNormal: vec3f=textureSample(geometryNormalSampler,geometryNormalSamplerSampler,fragmentInputs.vGeometryNormalUV+uvOffset).xyz*2.0-1.0;
478#if DETAIL_NORMALBLENDMETHOD==0 
479detailNormal=vec3f(detailNormal.xy*uniforms.vDetailInfos.z,detailNormal.z);var blendedNormal: vec3f=normalize( vec3f(sampledNormal.xy+detailNormal.xy,sampledNormal.z*detailNormal.z));
480#elif DETAIL_NORMALBLENDMETHOD==1 
481detailNormal=vec3f(detailNormal.xy*uniforms.vDetailInfos.z,detailNormal.z);sampledNormal+= vec3f(0.0,0.0,1.0);detailNormal*= vec3f(-1.0,-1.0,1.0);var blendedNormal: vec3f=sampledNormal*dot(sampledNormal,detailNormal)/sampledNormal.z-detailNormal;
482#endif
483normalW=perturbNormalBase(TBN,blendedNormal,uniforms.vGeometryNormalInfos.y);
484#endif
485#elif defined(DETAIL)
486detailNormal=vec3f(detailNormal.xy*uniforms.vDetailInfos.z,detailNormal.z);normalW=perturbNormalBase(TBN,detailNormal,uniforms.vDetailInfos.z);
487#endif
488`;e.IncludesShadersStoreWGSL[s]||(e.IncludesShadersStoreWGSL[s]=O);const m="openpbrBlockNormalFinal",T=`#if defined(FORCENORMALFORWARD) && defined(NORMAL)
489var faceNormal: vec3f=normalize(cross(dpdx(fragmentInputs.vPositionW),dpdy(fragmentInputs.vPositionW)))*scene.vEyePosition.w;
490#if defined(TWOSIDEDLIGHTING)
491faceNormal=select(-faceNormal,faceNormal,fragmentInputs.frontFacing);
492#endif
493normalW*=sign(dot(normalW,faceNormal));coatNormalW*=sign(dot(coatNormalW,faceNormal));
494#endif
495#if defined(TWOSIDEDLIGHTING) && defined(NORMAL)
496#if defined(MIRRORED)
497normalW=select(normalW,-normalW,fragmentInputs.frontFacing);coatNormalW=select(coatNormalW,-coatNormalW,fragmentInputs.frontFacing);
498#else
499normalW=select(-normalW,normalW,fragmentInputs.frontFacing);coatNormalW=select(-coatNormalW,coatNormalW,fragmentInputs.frontFacing);
500#endif
501#endif
502`;e.IncludesShadersStoreWGSL[m]||(e.IncludesShadersStoreWGSL[m]=T);const d="openpbrBaseLayerData",b=`var base_color=vec3f(0.8);var base_metalness: f32=0.0;var base_diffuse_roughness: f32=0.0;var specular_weight: f32=1.0;var specular_roughness: f32=0.3;var specular_color: vec3f=vec3f(1.0);var specular_roughness_anisotropy: f32=0.0;var specular_ior: f32=1.5;var alpha: f32=1.0;var geometry_tangent: vec2f=vec2f(1.0,0.0);
503#ifdef BASE_WEIGHT
504let baseWeightFromTexture: vec4f=textureSample(baseWeightSampler,baseWeightSamplerSampler,fragmentInputs.vBaseWeightUV+uvOffset);
505#endif
506#ifdef BASE_COLOR
507let baseColorFromTexture: vec4f=textureSample(baseColorSampler,baseColorSamplerSampler,fragmentInputs.vBaseColorUV+uvOffset);
508#endif
509#ifdef BASE_METALNESS
510let metallicFromTexture: vec4f=textureSample(baseMetalnessSampler,baseMetalnessSamplerSampler,fragmentInputs.vBaseMetalnessUV+uvOffset);
511#endif
512#ifdef BASE_DIFFUSE_ROUGHNESS
513let baseDiffuseRoughnessFromTexture: f32=textureSample(baseDiffuseRoughnessSampler,baseDiffuseRoughnessSamplerSampler,fragmentInputs.vBaseDiffuseRoughnessUV+uvOffset).r;
514#endif
515#ifdef GEOMETRY_TANGENT
516let geometryTangentFromTexture: vec3f=textureSample(geometryTangentSampler,geometryTangentSamplerSampler,fragmentInputs.vGeometryTangentUV+uvOffset).rgb;
517#endif
518#ifdef SPECULAR_ROUGHNESS_ANISOTROPY
519let anisotropyFromTexture: f32=textureSample(specularRoughnessAnisotropySampler,specularRoughnessAnisotropySamplerSampler,fragmentInputs.vSpecularRoughnessAnisotropyUV+uvOffset).r*uniforms.vSpecularRoughnessAnisotropyInfos.y;
520#endif
521#ifdef GEOMETRY_OPACITY
522let opacityFromTexture: vec4f=textureSample(opacitySampler,opacitySamplerSampler,fragmentInputs.vOpacityUV+uvOffset);
523#endif
524#ifdef DECAL
525let decalFromTexture: vec4f=textureSample(decalSampler,decalSamplerSampler,fragmentInputs.vDecalUV+uvOffset);
526#endif
527#ifdef SPECULAR_COLOR
528let specularColorFromTexture: vec4f=textureSample(specularColorSampler,specularColorSamplerSampler,fragmentInputs.vSpecularColorUV+uvOffset);
529#endif
530#if defined(SPECULAR_WEIGHT)
531#ifdef SPECULAR_WEIGHT_IN_ALPHA
532let specularWeightFromTexture: f32=textureSample(specularWeightSampler,specularWeightSamplerSampler,fragmentInputs.vSpecularWeightUV+uvOffset).a;
533#else
534let specularWeightFromTexture: f32=textureSample(specularWeightSampler,specularWeightSamplerSampler,fragmentInputs.vSpecularWeightUV+uvOffset).r;
535#endif
536#endif
537#ifdef ANISOTROPIC
538let noise=textureSample(blueNoiseSampler,blueNoiseSamplerSampler,fragmentInputs.position.xy/256.0).xyz;
539#endif
540#if defined(ROUGHNESSSTOREINMETALMAPGREEN) && defined(BASE_METALNESS)
541let roughnessFromTexture: f32=metallicFromTexture.g;
542#elif defined(SPECULAR_ROUGHNESS)
543let roughnessFromTexture: f32=textureSample(specularRoughnessSampler,specularRoughnessSamplerSampler,fragmentInputs.vSpecularRoughnessUV+uvOffset).r;
544#endif
545base_color=uniforms.vBaseColor.rgb;
546#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)
547base_color*=uniforms.vColor.rgb;
548#endif
549#if defined(VERTEXALPHA) || defined(INSTANCESCOLOR) && defined(INSTANCES)
550alpha*=uniforms.vColor.a;
551#endif
552base_color*=vec3(uniforms.vBaseWeight);alpha=uniforms.vBaseColor.a;base_metalness=uniforms.vReflectanceInfo.x;base_diffuse_roughness=uniforms.vBaseDiffuseRoughness;specular_roughness=uniforms.vReflectanceInfo.y;specular_color=uniforms.vSpecularColor.rgb;specular_weight=uniforms.vReflectanceInfo.a;specular_ior=uniforms.vReflectanceInfo.z;specular_roughness_anisotropy=uniforms.vSpecularAnisotropy.b;geometry_tangent=uniforms.vSpecularAnisotropy.rg;
553#ifdef BASE_COLOR
554#ifdef BASE_COLOR_GAMMA
555base_color*=toLinearSpace(baseColorFromTexture.rgb);
556#else
557base_color*=baseColorFromTexture.rgb;
558#endif
559base_color*=uniforms.vBaseColorInfos.y;
560#endif
561#ifdef BASE_WEIGHT
562base_color*=baseWeightFromTexture.r;
563#endif
564#if defined(BASE_COLOR) && defined(ALPHA_FROM_BASE_COLOR_TEXTURE)
565alpha*=baseColorFromTexture.a;
566#elif defined(GEOMETRY_OPACITY)
567alpha*=opacityFromTexture.a;alpha*=uniforms.vGeometryOpacityInfos.y;
568#endif
569#ifdef ALPHATEST
570#if DEBUGMODE != 88
571if (alpha<ALPHATESTVALUE)
572discard;
573#endif
574#ifndef ALPHABLEND
575alpha=1.0;
576#endif
577#endif
578#ifdef BASE_METALNESS
579#ifdef METALLNESSSTOREINMETALMAPBLUE
580base_metalness*=metallicFromTexture.b;
581#else
582base_metalness*=metallicFromTexture.r;
583#endif
584#endif
585#ifdef BASE_DIFFUSE_ROUGHNESS
586base_diffuse_roughness*=baseDiffuseRoughnessFromTexture*uniforms.vBaseDiffuseRoughnessInfos.y;
587#endif
588#ifdef SPECULAR_COLOR
589#ifdef SPECULAR_COLOR_GAMMA
590specular_color*=toLinearSpace(specularColorFromTexture.rgb);
591#else
592specular_color*=specularColorFromTexture.rgb;
593#endif
594#endif
595#ifdef SPECULAR_WEIGHT_FROM_SPECULAR_COLOR_TEXTURE
596specular_weight*=specularColorFromTexture.a;
597#elif defined(SPECULAR_WEIGHT)
598specular_weight*=specularWeightFromTexture;
599#endif
600#if defined(SPECULAR_ROUGHNESS) || (defined(ROUGHNESSSTOREINMETALMAPGREEN) && defined(BASE_METALNESS))
601specular_roughness*=roughnessFromTexture;
602#endif
603#ifdef GEOMETRY_TANGENT
604{let tangentFromTexture: vec2f=normalize(geometryTangentFromTexture.xy*vec2f(2.0f)-vec2f(1.0f));let tangent_angle_texture: f32=atan2(tangentFromTexture.y,tangentFromTexture.x);let tangent_angle_uniform: f32=atan2(geometry_tangent.y,geometry_tangent.x);let tangent_angle: f32=tangent_angle_texture+tangent_angle_uniform;geometry_tangent=vec2f(cos(tangent_angle),sin(tangent_angle));}
605#endif
606#if defined(GEOMETRY_TANGENT) && defined(SPECULAR_ROUGHNESS_ANISOTROPY_FROM_TANGENT_TEXTURE)
607specular_roughness_anisotropy*=geometryTangentFromTexture.b;
608#elif defined(SPECULAR_ROUGHNESS_ANISOTROPY)
609specular_roughness_anisotropy*=anisotropyFromTexture;
610#endif
611#ifdef DETAIL
612let detailRoughness: f32=mix(0.5f,detailColor.b,vDetailInfos.w);let loLerp: f32=mix(0.f,specular_roughness,detailRoughness*2.f);let hiLerp: f32=mix(specular_roughness,1.f,(detailRoughness-0.5f)*2.f);specular_roughness=mix(loLerp,hiLerp,step(detailRoughness,0.5f));
613#endif
614#ifdef USE_GLTF_STYLE_ANISOTROPY
615let baseAlpha: f32=specular_roughness*specular_roughness;let roughnessT: f32=mix(baseAlpha,1.0f,specular_roughness_anisotropy*specular_roughness_anisotropy);let roughnessB: f32=baseAlpha;specular_roughness_anisotropy=1.0f-roughnessB/max(roughnessT,0.00001f);specular_roughness=sqrt(roughnessT/sqrt(2.0f/(1.0f+(1.0f-specular_roughness_anisotropy)*(1.0f-specular_roughness_anisotropy))));
616#endif
617`;e.IncludesShadersStoreWGSL[d]||(e.IncludesShadersStoreWGSL[d]=b);const u="openpbrCoatLayerData",C=`var coat_weight: f32=0.0f;var coat_color: vec3f=vec3f(1.0f);var coat_roughness: f32=0.0f;var coat_roughness_anisotropy: f32=0.0f;var coat_ior: f32=1.6f;var coat_darkening: f32=1.0f;var geometry_coat_tangent: vec2f=vec2f(1.0f,0.0f);
618#ifdef COAT_WEIGHT
619var coatWeightFromTexture: vec4f=textureSample(coatWeightSampler,coatWeightSamplerSampler,fragmentInputs.vCoatWeightUV+uvOffset);
620#endif
621#ifdef COAT_COLOR
622var coatColorFromTexture: vec4f=textureSample(coatColorSampler,coatColorSamplerSampler,fragmentInputs.vCoatColorUV+uvOffset);
623#endif
624#ifdef COAT_ROUGHNESS
625var coatRoughnessFromTexture: vec4f=textureSample(coatRoughnessSampler,coatRoughnessSamplerSampler,fragmentInputs.vCoatRoughnessUV+uvOffset);
626#endif
627#ifdef COAT_ROUGHNESS_ANISOTROPY
628var coatRoughnessAnisotropyFromTexture: f32=textureSample(coatRoughnessAnisotropySampler,coatRoughnessAnisotropySamplerSampler,fragmentInputs.vCoatRoughnessAnisotropyUV+uvOffset).r;
629#endif
630#ifdef COAT_DARKENING
631var coatDarkeningFromTexture: vec4f=textureSample(coatDarkeningSampler,coatDarkeningSamplerSampler,fragmentInputs.vCoatDarkeningUV+uvOffset);
632#endif
633#ifdef GEOMETRY_COAT_TANGENT
634var geometryCoatTangentFromTexture: vec3f=textureSample(geometryCoatTangentSampler,geometryCoatTangentSamplerSampler,fragmentInputs.vGeometryCoatTangentUV+uvOffset).rgb;
635#endif
636coat_color=uniforms.vCoatColor.rgb;coat_weight=uniforms.vCoatWeight;coat_roughness=uniforms.vCoatRoughness;coat_roughness_anisotropy=uniforms.vCoatRoughnessAnisotropy;coat_ior=uniforms.vCoatIor;coat_darkening=uniforms.vCoatDarkening;geometry_coat_tangent=uniforms.vGeometryCoatTangent.rg;
637#ifdef COAT_WEIGHT
638coat_weight*=coatWeightFromTexture.r;
639#endif
640#ifdef COAT_COLOR
641#ifdef COAT_COLOR_GAMMA
642coat_color*=toLinearSpace(coatColorFromTexture.rgb);
643#else
644coat_color*=coatColorFromTexture.rgb;
645#endif
646coat_color*=uniforms.vCoatColorInfos.y;
647#endif
648#ifdef COAT_ROUGHNESS
649coat_roughness*=coatRoughnessFromTexture.r;
650#endif
651#if defined(GEOMETRY_COAT_TANGENT) && defined(COAT_ROUGHNESS_ANISOTROPY_FROM_TANGENT_TEXTURE)
652coat_roughness_anisotropy*=geometryCoatTangentFromTexture.b;
653#elif defined(COAT_ROUGHNESS_ANISOTROPY)
654coat_roughness_anisotropy*=coatRoughnessAnisotropyFromTexture;
655#endif
656#ifdef COAT_DARKENING
657coat_darkening*=coatDarkeningFromTexture.r;
658#endif
659#ifdef GEOMETRY_COAT_TANGENT
660{let tangentFromTexture: vec2f=normalize(geometryCoatTangentFromTexture.xy*vec2f(2.0f)-vec2f(1.0f));let tangent_angle_texture: f32=atan2(tangentFromTexture.y,tangentFromTexture.x);let tangent_angle_uniform: f32=atan2(geometry_coat_tangent.y,geometry_coat_tangent.x);let tangent_angle: f32=tangent_angle_texture+tangent_angle_uniform;geometry_coat_tangent=vec2f(cos(tangent_angle),sin(tangent_angle));}
661#endif
662#ifdef USE_GLTF_STYLE_ANISOTROPY
663let coatAlpha: f32=coat_roughness*coat_roughness;let coatRoughnessT: f32=mix(coatAlpha,1.0f,coat_roughness_anisotropy*coat_roughness_anisotropy);let coatRoughnessB: f32=coatAlpha;coat_roughness_anisotropy=1.0f-coatRoughnessB/max(coatRoughnessT,0.00001f);coat_roughness=sqrt(coatRoughnessT/sqrt(2.0f/(1.0f+(1.0f-coat_roughness_anisotropy)*(1.0f-coat_roughness_anisotropy))));
664#endif
665`;e.IncludesShadersStoreWGSL[u]||(e.IncludesShadersStoreWGSL[u]=C);const p="openpbrEnvironmentLighting",F=`#ifdef REFLECTION
666var baseDiffuseEnvironmentLight: vec3f=sampleIrradiance(
667normalW
668#if defined(NORMAL) && defined(USESPHERICALINVERTEX)
669,vEnvironmentIrradiance 
670#endif
671#if (defined(USESPHERICALFROMREFLECTIONMAP) && (!defined(NORMAL) || !defined(USESPHERICALINVERTEX))) || (defined(USEIRRADIANCEMAP) && defined(REFLECTIONMAP_3D))
672,uniforms.reflectionMatrix
673#endif
674#ifdef USEIRRADIANCEMAP
675,irradianceSampler
676,irradianceSamplerSampler
677#ifdef USE_IRRADIANCE_DOMINANT_DIRECTION
678,uniforms.vReflectionDominantDirection
679#endif
680#endif
681#ifdef REALTIME_FILTERING
682,uniforms.vReflectionFilteringInfo
683#ifdef IBL_CDF_FILTERING
684,icdfSampler
685,icdfSamplerSampler
686#endif
687#endif
688,uniforms.vReflectionInfos
689,viewDirectionW
690,base_diffuse_roughness
691,base_color
692);
693#ifdef REFLECTIONMAP_3D
694var reflectionCoords: vec3f=vec3f(0.f,0.f,0.f);
695#else
696var reflectionCoords: vec2f=vec2f(0.f,0.f);
697#endif
698let specularAlphaG: f32=specular_roughness*specular_roughness;
699#ifdef ANISOTROPIC_BASE
700var baseSpecularEnvironmentLight: vec3f=sampleRadianceAnisotropic(specularAlphaG,uniforms.vReflectionMicrosurfaceInfos.rgb,uniforms.vReflectionInfos
701,baseGeoInfo
702,normalW
703,viewDirectionW
704,fragmentInputs.vPositionW
705,noise
706,reflectionSampler
707,reflectionSamplerSampler
708#ifdef REALTIME_FILTERING
709,uniforms.vReflectionFilteringInfo
710#endif
711);
712#else
713reflectionCoords=createReflectionCoords(fragmentInputs.vPositionW,normalW);var baseSpecularEnvironmentLight: vec3f=sampleRadiance(specularAlphaG,uniforms.vReflectionMicrosurfaceInfos.rgb,uniforms.vReflectionInfos
714,baseGeoInfo
715,reflectionSampler
716,reflectionSamplerSampler
717,reflectionCoords
718#ifdef REALTIME_FILTERING
719,uniforms.vReflectionFilteringInfo
720#endif
721);
722#endif
723#ifdef ANISOTROPIC_BASE
724baseSpecularEnvironmentLight=mix(baseSpecularEnvironmentLight.rgb,baseDiffuseEnvironmentLight,specularAlphaG*specularAlphaG *max(1.0f-baseGeoInfo.anisotropy,0.3f));
725#else
726baseSpecularEnvironmentLight=mix(baseSpecularEnvironmentLight.rgb,baseDiffuseEnvironmentLight,specularAlphaG);
727#endif
728var coatEnvironmentLight: vec3f=vec3f(0.f,0.f,0.f);if (coat_weight>0.0) {
729#ifdef REFLECTIONMAP_3D
730var reflectionCoords: vec3f=vec3f(0.f,0.f,0.f);
731#else
732var reflectionCoords: vec2f=vec2f(0.f,0.f);
733#endif
734reflectionCoords=createReflectionCoords(fragmentInputs.vPositionW,coatNormalW);var coatAlphaG: f32=coat_roughness*coat_roughness;
735#ifdef ANISOTROPIC_COAT
736coatEnvironmentLight=sampleRadianceAnisotropic(coatAlphaG,uniforms.vReflectionMicrosurfaceInfos.rgb,uniforms.vReflectionInfos
737,coatGeoInfo
738,coatNormalW
739,viewDirectionW
740,fragmentInputs.vPositionW
741,noise
742,reflectionSampler
743,reflectionSamplerSampler
744#ifdef REALTIME_FILTERING
745,uniforms.vReflectionFilteringInfo
746#endif
747);
748#else
749coatEnvironmentLight=sampleRadiance(coatAlphaG,uniforms.vReflectionMicrosurfaceInfos.rgb,uniforms.vReflectionInfos
750,coatGeoInfo
751,reflectionSampler
752,reflectionSamplerSampler
753,reflectionCoords
754#ifdef REALTIME_FILTERING
755,uniforms.vReflectionFilteringInfo
756#endif
757);
758#endif
759}
760let dielectricIblFresnel: f32=getReflectanceFromBRDFWithEnvLookup(vec3f(baseDielectricReflectance.F0),vec3f(baseDielectricReflectance.F90),baseGeoInfo.environmentBrdf).r;let dielectricIblColoredFresnel: vec3f=getReflectanceFromBRDFWithEnvLookup(baseDielectricReflectance.coloredF0,baseDielectricReflectance.coloredF90,baseGeoInfo.environmentBrdf);let conductorIblFresnel: vec3f=conductorIblFresnel(baseConductorReflectance,baseGeoInfo.NdotV,specular_roughness,baseGeoInfo.environmentBrdf);var coatIblFresnel: f32=0.0;if (coat_weight>0.0) {coatIblFresnel=getReflectanceFromBRDFWithEnvLookup(vec3f(coatReflectance.F0),vec3f(coatReflectance.F90),coatGeoInfo.environmentBrdf).r;}
761var slab_diffuse_ibl: vec3f=vec3f(0.,0.,0.);var slab_glossy_ibl: vec3f=vec3f(0.,0.,0.);var slab_metal_ibl: vec3f=vec3f(0.,0.,0.);var slab_coat_ibl: vec3f=vec3f(0.,0.,0.);slab_diffuse_ibl=baseDiffuseEnvironmentLight*uniforms.vLightingIntensity.z;slab_diffuse_ibl*=aoOut.ambientOcclusionColor;slab_glossy_ibl=baseSpecularEnvironmentLight*uniforms.vLightingIntensity.z;slab_metal_ibl=baseSpecularEnvironmentLight*conductorIblFresnel*uniforms.vLightingIntensity.z;var coatAbsorption=vec3f(1.0);if (coat_weight>0.0) {slab_coat_ibl=coatEnvironmentLight*uniforms.vLightingIntensity.z;let hemisphere_avg_fresnel: f32=coatReflectance.F0+0.5f*(1.0f-coatReflectance.F0);var averageReflectance: f32=(coatIblFresnel+hemisphere_avg_fresnel)*0.5f;let roughnessFactor=1.0f-coat_roughness*0.5f;averageReflectance*=roughnessFactor;var darkened_transmission: f32=(1.0f-averageReflectance)*(1.0f-averageReflectance);darkened_transmission=mix(1.0,darkened_transmission,coat_darkening);var sin2: f32=1.0f-coatGeoInfo.NdotV*coatGeoInfo.NdotV;sin2=sin2/(coat_ior*coat_ior);let cos_t: f32=sqrt(1.0f-sin2);let coatPathLength=1.0f/cos_t;let colored_transmission: vec3f=pow(coat_color,vec3f(coatPathLength));coatAbsorption=mix(vec3f(1.0f),colored_transmission*vec3f(darkened_transmission),coat_weight);}
762var slab_subsurface_ibl: vec3f=vec3f(0.,0.,0.);var slab_translucent_base_ibl: vec3f=vec3f(0.,0.,0.);var slab_fuzz_ibl: vec3f=vec3f(0.,0.,0.);slab_diffuse_ibl*=base_color.rgb;
763#define CUSTOM_FRAGMENT_BEFORE_IBLLAYERCOMPOSITION
764let material_opaque_base_ibl: vec3f=mix(slab_diffuse_ibl,slab_subsurface_ibl,subsurface_weight);let material_dielectric_base_ibl: vec3f=mix(material_opaque_base_ibl,slab_translucent_base_ibl,transmission_weight);let material_dielectric_gloss_ibl: vec3f=layer(material_dielectric_base_ibl,slab_glossy_ibl,dielectricIblFresnel,vec3f(1.0f),specular_color);let material_base_substrate_ibl: vec3f=mix(material_dielectric_gloss_ibl,slab_metal_ibl,base_metalness);let material_coated_base_ibl: vec3f=layer(material_base_substrate_ibl,slab_coat_ibl,coatIblFresnel,coatAbsorption,vec3f(1.0f));material_surface_ibl=mix(material_coated_base_ibl,slab_fuzz_ibl,fuzz_weight);
765#endif
766`;e.IncludesShadersStoreWGSL[p]||(e.IncludesShadersStoreWGSL[p]=F);const g="openpbrDirectLightingInit",D=`#ifdef LIGHT{X}
767var preInfo{X}: preLightingInfo;var preInfoCoat{X}: preLightingInfo;let lightColor{X}: vec4f=light{X}.vLightDiffuse;var shadow{X}: f32=1.0f;
768#if defined(SHADOWONLY) || defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X}) && defined(LIGHTMAPNOSPECULAR{X})
769#else
770#define CUSTOM_LIGHT{X}_COLOR 
771#ifdef SPOTLIGHT{X}
772preInfo{X}=computePointAndSpotPreLightingInfo(light{X}.vLightData,viewDirectionW,normalW,vPositionW);preInfoCoat{X}=computePointAndSpotPreLightingInfo(light{X}.vLightData,viewDirectionW,coatNormalW,vPositionW);
773#elif defined(POINTLIGHT{X})
774preInfo{X}=computePointAndSpotPreLightingInfo(light{X}.vLightData,viewDirectionW,normalW,vPositionW);preInfoCoat{X}=computePointAndSpotPreLightingInfo(light{X}.vLightData,viewDirectionW,coatNormalW,vPositionW);
775#elif defined(HEMILIGHT{X})
776preInfo{X}=computeHemisphericPreLightingInfo(light{X}.vLightData,viewDirectionW,normalW);preInfoCoat{X}=computeHemisphericPreLightingInfo(light{X}.vLightData,viewDirectionW,coatNormalW);
777#elif defined(DIRLIGHT{X})
778preInfo{X}=computeDirectionalPreLightingInfo(light{X}.vLightData,viewDirectionW,normalW);preInfoCoat{X}=computeDirectionalPreLightingInfo(light{X}.vLightData,viewDirectionW,coatNormalW);
779#elif defined(AREALIGHT{X}) && defined(AREALIGHTSUPPORTED)
780preInfo{X}=computeAreaPreLightingInfo(areaLightsLTC1Sampler,areaLightsLTC2Sampler,viewDirectionW,normalW,vPositionW,light{X}.vLightData,light{X}.vLightWidth.xyz,light{X}.vLightHeight.xyz,specular_roughness);preInfoCoat{X}=computeAreaPreLightingInfo(areaLightsLTC1Sampler,areaLightsLTC2Sampler,viewDirectionW,coatNormalW,vPositionW,light{X}.vLightData,light{X}.vLightWidth.xyz,light{X}.vLightHeight.xyz,coat_roughness);
781#endif
782preInfo{X}.NdotV=baseGeoInfo.NdotV;preInfoCoat{X}.NdotV=coatGeoInfo.NdotV;
783#ifdef SPOTLIGHT{X}
784#ifdef LIGHT_FALLOFF_GLTF{X}
785preInfo{X}.attenuation=computeDistanceLightFalloff_GLTF(preInfo{X}.lightDistanceSquared,light{X}.vLightFalloff.y);
786#ifdef IESLIGHTTEXTURE{X}
787preInfo{X}.attenuation*=computeDirectionalLightFalloff_IES(light{X}.vLightDirection.xyz,preInfo{X}.L,iesLightTexture{X});
788#else
789preInfo{X}.attenuation*=computeDirectionalLightFalloff_GLTF(light{X}.vLightDirection.xyz,preInfo{X}.L,light{X}.vLightFalloff.z,light{X}.vLightFalloff.w);
790#endif
791#elif defined(LIGHT_FALLOFF_PHYSICAL{X})
792preInfo{X}.attenuation=computeDistanceLightFalloff_Physical(preInfo{X}.lightDistanceSquared);
793#ifdef IESLIGHTTEXTURE{X}
794preInfo{X}.attenuation*=computeDirectionalLightFalloff_IES(light{X}.vLightDirection.xyz,preInfo{X}.L,iesLightTexture{X});
795#else
796preInfo{X}.attenuation*=computeDirectionalLightFalloff_Physical(light{X}.vLightDirection.xyz,preInfo{X}.L,light{X}.vLightDirection.w);
797#endif
798#elif defined(LIGHT_FALLOFF_STANDARD{X})
799preInfo{X}.attenuation=computeDistanceLightFalloff_Standard(preInfo{X}.lightOffset,light{X}.vLightFalloff.x);
800#ifdef IESLIGHTTEXTURE{X}
801preInfo{X}.attenuation*=computeDirectionalLightFalloff_IES(light{X}.vLightDirection.xyz,preInfo{X}.L,iesLightTexture{X});
802#else
803preInfo{X}.attenuation*=computeDirectionalLightFalloff_Standard(light{X}.vLightDirection.xyz,preInfo{X}.L,light{X}.vLightDirection.w,light{X}.vLightData.w);
804#endif
805#else
806preInfo{X}.attenuation=computeDistanceLightFalloff(preInfo{X}.lightOffset,preInfo{X}.lightDistanceSquared,light{X}.vLightFalloff.x,light{X}.vLightFalloff.y);
807#ifdef IESLIGHTTEXTURE{X}
808preInfo{X}.attenuation*=computeDirectionalLightFalloff_IES(light{X}.vLightDirection.xyz,preInfo{X}.L,iesLightTexture{X});
809#else
810preInfo{X}.attenuation*=computeDirectionalLightFalloff(light{X}.vLightDirection.xyz,preInfo{X}.L,light{X}.vLightDirection.w,light{X}.vLightData.w,light{X}.vLightFalloff.z,light{X}.vLightFalloff.w);
811#endif
812#endif
813#elif defined(POINTLIGHT{X})
814#ifdef LIGHT_FALLOFF_GLTF{X}
815preInfo{X}.attenuation=computeDistanceLightFalloff_GLTF(preInfo{X}.lightDistanceSquared,light{X}.vLightFalloff.y);
816#elif defined(LIGHT_FALLOFF_PHYSICAL{X})
817preInfo{X}.attenuation=computeDistanceLightFalloff_Physical(preInfo{X}.lightDistanceSquared);
818#elif defined(LIGHT_FALLOFF_STANDARD{X})
819preInfo{X}.attenuation=computeDistanceLightFalloff_Standard(preInfo{X}.lightOffset,light{X}.vLightFalloff.x);
820#else
821preInfo{X}.attenuation=computeDistanceLightFalloff(preInfo{X}.lightOffset,preInfo{X}.lightDistanceSquared,light{X}.vLightFalloff.x,light{X}.vLightFalloff.y);
822#endif
823#else
824preInfo{X}.attenuation=1.0f;
825#endif
826preInfoCoat{X}.attenuation=preInfo{X}.attenuation;
827#if defined(HEMILIGHT{X}) || defined(AREALIGHT{X})
828preInfo{X}.roughness=specular_roughness;preInfoCoat{X}.roughness=coat_roughness;
829#else
830preInfo{X}.roughness=adjustRoughnessFromLightProperties(specular_roughness,light{X}.vLightSpecular.a,preInfo{X}.lightDistance);preInfoCoat{X}.roughness=adjustRoughnessFromLightProperties(coat_roughness,light{X}.vLightSpecular.a,preInfoCoat{X}.lightDistance);
831#endif
832preInfo{X}.diffuseRoughness=base_diffuse_roughness;preInfo{X}.surfaceAlbedo=base_color.rgb;
833#endif
834#endif
835`;e.IncludesShadersStoreWGSL[g]||(e.IncludesShadersStoreWGSL[g]=D);const _="openpbrDirectLighting",M=`#ifdef LIGHT{X}
836{var slab_diffuse: vec3f=vec3f(0.f,0.f,0.f);var slab_subsurface: vec3f=vec3f(0.f,0.f,0.f);var slab_translucent: vec3f=vec3f(0.f,0.f,0.f);var slab_glossy: vec3f=vec3f(0.f,0.f,0.f);var specularFresnel: f32=0.0f;var slab_metal: vec3f=vec3f(0.f,0.f,0.f);var slab_coat: vec3f=vec3f(0.f,0.f,0.f);var coatFresnel: f32=0.0f;var slab_fuzz: vec3f=vec3f(0.f,0.f,0.f);
837#ifdef HEMILIGHT{X}
838slab_diffuse=computeHemisphericDiffuseLighting(preInfo{X},lightColor{X}.rgb,light{X}.vLightGround);
839#elif defined(AREALIGHT{X})
840slab_diffuse=computeAreaDiffuseLighting(preInfo{X},lightColor{X}.rgb);
841#else
842slab_diffuse=computeDiffuseLighting(preInfo{X},lightColor{X}.rgb);
843#endif
844#ifdef PROJECTEDLIGHTTEXTURE{X}
845slab_diffuse*=computeProjectionTextureDiffuseLighting(projectionLightTexture{X},textureProjectionMatrix{X},vPositionW);
846#endif
847numLights+=1.0f;
848#if AREALIGHT{X}
849slab_glossy=computeAreaSpecularLighting(preInfo{X},light{X}.vLightSpecular.rgb,baseConductorReflectance.F0,baseConductorReflectance.F90);
850#else
851{
852#ifdef ANISOTROPIC_BASE
853slab_glossy=computeAnisotropicSpecularLighting(preInfo{X},viewDirectionW,normalW,
854baseGeoInfo.anisotropicTangent,baseGeoInfo.anisotropicBitangent,baseGeoInfo.anisotropy,
8550.0f,lightColor{X}.rgb);
856#else
857slab_glossy=computeSpecularLighting(preInfo{X},normalW,baseDielectricReflectance.coloredF0,baseDielectricReflectance.coloredF90,specular_roughness,lightColor{X}.rgb);
858#endif
859let NdotH: f32=dot(normalW,preInfo{X}.H);specularFresnel=fresnelSchlickGGX(NdotH,baseDielectricReflectance.F0,baseDielectricReflectance.F90);}
860#endif
861#if AREALIGHT{X}
862slab_metal=computeAreaSpecularLighting(preInfo{X},light{X}.vLightSpecular.rgb,baseConductorReflectance.F0,baseConductorReflectance.F90);
863#else
864{
865#if (CONDUCTOR_SPECULAR_MODEL==CONDUCTOR_SPECULAR_MODEL_OPENPBR)
866let coloredFresnel: vec3f=specular_weight*getF82Specular(preInfo{X}.VdotH,baseConductorReflectance.coloredF0,baseConductorReflectance.coloredF90,specular_roughness);
867#else
868let coloredFresnel: vec3f=fresnelSchlickGGX(preInfo{X}.VdotH,baseConductorReflectance.coloredF0,baseConductorReflectance.coloredF90);
869#endif
870#ifdef ANISOTROPIC_BASE
871slab_metal=computeAnisotropicSpecularLighting(preInfo{X},viewDirectionW,normalW,baseGeoInfo.anisotropicTangent,baseGeoInfo.anisotropicBitangent,baseGeoInfo.anisotropy,0.0,lightColor{X}.rgb);
872#else
873slab_metal=computeSpecularLighting(preInfo{X},normalW,vec3f(baseConductorReflectance.coloredF0),coloredFresnel,specular_roughness,lightColor{X}.rgb);
874#endif
875}
876#endif
877#if AREALIGHT{X}
878slab_coat=computeAreaSpecularLighting(preInfoCoat{X},light{X}.vLightSpecular.rgb,coatReflectance.F0,coatReflectance.F90);
879#else
880{
881#ifdef ANISOTROPIC_COAT
882slab_coat=computeAnisotropicSpecularLighting(preInfoCoat{X},viewDirectionW,coatNormalW,
883coatGeoInfo.anisotropicTangent,coatGeoInfo.anisotropicBitangent,coatGeoInfo.anisotropy,0.0,
884lightColor{X}.rgb);
885#else
886slab_coat=computeSpecularLighting(preInfoCoat{X},coatNormalW,vec3f(coatReflectance.F0),vec3f(1.0f),coat_roughness,lightColor{X}.rgb);
887#endif
888let NdotH: f32=dot(coatNormalW,preInfoCoat{X}.H);coatFresnel=fresnelSchlickGGX(NdotH,coatReflectance.F0,coatReflectance.F90);}
889#endif
890var coatAbsorption=vec3f(1.0f);if (coat_weight>0.0) {let cosTheta_view: f32=max(preInfoCoat{X}.NdotV,0.001f);let cosTheta_light: f32=max(preInfoCoat{X}.NdotL,0.001f);let fresnel_view: f32=coatReflectance.F0+(1.0f-coatReflectance.F0)*pow(1.0f-cosTheta_view,5.0);let fresnel_light: f32=coatReflectance.F0+(1.0f-coatReflectance.F0)*pow(1.0f-cosTheta_light,5.0);let averageReflectance: f32=(fresnel_view+fresnel_light)*0.5;var darkened_transmission: f32=(1.0f-averageReflectance)/(1.0f+averageReflectance);darkened_transmission=mix(1.0f,darkened_transmission,coat_darkening);var sin2: f32=1.0f-coatGeoInfo.NdotV*coatGeoInfo.NdotV;sin2=sin2/(coat_ior*coat_ior);let cos_t: f32=sqrt(1.0f-sin2);let coatPathLength=1.0f/cos_t;let colored_transmission: vec3f=pow(coat_color,vec3f(coatPathLength));
890coatAbsorption=mix(vec3f(1.0f),colored_transmission*vec3f(darkened_transmission),coat_weight);}
891slab_diffuse*=base_color.rgb;let material_opaque_base: vec3f=mix(slab_diffuse,slab_subsurface,subsurface_weight);let material_dielectric_base: vec3f=mix(material_opaque_base,slab_translucent,transmission_weight);let material_dielectric_gloss: vec3f=layer(material_dielectric_base,slab_glossy,specularFresnel,vec3f(1.0),specular_color);let material_base_substrate: vec3f=mix(material_dielectric_gloss,slab_metal,base_metalness);let material_coated_base: vec3f=layer(material_base_substrate,slab_coat,coatFresnel,coatAbsorption,vec3f(1.0));material_surface_direct+=mix(material_coated_base,slab_fuzz,fuzz_weight);}
892#endif
893`;e.IncludesShadersStoreWGSL[_]||(e.IncludesShadersStoreWGSL[_]=M);const a="openpbrPixelShader",v=`#define OPENPBR_FRAGMENT_SHADER
894#define CUSTOM_FRAGMENT_BEGIN
895#include<prePassDeclaration>[SCENE_MRT_COUNT]
896#include<oitDeclaration>
897#ifndef FROMLINEARSPACE
898#define FROMLINEARSPACE
899#endif
900#include<openpbrUboDeclaration>
901#include<pbrFragmentExtraDeclaration>
902#include<lightUboDeclaration>[0..maxSimultaneousLights]
903#include<openpbrFragmentSamplersDeclaration>
904#include<imageProcessingDeclaration>
905#include<clipPlaneFragmentDeclaration>
906#include<logDepthDeclaration>
907#include<fogFragmentDeclaration>
908#include<helperFunctions>
909#include<subSurfaceScatteringFunctions>
910#include<importanceSampling>
911#include<pbrHelperFunctions>
912#include<imageProcessingFunctions>
913#include<shadowsFragmentFunctions>
914#include<harmonicsFunctions>
915#include<pbrDirectLightingSetupFunctions>
916#include<pbrDirectLightingFalloffFunctions>
917#include<pbrBRDFFunctions>
918#include<hdrFilteringFunctions>
919#include<pbrDirectLightingFunctions>
920#include<pbrIBLFunctions>
921#include<openpbrNormalMapFragmentMainFunctions>
922#include<openpbrNormalMapFragmentFunctions>
923#ifdef REFLECTION
924#include<reflectionFunction>
925#endif
926#define CUSTOM_FRAGMENT_DEFINITIONS
927#include<openpbrDielectricReflectance>
928#include<openpbrConductorReflectance>
929#include<openpbrBlockAmbientOcclusion>
930#include<openpbrGeometryInfo>
931#include<openpbrIblFunctions>
932fn layer(slab_bottom: vec3f,slab_top: vec3f,lerp_factor: f32,bottom_multiplier: vec3f,top_multiplier: vec3f)->vec3f {return mix(slab_bottom*bottom_multiplier,slab_top*top_multiplier,lerp_factor);}
933@fragment
934fn main(input: FragmentInputs)->FragmentOutputs {
935#define CUSTOM_FRAGMENT_MAIN_BEGIN
936#include<clipPlaneFragment>
937#include<pbrBlockNormalGeometric>
938var coatNormalW: vec3f=normalW;
939#include<openpbrNormalMapFragment>
940#include<openpbrBlockNormalFinal>
941#include<openpbrBaseLayerData>
942#include<openpbrCoatLayerData>
943var subsurface_weight: f32=0.0f;var transmission_weight: f32=0.0f;var fuzz_weight: f32=0.0f;
944#define CUSTOM_FRAGMENT_UPDATE_ALPHA
945#include<depthPrePass>
946#define CUSTOM_FRAGMENT_BEFORE_LIGHTS
947var aoOut: ambientOcclusionOutParams;
948#ifdef AMBIENT_OCCLUSION
949var ambientOcclusionFromTexture: vec3f=textureSample(ambientOcclusionSampler,ambientOcclusionSamplerSampler,fragmentInputs.vAmbientOcclusionUV+uvOffset).rgb;
950#endif
951aoOut=ambientOcclusionBlock(
952#ifdef AMBIENT_OCCLUSION
953ambientOcclusionFromTexture,
954uniforms.vAmbientOcclusionInfos
955#endif
956);
957#ifdef ANISOTROPIC_COAT
958let coatGeoInfo: geometryInfoAnisoOutParams=geometryInfoAniso(
959coatNormalW,viewDirectionW.xyz,coat_roughness,geometricNormalW
960,vec3f(geometry_coat_tangent.x,geometry_coat_tangent.y,coat_roughness_anisotropy),TBN
961);
962#else
963let coatGeoInfo: geometryInfoOutParams=geometryInfo(
964coatNormalW,viewDirectionW.xyz,coat_roughness,geometricNormalW
965);
966#endif
967specular_roughness=mix(specular_roughness,pow(min(1.0f,pow(specular_roughness,4.0f)+2.0f*pow(coat_roughness,4.0f)),0.25f),coat_weight);
968#ifdef ANISOTROPIC_BASE
969let baseGeoInfo: geometryInfoAnisoOutParams=geometryInfoAniso(
970normalW,viewDirectionW.xyz,specular_roughness,geometricNormalW
971,vec3f(geometry_tangent.x,geometry_tangent.y,specular_roughness_anisotropy),TBN
972);
973#else
974let baseGeoInfo: geometryInfoOutParams=geometryInfo(
975normalW,viewDirectionW.xyz,specular_roughness,geometricNormalW
976);
977#endif
978let coatReflectance: ReflectanceParams=dielectricReflectance(
979coat_ior 
980,1.0f 
981,vec3f(1.0f)
982,coat_weight
983);let baseDielectricReflectance: ReflectanceParams=dielectricReflectance(
984specular_ior 
985,mix(1.0f,coat_ior,coat_weight) 
986,specular_color
987,specular_weight
988);let baseConductorReflectance: ReflectanceParams=conductorReflectance(base_color,specular_color,specular_weight);var material_surface_ibl: vec3f=vec3f(0.f,0.f,0.f);
989#include<openpbrEnvironmentLighting>
990var material_surface_direct: vec3f=vec3f(0.f,0.f,0.f);
991#if defined(LIGHT0)
992var aggShadow: f32=0.f;var numLights: f32=0.f;
993#include<openpbrDirectLightingInit>[0..maxSimultaneousLights]
994#include<openpbrDirectLighting>[0..maxSimultaneousLights]
995#endif
996var material_surface_emission: vec3f=uniforms.vEmissionColor;
997#ifdef EMISSION_COLOR
998let emissionColorTex: vec3f=textureSample(emissionColorSampler,emissionColorSamplerSampler,uniforms.vEmissionColorUV+uvOffset).rgb;
999#ifdef EMISSION_COLOR_GAMMA
1000material_surface_emission*=toLinearSpace(emissionColorTex.rgb);
1001#else
1002material_surface_emission*=emissionColorTex.rgb;
1003#endif
1004material_surface_emission*= uniforms.vEmissionColorInfos.y;
1005#endif
1006material_surface_emission*=uniforms.vLightingIntensity.y;
1007#define CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION
1008var finalColor: vec4f=vec4f(material_surface_ibl+material_surface_direct+material_surface_emission,alpha);
1009#define CUSTOM_FRAGMENT_BEFORE_FOG
1010finalColor=max(finalColor,vec4f(0.0));
1011#include<logDepthFragment>
1012#include<fogFragment>(color,finalColor)
1013#include<pbrBlockImageProcessing>
1014#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR
1015#ifdef PREPASS
1016#include<pbrBlockPrePass>
1017#endif
1018#if !defined(PREPASS) && !defined(ORDER_INDEPENDENT_TRANSPARENCY)
1019fragmentOutputs.color=finalColor;
1020#endif
1021#include<oitFragment>
1022#if ORDER_INDEPENDENT_TRANSPARENCY
1023if (fragDepth==nearestDepth) {fragmentOutputs.frontColor=vec4f(fragmentOutputs.frontColor.rgb+finalColor.rgb*finalColor.a*alphaMultiplier,1.0-alphaMultiplier*(1.0-finalColor.a));} else {fragmentOutputs.backColor+=finalColor;}
1024#endif
1025#include<pbrDebug>
1026#define CUSTOM_FRAGMENT_MAIN_END
1027}
1028`;e.ShadersStoreWGSL[a]||(e.ShadersStoreWGSL[a]=v);const w={name:a,shader:v};export{w as openpbrPixelShaderWGSL};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.