@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.
237 lines • 8.72 kB
JavaScript
// Do not edit.
import { ShaderStore } from "../Engines/shaderStore.js";
import "./ShadersInclude/backgroundFragmentDeclaration.js";
import "./ShadersInclude/backgroundUboDeclaration.js";
import "./ShadersInclude/helperFunctions.js";
import "./ShadersInclude/reflectionFunction.js";
import "./ShadersInclude/imageProcessingDeclaration.js";
import "./ShadersInclude/lightFragmentDeclaration.js";
import "./ShadersInclude/lightUboDeclaration.js";
import "./ShadersInclude/lightsFragmentFunctions.js";
import "./ShadersInclude/shadowsFragmentFunctions.js";
import "./ShadersInclude/imageProcessingFunctions.js";
import "./ShadersInclude/logDepthDeclaration.js";
import "./ShadersInclude/clipPlaneFragmentDeclaration.js";
import "./ShadersInclude/fogFragmentDeclaration.js";
import "./ShadersInclude/intersectionFunctions.js";
import "./ShadersInclude/clipPlaneFragment.js";
import "./ShadersInclude/lightFragment.js";
import "./ShadersInclude/logDepthFragment.js";
import "./ShadersInclude/fogFragment.js";
const name = "backgroundPixelShader";
const shader = `
precision highp float;
varying vec3 vPositionW;
varying vec2 vMainUV1;
varying vec2 vMainUV2;
varying vec3 vNormalW;
varying vec2 vDiffuseUV;
uniform sampler2D diffuseSampler;
uniform samplerCube reflectionSampler;
uniform samplerCube reflectionSamplerLow;uniform samplerCube reflectionSamplerHigh;
uniform sampler2D reflectionSampler;
uniform samplerCube reflectionSamplerLow;uniform samplerCube reflectionSamplerHigh;
varying vec3 vPositionUVW;
varying vec3 vDirectionW;
vec3 fresnelSchlickEnvironmentGGX(float VdotN,vec3 reflectance0,vec3 reflectance90,float smoothness)
{float weight=mix(FRESNEL_MAXIMUM_ON_ROUGH,1.0,smoothness);return reflectance0+weight*(reflectance90-reflectance0)*pow5(saturate(1.0-VdotN));}
vec3 project(vec3 viewDirectionW,vec3 eyePosition) {float radius=projectedGroundInfos.x;float height=projectedGroundInfos.y;vec3 camDir=-viewDirectionW;float skySphereDistance=sphereIntersectFromOrigin(eyePosition,camDir,radius).x;vec3 skySpherePositionW=eyePosition+camDir*skySphereDistance;vec3 p=normalize(skySpherePositionW);eyePosition.y-=height;float sIntersection=sphereIntersectFromOrigin(eyePosition,p,radius).x;vec3 h=vec3(0.0,-height,0.0);float dIntersection=diskIntersectWithBackFaceCulling(eyePosition,p,h,radius);p=(eyePosition+min(sIntersection,dIntersection)*p);return p;}
void main(void) {
vec3 viewDirectionW=normalize(vEyePosition.xyz-vPositionW);
vec3 normalW=normalize(vNormalW);
vec3 normalW=vec3(0.0,1.0,0.0);
float shadow=1.;float globalShadow=0.;float shadowLightCount=0.;float aggShadow=0.;float numLights=0.;
globalShadow/=shadowLightCount;
globalShadow=1.0;
vec4 reflectionColor=vec4(1.,1.,1.,1.);
vec3 reflectionVector=project(viewDirectionW,vEyePosition.xyz);reflectionVector=vec3(reflectionMatrix*vec4(reflectionVector,1.));
vec3 reflectionVector=computeReflectionCoords(vec4(vPositionW,1.0),normalW);
reflectionVector.z*=-1.0;
vec3 reflectionCoords=reflectionVector;
vec2 reflectionCoords=reflectionVector.xy;
reflectionCoords/=reflectionVector.z;
reflectionCoords.y=1.0-reflectionCoords.y;
float reflectionLOD=vReflectionInfos.y;
reflectionLOD=reflectionLOD*log2(vReflectionMicrosurfaceInfos.x)*vReflectionMicrosurfaceInfos.y+vReflectionMicrosurfaceInfos.z;reflectionColor=sampleReflectionLod(reflectionSampler,reflectionCoords,reflectionLOD);
float lodReflectionNormalized=saturate(reflectionLOD);float lodReflectionNormalizedDoubled=lodReflectionNormalized*2.0;vec4 reflectionSpecularMid=sampleReflection(reflectionSampler,reflectionCoords);if(lodReflectionNormalizedDoubled<1.0){reflectionColor=mix(
sampleReflection(reflectionSamplerHigh,reflectionCoords),
reflectionSpecularMid,
lodReflectionNormalizedDoubled
);} else {reflectionColor=mix(
reflectionSpecularMid,
sampleReflection(reflectionSamplerLow,reflectionCoords),
lodReflectionNormalizedDoubled-1.0
);}
vec4 reflectionSample=sampleReflection(reflectionSampler,reflectionCoords);reflectionColor=reflectionSample;
reflectionColor.rgb=fromRGBD(reflectionColor);
reflectionColor.rgb=toLinearSpace(reflectionColor.rgb);
reflectionColor.rgb=reflectionColor.bgr;
reflectionColor.rgb*=vReflectionInfos.x;
vec3 diffuseColor=vec3(1.,1.,1.);float finalAlpha=alpha;
vec4 diffuseMap=texture2D(diffuseSampler,vDiffuseUV);
diffuseMap.rgb=toLinearSpace(diffuseMap.rgb);
diffuseMap.rgb*=vDiffuseInfos.y;
finalAlpha*=diffuseMap.a;
diffuseColor=diffuseMap.rgb;
vec3 colorBase=diffuseColor;
vec3 colorBase=reflectionColor.rgb*diffuseColor;
colorBase=max(colorBase,0.0);
vec3 finalColor=colorBase;
vec3 mainColor=mix(vPrimaryColorShadow.rgb,vPrimaryColor.rgb,colorBase);
vec3 mainColor=vPrimaryColor.rgb;
vec3 finalColor=colorBase*mainColor;
vec3 reflectionAmount=vReflectionControl.xxx;vec3 reflectionReflectance0=vReflectionControl.yyy;vec3 reflectionReflectance90=vReflectionControl.zzz;float VdotN=dot(normalize(vEyePosition.xyz),normalW);vec3 planarReflectionFresnel=fresnelSchlickEnvironmentGGX(saturate(VdotN),reflectionReflectance0,reflectionReflectance90,1.0);reflectionAmount*=planarReflectionFresnel;
float reflectionDistanceFalloff=1.0-saturate(length(vPositionW.xyz-vBackgroundCenter)*vReflectionControl.w);reflectionDistanceFalloff*=reflectionDistanceFalloff;reflectionAmount*=reflectionDistanceFalloff;
finalColor=mix(finalColor,reflectionColor.rgb,saturate(reflectionAmount));
float viewAngleToFloor=dot(normalW,normalize(vEyePosition.xyz-vBackgroundCenter));const float startAngle=0.1;float fadeFactor=saturate(viewAngleToFloor/startAngle);finalAlpha*=fadeFactor*fadeFactor;
finalColor=mix(finalColor*shadowLevel,finalColor,globalShadow);
vec4 color=vec4(finalColor,finalAlpha);
vec4 color=vec4(vPrimaryColor.rgb,(1.0-clamp(globalShadow,0.,1.))*alpha);
color.rgb=clamp(color.rgb,0.,30.0);
color=applyImageProcessing(color);
color.rgb*=color.a;
color.rgb+=dither(vPositionW.xy,0.5);color=max(color,0.0);
gl_FragColor=color;
}
`;
// Sideeffect
if (!ShaderStore.ShadersStore[name]) {
ShaderStore.ShadersStore[name] = shader;
}
/** @internal */
export const backgroundPixelShader = { name, shader };
//# sourceMappingURL=background.fragment.js.map