@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.
246 lines (242 loc) • 11.7 kB
JavaScript
import { S as ShaderStore } from './index-MZPybX0H.esm.js';
import { s as sceneUboDeclarationWGSL } from './sceneUboDeclaration-F06dki1D.esm.js';
import { b as backgroundUboDeclarationWGSL } from './backgroundUboDeclaration-CCbyiLC8.esm.js';
import { h as helperFunctionsWGSL } from './helperFunctions-CiGzvr6_.esm.js';
import { r as reflectionFunctionWGSL } from './reflectionFunction-M92qPCCu.esm.js';
import { i as imageProcessingDeclarationWGSL, a as imageProcessingFunctionsWGSL } from './imageProcessingFunctions-DmDAqk27.esm.js';
import { l as lightUboDeclarationWGSL, a as ltcHelperFunctionsWGSL, c as clusteredLightingFunctionsWGSL, s as shadowsFragmentFunctionsWGSL } from './shadowsFragmentFunctions-B3hA3Hts.esm.js';
import { c as clusteredLightingComputeWGSL, l as lightsFragmentFunctionsWGSL } from './lightsFragmentFunctions-BxV-pugT.esm.js';
import { l as logDepthDeclarationWGSL } from './logDepthDeclaration-BPJH8Xtb.esm.js';
import { c as clipPlaneFragmentDeclarationWGSL, a as clipPlaneFragmentWGSL } from './clipPlaneFragment-C6Z5D7El.esm.js';
import { f as fogFragmentDeclarationWGSL, a as fogFragmentWGSL } from './fogFragment-Lnu5KyrF.esm.js';
import { l as lightFragmentWGSL } from './lightFragment-QA3d09B7.esm.js';
import { l as logDepthFragmentWGSL } from './logDepthFragment-DD4DS4oL.esm.js';
// Do not edit.
const name$1 = "intersectionFunctions";
const shader$1 = `fn diskIntersectWithBackFaceCulling(ro: vec3f,rd: vec3f,c: vec3f,r: f32)->f32 {var d: f32=rd.y;if(d>0.0) { return 1e6; }
var o: vec3f=ro-c;var t: f32=-o.y/d;var q: vec3f=o+rd*t;return select(1e6,t,(dot(q,q)<r*r));}
fn sphereIntersect(ro: vec3f,rd: vec3f,ce: vec3f,ra: f32)->vec2f {var oc: vec3f=ro-ce;var b: f32=dot(oc,rd);var c: f32=dot(oc,oc)-ra*ra;var h: f32=b*b-c;if(h<0.0) { return vec2f(-1.,-1.); }
h=sqrt(h);return vec2f(-b+h,-b-h);}
fn sphereIntersectFromOrigin(ro: vec3f,rd: vec3f,ra: f32)->vec2f {var b: f32=dot(ro,rd);var c: f32=dot(ro,ro)-ra*ra;var h: f32=b*b-c;if(h<0.0) { return vec2f(-1.,-1.); }
h=sqrt(h);return vec2f(-b+h,-b-h);}`;
// Sideeffect
if (!ShaderStore.IncludesShadersStoreWGSL[name$1]) {
ShaderStore.IncludesShadersStoreWGSL[name$1] = shader$1;
}
/** @internal */
const intersectionFunctionsWGSL = { name: name$1, shader: shader$1 };
// Do not edit.
const name = "backgroundPixelShader";
const shader = `
varying vPositionW: vec3f;
varying vMainUV1: vec2f;
varying vMainUV2: vec2f;
varying vNormalW: vec3f;
varying vDiffuseUV: vec2f;
var diffuseSamplerSampler: sampler;var diffuseSampler: texture_2d<f32>;
var reflectionSamplerSampler: sampler;var reflectionSampler: texture_cube<f32>;
var reflectionLowSamplerSampler: sampler;var reflectionLowSampler: texture_cube<f32>;var reflectionHighSamplerSampler: sampler;var reflectionHighSampler: texture_cube<f32>;
var reflectionSamplerSampler: sampler;var reflectionSampler: texture_2d<f32>;
var reflectionLowSamplerSampler: sampler;var reflectionLowSampler: texture_2d<f32>;var reflectionHighSamplerSampler: sampler;var reflectionHighSampler: texture_2d<f32>;
varying vPositionUVW: vec3f;
varying vDirectionW: vec3f;
fn fresnelSchlickEnvironmentGGX(VdotN: f32,reflectance0: vec3f,reflectance90: vec3f,smoothness: f32)->vec3f
{var weight: f32=mix(FRESNEL_MAXIMUM_ON_ROUGH,1.0,smoothness);return reflectance0+weight*(reflectance90-reflectance0)*pow5(saturate(1.0-VdotN));}
fn project(viewDirectionW: vec3f,eyePosition: vec3f)->vec3f {var radius: f32=uniforms.projectedGroundInfos.x;var height: f32=uniforms.projectedGroundInfos.y;var camDir: vec3f=-viewDirectionW;var skySphereDistance: f32=sphereIntersectFromOrigin(eyePosition,camDir,radius).x;var skySpherePositionW: vec3f=eyePosition+camDir*skySphereDistance;var p: vec3f=normalize(skySpherePositionW);var upEyePosition=vec3f(eyePosition.x,eyePosition.y-height,eyePosition.z);var sIntersection: f32=sphereIntersectFromOrigin(upEyePosition,p,radius).x;var h: vec3f= vec3f(0.0,-height,0.0);var dIntersection: f32=diskIntersectWithBackFaceCulling(upEyePosition,p,h,radius);p=(upEyePosition+min(sIntersection,dIntersection)*p);return p;}
@fragment
fn main(input: FragmentInputs)->FragmentOutputs {
var viewDirectionW: vec3f=normalize(scene.vEyePosition.xyz-input.vPositionW);
var normalW: vec3f=normalize(fragmentInputs.vNormalW);
var normalW: vec3f= vec3f(0.0,1.0,0.0);
var shadow: f32=1.;var globalShadow: f32=0.;var shadowLightCount: f32=0.;var aggShadow: f32=0.;var numLights: f32=0.;
globalShadow/=shadowLightCount;
globalShadow=1.0;
var reflectionColor: vec4f= vec4f(1.,1.,1.,1.);
var reflectionVector: vec3f=project(viewDirectionW,scene.vEyePosition.xyz);reflectionVector= (uniforms.reflectionMatrix*vec4f(reflectionVector,1.)).xyz;
var reflectionVector: vec3f=computeReflectionCoords( vec4f(fragmentInputs.vPositionW,1.0),normalW);
reflectionVector.z*=-1.0;
var reflectionCoords: vec3f=reflectionVector;
var reflectionCoords: vec2f=reflectionVector.xy;
reflectionCoords/=reflectionVector.z;
reflectionCoords.y=1.0-reflectionCoords.y;
var reflectionLOD: f32=uniforms.vReflectionInfos.y;
reflectionLOD=reflectionLOD*log2(uniforms.vReflectionMicrosurfaceInfos.x)*uniforms.vReflectionMicrosurfaceInfos.y+uniforms.vReflectionMicrosurfaceInfos.z;reflectionColor=textureSampleLevel(reflectionSampler,reflectionSamplerSampler,reflectionCoords,reflectionLOD);
var lodReflectionNormalized: f32=saturate(reflectionLOD);var lodReflectionNormalizedDoubled: f32=lodReflectionNormalized*2.0;var reflectionSpecularMid: vec4f=textureSample(reflectionSampler,reflectionSamplerSampler,reflectionCoords);if(lodReflectionNormalizedDoubled<1.0){reflectionColor=mix(
textureSample(reflectionrHighSampler,reflectionrHighSamplerSampler,reflectionCoords),
reflectionSpecularMid,
lodReflectionNormalizedDoubled
);} else {reflectionColor=mix(
reflectionSpecularMid,
textureSample(reflectionLowSampler,reflectionLowSamplerSampler,reflectionCoords),
lodReflectionNormalizedDoubled-1.0
);}
var reflectionSample: vec4f=textureSample(reflectionSampler,reflectionSamplerSampler,reflectionCoords);reflectionColor=reflectionSample;
reflectionColor=vec4f(fromRGBD(reflectionColor).rgb,reflectionColor.a);
reflectionColor=vec4f(toLinearSpaceVec3(reflectionColor.rgb),reflectionColor.a);
reflectionColor=vec4f(reflectionColor.bgr,reflectionColor.a);
reflectionColor=vec4f(reflectionColor.rgb*uniforms.vReflectionInfos.x,reflectionColor.a);
var diffuseColor: vec3f= vec3f(1.,1.,1.);var finalAlpha: f32=uniforms.alpha;
var diffuseMap: vec4f=textureSample(diffuseSampler,diffuseSamplerSampler,input.vDiffuseUV);
diffuseMap=vec4f(toLinearSpaceVec3(diffuseMap.rgb),diffuseMap.a);
diffuseMap=vec4f(diffuseMap.rgb *uniforms.vDiffuseInfos.y,diffuseMap.a);
finalAlpha*=diffuseMap.a;
diffuseColor=diffuseMap.rgb;
var colorBase: vec3f=diffuseColor;
var colorBase: vec3f=reflectionColor.rgb*diffuseColor;
colorBase=max(colorBase,vec3f(0.0));
var finalColor: vec3f=colorBase;
var mainColor: vec3f=mix(uniforms.vPrimaryColorShadow.rgb,uniforms.vPrimaryColor.rgb,colorBase);
var mainColor: vec3f=uniforms.vPrimaryColor.rgb;
var finalColor: vec3f=colorBase*mainColor;
var reflectionAmount: vec3f=uniforms.vReflectionControl.xxx;var reflectionReflectance0: vec3f=uniforms.vReflectionControl.yyy;var reflectionReflectance90: vec3f=uniforms.vReflectionControl.zzz;var VdotN: f32=dot(normalize(scene.vEyePosition.xyz),normalW);var planarReflectionFresnel: vec3f=fresnelSchlickEnvironmentGGX(saturate(VdotN),reflectionReflectance0,reflectionReflectance90,1.0);reflectionAmount*=planarReflectionFresnel;
var reflectionDistanceFalloff: f32=1.0-saturate(length(fragmentInputs.vPositionW.xyz-uniforms.vBackgroundCenter)*uniforms.vReflectionControl.w);reflectionDistanceFalloff*=reflectionDistanceFalloff;reflectionAmount*=reflectionDistanceFalloff;
finalColor=mix(finalColor,reflectionColor.rgb,saturateVec3(reflectionAmount));
var viewAngleToFloor: f32=dot(normalW,normalize(scene.vEyePosition.xyz-uniforms.vBackgroundCenter));const startAngle: f32=0.1;var fadeFactor: f32=saturate(viewAngleToFloor/startAngle);finalAlpha*=fadeFactor*fadeFactor;
finalColor=mix(finalColor*uniforms.shadowLevel,finalColor,globalShadow);
var color: vec4f= vec4f(finalColor,finalAlpha);
var color: vec4f= vec4f(uniforms.vPrimaryColor.rgb,(1.0-clamp(globalShadow,0.,1.))*uniforms.alpha);
color=vec4f(clamp(color.rgb,vec3f(0.),vec3f(30.0)),color.a);
color=applyImageProcessing(color);
color=vec4f(color.rgb *color.a,color.a);
color=vec4f(color.rgb+dither(fragmentInputs.vPositionW.xy,0.5),color.a);color=max(color,vec4f(0.0));
fragmentOutputs.color=color;
}
`;
// Sideeffect
if (!ShaderStore.ShadersStoreWGSL[name]) {
ShaderStore.ShadersStoreWGSL[name] = shader;
}
const includes = [sceneUboDeclarationWGSL, backgroundUboDeclarationWGSL, helperFunctionsWGSL, reflectionFunctionWGSL, imageProcessingDeclarationWGSL, lightUboDeclarationWGSL, ltcHelperFunctionsWGSL, clusteredLightingFunctionsWGSL, clusteredLightingComputeWGSL, lightsFragmentFunctionsWGSL, shadowsFragmentFunctionsWGSL, imageProcessingFunctionsWGSL, logDepthDeclarationWGSL, clipPlaneFragmentDeclarationWGSL, fogFragmentDeclarationWGSL, intersectionFunctionsWGSL, clipPlaneFragmentWGSL, lightFragmentWGSL, logDepthFragmentWGSL, fogFragmentWGSL];
for (const inc of includes) {
if (!ShaderStore.IncludesShadersStoreWGSL[inc.name]) {
ShaderStore.IncludesShadersStoreWGSL[inc.name] = inc.shader;
}
}
/** @internal */
const backgroundPixelShaderWGSL = { name, shader };
export { backgroundPixelShaderWGSL };
//# sourceMappingURL=background.fragment-CKtrvoww.esm.js.map