@babylonjs/viewer
Version:
The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.
289 lines (284 loc) • 11.5 kB
JavaScript
import { S as ShaderStore } from './index-MZPybX0H.esm.js';
import { s as sceneUboDeclaration } from './sceneUboDeclaration-D-TsHbOr.esm.js';
import { b as backgroundUboDeclaration } from './backgroundUboDeclaration-BohUXfzA.esm.js';
import { h as helperFunctions } from './helperFunctions-BVaVsPjM.esm.js';
import { r as reflectionFunction } from './reflectionFunction-B6TP4JGf.esm.js';
import { i as imageProcessingDeclaration, a as imageProcessingFunctions } from './imageProcessingFunctions-ZNIKNDtH.esm.js';
import { l as lightFragmentDeclaration, a as lightUboDeclaration, b as ltcHelperFunctions, s as shadowsFragmentFunctions } from './shadowsFragmentFunctions-A24LahRk.esm.js';
import { c as clusteredLightingFunctions, l as lightFragment } from './lightFragment-L93CSMZ9.esm.js';
import { l as lightsFragmentFunctions } from './lightsFragmentFunctions-DCgXTskf.esm.js';
import { l as logDepthDeclaration } from './logDepthDeclaration-BdXvBJD5.esm.js';
import { c as clipPlaneFragmentDeclaration, a as clipPlaneFragment } from './clipPlaneFragment-CKB1su_H.esm.js';
import { f as fogFragmentDeclaration, a as fogFragment } from './fogFragment-C3YQIhnt.esm.js';
import { l as logDepthFragment } from './logDepthFragment-4hdISSc_.esm.js';
// Do not edit.
const name$2 = "backgroundFragmentDeclaration";
const shader$2 = `uniform vec4 vEyePosition;uniform vec4 vPrimaryColor;
uniform vec4 vPrimaryColorShadow;
uniform float shadowLevel;uniform float alpha;
uniform vec2 vDiffuseInfos;
uniform vec2 vReflectionInfos;uniform mat4 reflectionMatrix;uniform vec3 vReflectionMicrosurfaceInfos;
uniform vec3 vBackgroundCenter;
uniform vec4 vReflectionControl;
uniform mat4 view;
uniform vec2 projectedGroundInfos;
`;
// Sideeffect
if (!ShaderStore.IncludesShadersStore[name$2]) {
ShaderStore.IncludesShadersStore[name$2] = shader$2;
}
/** @internal */
const backgroundFragmentDeclaration = { name: name$2, shader: shader$2 };
// Do not edit.
const name$1 = "intersectionFunctions";
const shader$1 = `float diskIntersectWithBackFaceCulling(vec3 ro,vec3 rd,vec3 c,float r) {float d=rd.y;if(d>0.0) { return 1e6; }
vec3 o=ro-c;float t=-o.y/d;vec3 q=o+rd*t;return (dot(q,q)<r*r) ? t : 1e6;}
vec2 sphereIntersect(vec3 ro,vec3 rd,vec3 ce,float ra) {vec3 oc=ro-ce;float b=dot(oc,rd);float c=dot(oc,oc)-ra*ra;float h=b*b-c;if(h<0.0) { return vec2(-1.0,-1.0); }
h=sqrt(h);return vec2(-b+h,-b-h);}
vec2 sphereIntersectFromOrigin(vec3 ro,vec3 rd,float ra) {float b=dot(ro,rd);float c=dot(ro,ro)-ra*ra;float h=b*b-c;if(h<0.0) { return vec2(-1.0,-1.0); }
h=sqrt(h);return vec2(-b+h,-b-h);}`;
// Sideeffect
if (!ShaderStore.IncludesShadersStore[name$1]) {
ShaderStore.IncludesShadersStore[name$1] = shader$1;
}
/** @internal */
const intersectionFunctions = { name: name$1, shader: shader$1 };
// Do not edit.
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;
}
const includes = [backgroundFragmentDeclaration, sceneUboDeclaration, backgroundUboDeclaration, helperFunctions, reflectionFunction, imageProcessingDeclaration, lightFragmentDeclaration, lightUboDeclaration, ltcHelperFunctions, clusteredLightingFunctions, lightsFragmentFunctions, shadowsFragmentFunctions, imageProcessingFunctions, logDepthDeclaration, clipPlaneFragmentDeclaration, fogFragmentDeclaration, intersectionFunctions, clipPlaneFragment, lightFragment, logDepthFragment, fogFragment];
for (const inc of includes) {
if (!ShaderStore.IncludesShadersStore[inc.name]) {
ShaderStore.IncludesShadersStore[inc.name] = inc.shader;
}
}
/** @internal */
const backgroundPixelShader = { name, shader };
export { backgroundPixelShader };
//# sourceMappingURL=background.fragment-DKUcpnok.esm.js.map