@babylonjs/core
Version:
Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.
248 lines • 8.8 kB
JavaScript
// Do not edit.
import { ShaderStore } from "../../Engines/shaderStore.js";
const name = "pbrBlockClearcoat";
const shader = `struct clearcoatOutParams
{vec3 specularEnvironmentR0;float conservationFactor;vec3 clearCoatNormalW;vec2 clearCoatAARoughnessFactors;float clearCoatIntensity;float clearCoatRoughness;
vec3 finalClearCoatRadianceScaled;
vec3 absorption;float clearCoatNdotVRefract;vec3 clearCoatColor;float clearCoatThickness;
vec3 energyConservationFactorClearCoat;
mat3 TBNClearCoat;
vec2 clearCoatMapData;
vec4 clearCoatTintMapData;
vec4 environmentClearCoatRadiance;vec3 clearCoatEnvironmentReflectance;
float clearCoatNdotV;
};
clearcoatOutParams clearcoatBlock(
in vec3 vPositionW
,in vec3 geometricNormalW
,in vec3 viewDirectionW
,in vec2 vClearCoatParams
,in vec4 clearCoatMapRoughnessData
,in vec3 specularEnvironmentR0
,in vec2 clearCoatMapData
,in vec4 vClearCoatTintParams
,in float clearCoatColorAtDistance
,in vec4 vClearCoatRefractionParams
,in vec4 clearCoatTintMapData
,in vec2 vClearCoatBumpInfos
,in vec4 clearCoatBumpMapData
,in vec2 vClearCoatBumpUV
,in mat3 vTBN
,in vec2 vClearCoatTangentSpaceParams
,in mat4 normalMatrix
,in vec3 faceNormal
,in vec3 vReflectionMicrosurfaceInfos
,in vec2 vReflectionInfos
,in vec3 vReflectionColor
,in vec4 vLightingIntensity
,in samplerCube reflectionSampler
,in sampler2D reflectionSampler
,in samplerCube reflectionSamplerLow
,in samplerCube reflectionSamplerHigh
,in sampler2D reflectionSamplerLow
,in sampler2D reflectionSamplerHigh
,in vec2 vReflectionFilteringInfo
,in float frontFacingMultiplier
)
{clearcoatOutParams outParams;float clearCoatIntensity=vClearCoatParams.x;float clearCoatRoughness=vClearCoatParams.y;
clearCoatIntensity*=clearCoatMapData.x;
clearCoatRoughness*=clearCoatMapData.y;
outParams.clearCoatMapData=clearCoatMapData;
clearCoatRoughness*=clearCoatMapRoughnessData.y;
outParams.clearCoatIntensity=clearCoatIntensity;outParams.clearCoatRoughness=clearCoatRoughness;
vec3 clearCoatColor=vClearCoatTintParams.rgb;float clearCoatThickness=vClearCoatTintParams.a;
clearCoatColor*=toLinearSpace(clearCoatTintMapData.rgb);
clearCoatColor*=clearCoatTintMapData.rgb;
clearCoatThickness*=clearCoatTintMapData.a;
outParams.clearCoatTintMapData=clearCoatTintMapData;
outParams.clearCoatColor=computeColorAtDistanceInMedia(clearCoatColor,clearCoatColorAtDistance);outParams.clearCoatThickness=clearCoatThickness;
vec3 specularEnvironmentR0Updated=getR0RemappedForClearCoat(specularEnvironmentR0);
vec3 specularEnvironmentR0Updated=specularEnvironmentR0;
outParams.specularEnvironmentR0=mix(specularEnvironmentR0,specularEnvironmentR0Updated,clearCoatIntensity);vec3 clearCoatNormalW=geometricNormalW;
float clearCoatNormalScale=1.0;
float clearCoatNormalScale=vClearCoatBumpInfos.y;
mat3 TBNClearCoat=vTBN;
vec2 TBNClearCoatUV=vClearCoatBumpUV*frontFacingMultiplier;mat3 TBNClearCoat=cotangent_frame(clearCoatNormalW*clearCoatNormalScale,vPositionW,TBNClearCoatUV,vClearCoatTangentSpaceParams);
outParams.TBNClearCoat=TBNClearCoat;
clearCoatNormalW=normalize(clearCoatBumpMapData.xyz *2.0-1.0);clearCoatNormalW=normalize(mat3(normalMatrix)*clearCoatNormalW);
clearCoatNormalW=perturbNormal(TBNClearCoat,clearCoatBumpMapData.xyz,vClearCoatBumpInfos.y);
clearCoatNormalW*=sign(dot(clearCoatNormalW,faceNormal));
clearCoatNormalW=clearCoatNormalW*frontFacingMultiplier;
outParams.clearCoatNormalW=clearCoatNormalW;outParams.clearCoatAARoughnessFactors=getAARoughnessFactors(clearCoatNormalW.xyz);float clearCoatNdotVUnclamped=dot(clearCoatNormalW,viewDirectionW);float clearCoatNdotV=absEps(clearCoatNdotVUnclamped);
outParams.clearCoatNdotV=clearCoatNdotV;
vec3 clearCoatVRefract=refract(-viewDirectionW,clearCoatNormalW,vClearCoatRefractionParams.y);outParams.clearCoatNdotVRefract=absEps(dot(clearCoatNormalW,clearCoatVRefract));
vec3 environmentClearCoatBrdf=getBRDFLookup(clearCoatNdotV,clearCoatRoughness);
float clearCoatAlphaG=convertRoughnessToAverageSlope(clearCoatRoughness);
clearCoatAlphaG+=outParams.clearCoatAARoughnessFactors.y;
vec4 environmentClearCoatRadiance=vec4(0.,0.,0.,0.);vec3 clearCoatReflectionVector=computeReflectionCoords(vec4(vPositionW,1.0),clearCoatNormalW);
clearCoatReflectionVector.z*=-1.0;
vec3 clearCoatReflectionCoords=clearCoatReflectionVector;
vec2 clearCoatReflectionCoords=clearCoatReflectionVector.xy;
clearCoatReflectionCoords/=clearCoatReflectionVector.z;
clearCoatReflectionCoords.y=1.0-clearCoatReflectionCoords.y;
sampleReflectionTexture(
clearCoatAlphaG,
vReflectionMicrosurfaceInfos,
vReflectionInfos,
vReflectionColor,
clearCoatNdotVUnclamped,
clearCoatRoughness,
reflectionSampler,
clearCoatReflectionCoords,
reflectionSamplerLow,
reflectionSamplerHigh,
vReflectionFilteringInfo,
environmentClearCoatRadiance
);
outParams.environmentClearCoatRadiance=environmentClearCoatRadiance;
vec3 clearCoatEnvironmentReflectance=getReflectanceFromBRDFLookup(vec3(vClearCoatRefractionParams.x),environmentClearCoatBrdf);
float clearCoatEho=environmentHorizonOcclusion(-viewDirectionW,clearCoatNormalW,geometricNormalW);clearCoatEnvironmentReflectance*=clearCoatEho;
vec3 clearCoatEnvironmentReflectance=getReflectanceFromAnalyticalBRDFLookup_Jones(clearCoatNdotV,vec3(1.),vec3(1.),sqrt(1.-clearCoatRoughness));
clearCoatEnvironmentReflectance*=clearCoatIntensity;
outParams.clearCoatEnvironmentReflectance=clearCoatEnvironmentReflectance;
outParams.finalClearCoatRadianceScaled=
environmentClearCoatRadiance.rgb *
clearCoatEnvironmentReflectance *
vLightingIntensity.z;
outParams.absorption=computeClearCoatAbsorption(outParams.clearCoatNdotVRefract,outParams.clearCoatNdotVRefract,outParams.clearCoatColor,clearCoatThickness,clearCoatIntensity);
float fresnelIBLClearCoat=fresnelSchlickGGX(clearCoatNdotV,vClearCoatRefractionParams.x,CLEARCOATREFLECTANCE90);fresnelIBLClearCoat*=clearCoatIntensity;outParams.conservationFactor=(1.-fresnelIBLClearCoat);
outParams.energyConservationFactorClearCoat=getEnergyConservationFactor(outParams.specularEnvironmentR0,environmentClearCoatBrdf);
return outParams;}
`;
// Sideeffect
if (!ShaderStore.IncludesShadersStore[name]) {
ShaderStore.IncludesShadersStore[name] = shader;
}
/** @internal */
export const pbrBlockClearcoat = { name, shader };
//# sourceMappingURL=pbrBlockClearcoat.js.map