@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.
385 lines • 14.7 kB
JavaScript
// Do not edit.
import { ShaderStore } from "../Engines/shaderStore.js";
import "./ShadersInclude/defaultFragmentDeclaration.js";
import "./ShadersInclude/defaultUboDeclaration.js";
import "./ShadersInclude/prePassDeclaration.js";
import "./ShadersInclude/oitDeclaration.js";
import "./ShadersInclude/mainUVVaryingDeclaration.js";
import "./ShadersInclude/helperFunctions.js";
import "./ShadersInclude/lightFragmentDeclaration.js";
import "./ShadersInclude/lightUboDeclaration.js";
import "./ShadersInclude/lightsFragmentFunctions.js";
import "./ShadersInclude/shadowsFragmentFunctions.js";
import "./ShadersInclude/samplerFragmentDeclaration.js";
import "./ShadersInclude/fresnelFunction.js";
import "./ShadersInclude/reflectionFunction.js";
import "./ShadersInclude/imageProcessingDeclaration.js";
import "./ShadersInclude/imageProcessingFunctions.js";
import "./ShadersInclude/bumpFragmentMainFunctions.js";
import "./ShadersInclude/bumpFragmentFunctions.js";
import "./ShadersInclude/clipPlaneFragmentDeclaration.js";
import "./ShadersInclude/logDepthDeclaration.js";
import "./ShadersInclude/fogFragmentDeclaration.js";
import "./ShadersInclude/clipPlaneFragment.js";
import "./ShadersInclude/bumpFragment.js";
import "./ShadersInclude/decalFragment.js";
import "./ShadersInclude/depthPrePass.js";
import "./ShadersInclude/lightFragment.js";
import "./ShadersInclude/logDepthFragment.js";
import "./ShadersInclude/fogFragment.js";
import "./ShadersInclude/oitFragment.js";
const name = "defaultPixelShader";
const shader = `
varying vec3 vPositionW;
varying vec3 vNormalW;
varying vec4 vColor;
uniform samplerCube refractionCubeSampler;
uniform sampler2D refraction2DSampler;
uniform samplerCube reflectionCubeSampler;
uniform sampler2D reflection2DSampler;
varying vec3 vPositionUVW;
varying vec3 vDirectionW;
void main(void) {
vec3 viewDirectionW=normalize(vEyePosition.xyz-vPositionW);vec4 baseColor=vec4(1.,1.,1.,1.);vec3 diffuseColor=vDiffuseColor.rgb;float alpha=vDiffuseColor.a;
vec3 normalW=normalize(vNormalW);
vec3 normalW=normalize(-cross(dFdx(vPositionW),dFdy(vPositionW)));
normalW=gl_FrontFacing ? normalW : -normalW;
baseColor=texture2D(diffuseSampler,vDiffuseUV+uvOffset);
if (baseColor.a<alphaCutOff)
discard;
alpha*=baseColor.a;
baseColor.rgb*=vDiffuseInfos.y;
vec4 decalColor=texture2D(decalSampler,vDecalUV+uvOffset);
baseColor.rgb*=vColor.rgb;
baseColor.rgb=baseColor.rgb*2.0*mix(0.5,detailColor.r,vDetailInfos.y);
vec4 decalColor=texture2D(decalSampler,vDecalUV+uvOffset);
vec3 baseAmbientColor=vec3(1.,1.,1.);
baseAmbientColor=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;
float glossiness=vSpecularColor.a;vec3 specularColor=vSpecularColor.rgb;
vec4 specularMapColor=texture2D(specularSampler,vSpecularUV+uvOffset);specularColor=specularMapColor.rgb;
glossiness=glossiness*specularMapColor.a;
vec3 diffuseBase=vec3(0.,0.,0.);lightingInfo info;
vec3 specularBase=vec3(0.,0.,0.);
float shadow=1.;float aggShadow=0.;float numLights=0.;
vec4 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset);
lightmapColor.rgb=fromRGBD(lightmapColor);
lightmapColor.rgb*=vLightmapInfos.y;
aggShadow=aggShadow/numLights;vec4 refractionColor=vec4(0.,0.,0.,1.);
vec3 refractionVector=normalize(refract(-viewDirectionW,normalW,vRefractionInfos.y));
refractionVector=parallaxCorrectNormal(vPositionW,refractionVector,vRefractionSize,vRefractionPosition);
refractionVector.y=refractionVector.y*vRefractionInfos.w;vec4 refractionLookup=textureCube(refractionCubeSampler,refractionVector);if (dot(refractionVector,viewDirectionW)<1.0) {refractionColor=refractionLookup;}
vec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));vec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;refractionCoords.y=1.0-refractionCoords.y;refractionColor=texture2D(refraction2DSampler,refractionCoords);
refractionColor.rgb=fromRGBD(refractionColor);
refractionColor.rgb=toGammaSpace(refractionColor.rgb);
refractionColor.rgb*=vRefractionInfos.x;
vec4 reflectionColor=vec4(0.,0.,0.,1.);
vec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);
vReflectionUVW.z*=-1.0;
float bias=vReflectionInfos.y;
bias*=(1.0-specularMapColor.a);
reflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW,bias);
reflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW);
vec2 coords=vReflectionUVW.xy;
coords/=vReflectionUVW.z;
coords.y=1.0-coords.y;reflectionColor=texture2D(reflection2DSampler,coords);
reflectionColor.rgb=fromRGBD(reflectionColor);
reflectionColor.rgb=toGammaSpace(reflectionColor.rgb);
reflectionColor.rgb*=vReflectionInfos.x;
float reflectionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,reflectionRightColor.a,reflectionLeftColor.a);
reflectionColor.rgb*=specularColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;
reflectionColor.rgb*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;
reflectionColor.rgb*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;
float refractionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,refractionRightColor.a,refractionLeftColor.a);refractionColor.rgb*=refractionLeftColor.rgb*(1.0-refractionFresnelTerm)+refractionFresnelTerm*refractionRightColor.rgb;
vec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);
opacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);alpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;
alpha*=opacityMap.a*vOpacityInfos.y;
alpha*=vColor.a;
float opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);alpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;
if (alpha<alphaCutOff)
discard;
alpha=1.0;
vec3 emissiveColor=vEmissiveColor;
emissiveColor+=texture2D(emissiveSampler,vEmissiveUV+uvOffset).rgb*vEmissiveInfos.y;
float emissiveFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,emissiveRightColor.a,emissiveLeftColor.a);emissiveColor*=emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*emissiveRightColor.rgb;
float diffuseFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,diffuseRightColor.a,diffuseLeftColor.a);diffuseBase*=diffuseLeftColor.rgb*(1.0-diffuseFresnelTerm)+diffuseFresnelTerm*diffuseRightColor.rgb;
vec3 finalDiffuse=clamp(diffuseBase*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;
vec3 finalDiffuse=clamp((diffuseBase+emissiveColor)*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;
vec3 finalDiffuse=clamp(diffuseBase*diffuseColor+emissiveColor+vAmbientColor,0.0,1.0)*baseColor.rgb;
vec3 finalSpecular=specularBase*specularColor;
alpha=clamp(alpha+dot(finalSpecular,vec3(0.3,0.59,0.11)),0.,1.);
vec3 finalSpecular=vec3(0.0);
alpha=clamp(alpha+dot(reflectionColor.rgb,vec3(0.3,0.59,0.11)),0.,1.);
vec4 color=vec4(clamp(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor.rgb+emissiveColor+refractionColor.rgb,0.0,1.0),alpha);
vec4 color=vec4(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor.rgb+refractionColor.rgb,alpha);
color.rgb*=lightmapColor.rgb;
color.rgb+=lightmapColor.rgb;
color.rgb=max(color.rgb,0.);
color.rgb=toLinearSpace(color.rgb);
color.rgb=toLinearSpace(color.rgb);color=applyImageProcessing(color);
color.a*=visibility;
color.rgb*=color.a;
float writeGeometryInfo=color.a>0.4 ? 1.0 : 0.0;
gl_FragData[PREPASS_COLOR_INDEX]=color;
gl_FragData[PREPASS_POSITION_INDEX]=vec4(vPositionW,writeGeometryInfo);
gl_FragData[PREPASS_LOCAL_POSITION_INDEX]=vec4(vPosition,writeGeometryInfo);
vec2 a=(vCurrentPosition.xy/vCurrentPosition.w)*0.5+0.5;vec2 b=(vPreviousPosition.xy/vPreviousPosition.w)*0.5+0.5;vec2 velocity=abs(a-b);velocity=vec2(pow(velocity.x,1.0/3.0),pow(velocity.y,1.0/3.0))*sign(a-b)*0.5+0.5;gl_FragData[PREPASS_VELOCITY_INDEX]=vec4(velocity,0.0,writeGeometryInfo);
vec2 velocity=vec2(0.5)*((vPreviousPosition.xy/vPreviousPosition.w)-(vCurrentPosition.xy/vCurrentPosition.w));gl_FragData[PREPASS_VELOCITY_LINEAR_INDEX]=vec4(velocity,0.0,writeGeometryInfo);
gl_FragData[PREPASS_IRRADIANCE_INDEX]=vec4(0.0,0.0,0.0,writeGeometryInfo);
gl_FragData[PREPASS_DEPTH_INDEX]=vec4(vViewPos.z,0.0,0.0,writeGeometryInfo);
gl_FragData[PREPASS_SCREENSPACE_DEPTH_INDEX]=vec4(gl_FragCoord.z,0.0,0.0,writeGeometryInfo);
gl_FragData[PREPASS_NORMALIZED_VIEW_DEPTH_INDEX]=vec4(vNormViewDepth,0.0,0.0,writeGeometryInfo);
gl_FragData[PREPASS_NORMAL_INDEX]=vec4(normalW,writeGeometryInfo);
gl_FragData[PREPASS_NORMAL_INDEX]=vec4(normalize((view*vec4(normalW,0.0)).rgb),writeGeometryInfo);
gl_FragData[PREPASS_WORLD_NORMAL_INDEX]=vec4(normalW*0.5+0.5,writeGeometryInfo);
gl_FragData[PREPASS_ALBEDO_INDEX]=vec4(baseColor.rgb,writeGeometryInfo);
gl_FragData[PREPASS_ALBEDO_SQRT_INDEX]=vec4(sqrt(baseColor.rgb),writeGeometryInfo);
gl_FragData[PREPASS_REFLECTIVITY_INDEX]=vec4(toLinearSpace(specularMapColor))*writeGeometryInfo;
gl_FragData[PREPASS_REFLECTIVITY_INDEX]=vec4(toLinearSpace(specularColor),1.0)*writeGeometryInfo;
gl_FragColor=color;
if (fragDepth==nearestDepth) {frontColor.rgb+=color.rgb*color.a*alphaMultiplier;frontColor.a=1.0-alphaMultiplier*(1.0-color.a);} else {backColor+=color;}
}
`;
// Sideeffect
if (!ShaderStore.ShadersStore[name]) {
ShaderStore.ShadersStore[name] = shader;
}
/** @internal */
export const defaultPixelShader = { name, shader };
//# sourceMappingURL=default.fragment.js.map