@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.
651 lines • 23.1 kB
JavaScript
// Do not edit.
import { ShaderStore } from "../Engines/shaderStore.js";
import { prePassDeclaration } from "./ShadersInclude/prePassDeclaration.js";
import { oitDeclaration } from "./ShadersInclude/oitDeclaration.js";
import { decalFragmentDeclaration } from "./ShadersInclude/decalFragmentDeclaration.js";
import { pbrFragmentDeclaration } from "./ShadersInclude/pbrFragmentDeclaration.js";
import { sceneUboDeclaration } from "./ShadersInclude/sceneUboDeclaration.js";
import { meshUboDeclaration } from "./ShadersInclude/meshUboDeclaration.js";
import { pbrUboDeclaration } from "./ShadersInclude/pbrUboDeclaration.js";
import { mainUVVaryingDeclaration } from "./ShadersInclude/mainUVVaryingDeclaration.js";
import { pbrFragmentExtraDeclaration } from "./ShadersInclude/pbrFragmentExtraDeclaration.js";
import { lightFragmentDeclaration } from "./ShadersInclude/lightFragmentDeclaration.js";
import { lightUboDeclaration } from "./ShadersInclude/lightUboDeclaration.js";
import { samplerFragmentDeclaration } from "./ShadersInclude/samplerFragmentDeclaration.js";
import { samplerFragmentAlternateDeclaration } from "./ShadersInclude/samplerFragmentAlternateDeclaration.js";
import { pbrFragmentReflectionDeclaration } from "./ShadersInclude/pbrFragmentReflectionDeclaration.js";
import { pbrFragmentSamplersDeclaration } from "./ShadersInclude/pbrFragmentSamplersDeclaration.js";
import { imageProcessingDeclaration } from "./ShadersInclude/imageProcessingDeclaration.js";
import { clipPlaneFragmentDeclaration } from "./ShadersInclude/clipPlaneFragmentDeclaration.js";
import { logDepthDeclaration } from "./ShadersInclude/logDepthDeclaration.js";
import { fogFragmentDeclaration } from "./ShadersInclude/fogFragmentDeclaration.js";
import { textureRepetitionFunctions } from "./ShadersInclude/textureRepetitionFunctions.js";
import { helperFunctions } from "./ShadersInclude/helperFunctions.js";
import { subSurfaceScatteringFunctions } from "./ShadersInclude/subSurfaceScatteringFunctions.js";
import { importanceSampling } from "./ShadersInclude/importanceSampling.js";
import { pbrHelperFunctions } from "./ShadersInclude/pbrHelperFunctions.js";
import { imageProcessingFunctions } from "./ShadersInclude/imageProcessingFunctions.js";
import { shadowsFragmentFunctions } from "./ShadersInclude/shadowsFragmentFunctions.js";
import { harmonicsFunctions } from "./ShadersInclude/harmonicsFunctions.js";
import { ltcHelperFunctions } from "./ShadersInclude/ltcHelperFunctions.js";
import { pbrDirectLightingSetupFunctions } from "./ShadersInclude/pbrDirectLightingSetupFunctions.js";
import { pbrDirectLightingFalloffFunctions } from "./ShadersInclude/pbrDirectLightingFalloffFunctions.js";
import { pbrBRDFFunctions } from "./ShadersInclude/pbrBRDFFunctions.js";
import { hdrFilteringFunctions } from "./ShadersInclude/hdrFilteringFunctions.js";
import { pbrDirectLightingFunctions } from "./ShadersInclude/pbrDirectLightingFunctions.js";
import { pbrIBLFunctions } from "./ShadersInclude/pbrIBLFunctions.js";
import { bumpFragmentMainFunctions } from "./ShadersInclude/bumpFragmentMainFunctions.js";
import { bumpFragmentFunctions } from "./ShadersInclude/bumpFragmentFunctions.js";
import { reflectionFunction } from "./ShadersInclude/reflectionFunction.js";
import { decalFragment } from "./ShadersInclude/decalFragment.js";
import { pbrBlockAlbedoOpacity } from "./ShadersInclude/pbrBlockAlbedoOpacity.js";
import { pbrBlockReflectivity } from "./ShadersInclude/pbrBlockReflectivity.js";
import { pbrBlockAmbientOcclusion } from "./ShadersInclude/pbrBlockAmbientOcclusion.js";
import { pbrBlockAlphaFresnel } from "./ShadersInclude/pbrBlockAlphaFresnel.js";
import { pbrBlockAnisotropic } from "./ShadersInclude/pbrBlockAnisotropic.js";
import { pbrBlockReflection } from "./ShadersInclude/pbrBlockReflection.js";
import { pbrBlockSheen } from "./ShadersInclude/pbrBlockSheen.js";
import { pbrBlockClearcoat } from "./ShadersInclude/pbrBlockClearcoat.js";
import { pbrBlockIridescence } from "./ShadersInclude/pbrBlockIridescence.js";
import { pbrBlockSubSurface } from "./ShadersInclude/pbrBlockSubSurface.js";
import { clusteredLightingFunctions } from "./ShadersInclude/clusteredLightingFunctions.js";
import { pbrBlockReflectance0 } from "./ShadersInclude/pbrBlockReflectance0.js";
import { pbrClusteredLightingFunctions } from "./ShadersInclude/pbrClusteredLightingFunctions.js";
import { clipPlaneFragment } from "./ShadersInclude/clipPlaneFragment.js";
import { pbrBlockNormalGeometric } from "./ShadersInclude/pbrBlockNormalGeometric.js";
import { bumpFragment } from "./ShadersInclude/bumpFragment.js";
import { pbrBlockNormalFinal } from "./ShadersInclude/pbrBlockNormalFinal.js";
import { depthPrePass } from "./ShadersInclude/depthPrePass.js";
import { pbrBlockLightmapInit } from "./ShadersInclude/pbrBlockLightmapInit.js";
import { pbrBlockGeometryInfo } from "./ShadersInclude/pbrBlockGeometryInfo.js";
import { pbrBlockReflectance } from "./ShadersInclude/pbrBlockReflectance.js";
import { pbrBlockDirectLighting } from "./ShadersInclude/pbrBlockDirectLighting.js";
import { lightFragment } from "./ShadersInclude/lightFragment.js";
import { pbrBlockFinalLitComponents } from "./ShadersInclude/pbrBlockFinalLitComponents.js";
import { pbrBlockFinalUnlitComponents } from "./ShadersInclude/pbrBlockFinalUnlitComponents.js";
import { pbrBlockFinalColorComposition } from "./ShadersInclude/pbrBlockFinalColorComposition.js";
import { logDepthFragment } from "./ShadersInclude/logDepthFragment.js";
import { fogFragment } from "./ShadersInclude/fogFragment.js";
import { pbrBlockImageProcessing } from "./ShadersInclude/pbrBlockImageProcessing.js";
import { pbrBlockPrePass } from "./ShadersInclude/pbrBlockPrePass.js";
import { oitFragment } from "./ShadersInclude/oitFragment.js";
import { pbrDebug } from "./ShadersInclude/pbrDebug.js";
const name = "pbrPixelShader";
const shader = `
precision highp float;
void main(void) {
albedoOpacityOutParams albedoOpacityOut;
vec4 albedoTexture=TEXRD(albedoSampler,vAlbedoUV+uvOffset);
vec4 baseWeightTexture=TEXRD(baseWeightSampler,vBaseWeightUV+uvOffset);
vec4 opacityMap=TEXRD(opacitySampler,vOpacityUV+uvOffset);
vec4 decalColor=texture2D(decalSampler,vDecalUV+uvOffset);
albedoOpacityOut=albedoOpacityBlock(
vAlbedoColor
,albedoTexture
,vAlbedoInfos
,baseWeight
,baseWeightTexture
,vBaseWeightInfos
,opacityMap
,vOpacityInfos
,detailColor
,vDetailInfos
,decalColor
,vDecalInfos
);vec3 surfaceAlbedo=albedoOpacityOut.surfaceAlbedo;float alpha=albedoOpacityOut.alpha;
ambientOcclusionOutParams aoOut;
vec3 ambientOcclusionColorMap=TEXRD(ambientSampler,vAmbientUV+uvOffset).rgb;
aoOut=ambientOcclusionBlock(
ambientOcclusionColorMap,
vAmbientInfos
);
vec3 diffuseBase=vec3(1.,1.,1.);
vec3 baseColor=surfaceAlbedo;reflectivityOutParams reflectivityOut;
vec4 surfaceMetallicOrReflectivityColorMap=TEXRD(reflectivitySampler,vReflectivityUV+uvOffset);vec4 baseReflectivity=surfaceMetallicOrReflectivityColorMap;
surfaceMetallicOrReflectivityColorMap=toLinearSpace(surfaceMetallicOrReflectivityColorMap);
surfaceMetallicOrReflectivityColorMap.rgb*=vReflectivityInfos.y;
vec4 microSurfaceTexel=TEXRD(microSurfaceSampler,vMicroSurfaceSamplerUV+uvOffset)*vMicroSurfaceSamplerInfos.y;
vec4 metallicReflectanceFactors=vMetallicReflectanceFactors;
vec4 reflectanceFactorsMap=TEXRD(reflectanceSampler,vReflectanceUV+uvOffset);
reflectanceFactorsMap=toLinearSpace(reflectanceFactorsMap);
metallicReflectanceFactors.rgb*=reflectanceFactorsMap.rgb;
vec4 metallicReflectanceFactorsMap=TEXRD(metallicReflectanceSampler,vMetallicReflectanceUV+uvOffset);
metallicReflectanceFactorsMap=toLinearSpace(metallicReflectanceFactorsMap);
metallicReflectanceFactors.rgb*=metallicReflectanceFactorsMap.rgb;
metallicReflectanceFactors.a*=metallicReflectanceFactorsMap.a;
float baseDiffuseRoughnessTexture=TEXRD(baseDiffuseRoughnessSampler,vBaseDiffuseRoughnessUV+uvOffset).r;
reflectivityOut=reflectivityBlock(
vReflectivityColor
,surfaceAlbedo
,metallicReflectanceFactors
,baseDiffuseRoughness
,baseDiffuseRoughnessTexture
,vBaseDiffuseRoughnessInfos
,vReflectivityInfos
,surfaceMetallicOrReflectivityColorMap
,aoOut.ambientOcclusionColor
,microSurfaceTexel
,detailColor
,vDetailInfos
);float microSurface=reflectivityOut.microSurface;float roughness=reflectivityOut.roughness;float diffuseRoughness=reflectivityOut.diffuseRoughness;
surfaceAlbedo=reflectivityOut.surfaceAlbedo;
aoOut.ambientOcclusionColor=reflectivityOut.ambientOcclusionColor;
alphaFresnelOutParams alphaFresnelOut;alphaFresnelOut=alphaFresnelBlock(
normalW,
viewDirectionW,
alpha,
microSurface
);alpha=alphaFresnelOut.alpha;
anisotropicOutParams anisotropicOut;
vec3 anisotropyMapData=TEXRD(anisotropySampler,vAnisotropyUV+uvOffset).rgb*vAnisotropyInfos.y;
anisotropicOut=anisotropicBlock(
vAnisotropy,
roughness,
anisotropyMapData,
TBN,
normalW,
viewDirectionW
);
reflectionOutParams reflectionOut;
reflectionOut=reflectionBlock(
vPositionW
,normalW
,alphaG
,vReflectionMicrosurfaceInfos
,vReflectionInfos
,vReflectionColor
,anisotropicOut
,NdotVUnclamped
,roughness
,reflectionSampler
,vEnvironmentIrradiance
,reflectionMatrix
,irradianceSampler
,vReflectionDominantDirection
,reflectionSamplerLow
,reflectionSamplerHigh
,vReflectionFilteringInfo
,icdfSampler
,viewDirectionW
,diffuseRoughness
,baseColor
);
sheenOutParams sheenOut;
vec4 sheenMapData=TEXRD(sheenSampler,vSheenUV+uvOffset);
vec4 sheenMapRoughnessData=TEXRD(sheenRoughnessSampler,vSheenRoughnessUV+uvOffset)*vSheenInfos.w;
sheenOut=sheenBlock(
vSheenColor
,vSheenRoughness
,sheenMapRoughnessData
,roughness
,sheenMapData
,vSheenInfos.y
,reflectanceF0
,baseColor
,surfaceAlbedo
,NdotV
,environmentBrdf
,AARoughnessFactors
,vReflectionMicrosurfaceInfos
,vReflectionInfos
,vReflectionColor
,vLightingIntensity
,reflectionSampler
,reflectionOut.reflectionCoords
,NdotVUnclamped
,reflectionSamplerLow
,reflectionSamplerHigh
,vReflectionFilteringInfo
,seo
,eho
);
surfaceAlbedo=sheenOut.surfaceAlbedo;
vec2 clearCoatMapData=TEXRD(clearCoatSampler,vClearCoatUV+uvOffset).rg*vClearCoatInfos.y;
iridescenceOutParams iridescenceOut;
vec2 iridescenceMapData=TEXRD(iridescenceSampler,vIridescenceUV+uvOffset).rg*vIridescenceInfos.y;
vec2 iridescenceThicknessMapData=TEXRD(iridescenceThicknessSampler,vIridescenceThicknessUV+uvOffset).rg*vIridescenceInfos.w;
iridescenceOut=iridescenceBlock(
vIridescenceParams
,NdotV
,specularEnvironmentR0
,iridescenceMapData
,iridescenceThicknessMapData
,NdotVUnclamped
,vClearCoatParams
,clearCoatMapData
);float iridescenceIntensity=iridescenceOut.iridescenceIntensity;specularEnvironmentR0=iridescenceOut.specularEnvironmentR0;
clearcoatOutParams clearcoatOut;
vec4 clearCoatMapRoughnessData=TEXRD(clearCoatRoughnessSampler,vClearCoatRoughnessUV+uvOffset)*vClearCoatInfos.w;
vec4 clearCoatTintMapData=TEXRD(clearCoatTintSampler,vClearCoatTintUV+uvOffset);
vec4 clearCoatBumpMapData=TEXRD(clearCoatBumpSampler,vClearCoatBumpUV+uvOffset);
clearcoatOut=clearcoatBlock(
vPositionW
,geometricNormalW
,viewDirectionW
,vClearCoatParams
,clearCoatMapRoughnessData
,specularEnvironmentR0
,clearCoatMapData
,vClearCoatTintParams
,clearCoatColorAtDistance
,vClearCoatRefractionParams
,clearCoatTintMapData
,vClearCoatBumpInfos
,clearCoatBumpMapData
,vClearCoatBumpUV
,vTBN
,vClearCoatTangentSpaceParams
,normalMatrix
,faceNormal
,vReflectionMicrosurfaceInfos
,vReflectionInfos
,vReflectionColor
,vLightingIntensity
,reflectionSampler
,reflectionSamplerLow
,reflectionSamplerHigh
,vReflectionFilteringInfo
,(gl_FrontFacing ? 1. : -1.)
);
clearcoatOut.specularEnvironmentR0=specularEnvironmentR0;
subSurfaceOutParams subSurfaceOut;
vec4 thicknessMap=TEXRD(thicknessSampler,vThicknessUV+uvOffset);
vec4 refractionIntensityMap=TEXRD(refractionIntensitySampler,vRefractionIntensityUV+uvOffset);
vec4 translucencyIntensityMap=TEXRD(translucencyIntensitySampler,vTranslucencyIntensityUV+uvOffset);
vec4 translucencyColorMap=TEXRD(translucencyColorSampler,vTranslucencyColorUV+uvOffset);
translucencyColorMap=toLinearSpace(translucencyColorMap);
vec3 vSpecularEnvironmentReflectance=vec3(max(colorSpecularEnvironmentReflectance.r,max(colorSpecularEnvironmentReflectance.g,colorSpecularEnvironmentReflectance.b)));
subSurfaceOut=subSurfaceBlock(
vSubSurfaceIntensity
,vThicknessParam
,vTintColor
,normalW
,vSpecularEnvironmentReflectance
,baseSpecularEnvironmentReflectance
,thicknessMap
,refractionIntensityMap
,translucencyIntensityMap
,reflectionMatrix
,reflectionOut.irradianceVector
,reflectionSampler
,vReflectionFilteringInfo
,icdfSampler
,irradianceSampler
,surfaceAlbedo
,vPositionW
,viewDirectionW
,view
,vRefractionInfos
,refractionMatrix
,vRefractionMicrosurfaceInfos
,vLightingIntensity
,alpha
,NdotVUnclamped
,roughness
,alphaG
,refractionSampler
,refractionSamplerLow
,refractionSamplerHigh
,anisotropicOut
,vRefractionFilteringInfo
,vRefractionPosition
,vRefractionSize
,dispersion
,vDiffusionDistance
,vTranslucencyColor
,translucencyColorMap
);
surfaceAlbedo=subSurfaceOut.surfaceAlbedo;
alpha=subSurfaceOut.alpha;
subSurfaceOut.specularEnvironmentReflectance=colorSpecularEnvironmentReflectance;
gl_FragColor=finalColor;
if (fragDepth==nearestDepth) {frontColor.rgb+=finalColor.rgb*finalColor.a*alphaMultiplier;frontColor.a=1.0-alphaMultiplier*(1.0-finalColor.a);} else {backColor+=finalColor;}
}
`;
// Sideeffect
if (!ShaderStore.ShadersStore[name]) {
ShaderStore.ShadersStore[name] = shader;
}
const includes = [prePassDeclaration, oitDeclaration, decalFragmentDeclaration, pbrFragmentDeclaration, sceneUboDeclaration, meshUboDeclaration, pbrUboDeclaration, mainUVVaryingDeclaration, pbrFragmentExtraDeclaration, lightFragmentDeclaration, lightUboDeclaration, samplerFragmentDeclaration, samplerFragmentAlternateDeclaration, pbrFragmentReflectionDeclaration, pbrFragmentSamplersDeclaration, imageProcessingDeclaration, clipPlaneFragmentDeclaration, logDepthDeclaration, fogFragmentDeclaration, textureRepetitionFunctions, helperFunctions, subSurfaceScatteringFunctions, importanceSampling, pbrHelperFunctions, imageProcessingFunctions, shadowsFragmentFunctions, harmonicsFunctions, ltcHelperFunctions, pbrDirectLightingSetupFunctions, pbrDirectLightingFalloffFunctions, pbrBRDFFunctions, hdrFilteringFunctions, pbrDirectLightingFunctions, pbrIBLFunctions, bumpFragmentMainFunctions, bumpFragmentFunctions, reflectionFunction, decalFragment, pbrBlockAlbedoOpacity, pbrBlockReflectivity, pbrBlockAmbientOcclusion, pbrBlockAlphaFresnel, pbrBlockAnisotropic, pbrBlockReflection, pbrBlockSheen, pbrBlockClearcoat, pbrBlockIridescence, pbrBlockSubSurface, clusteredLightingFunctions, pbrBlockReflectance0, pbrClusteredLightingFunctions, clipPlaneFragment, pbrBlockNormalGeometric, bumpFragment, pbrBlockNormalFinal, depthPrePass, pbrBlockLightmapInit, pbrBlockGeometryInfo, pbrBlockReflectance, pbrBlockDirectLighting, lightFragment, pbrBlockFinalLitComponents, pbrBlockFinalUnlitComponents, pbrBlockFinalColorComposition, logDepthFragment, fogFragment, pbrBlockImageProcessing, pbrBlockPrePass, oitFragment, pbrDebug];
for (const inc of includes) {
if (!ShaderStore.IncludesShadersStore[inc.name]) {
ShaderStore.IncludesShadersStore[inc.name] = inc.shader;
}
}
/** @internal */
export const pbrPixelShader = { name, shader };
//# sourceMappingURL=pbr.fragment.js.map