@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.
410 lines (407 loc) • 19.5 kB
JavaScript
import { S as ShaderStore } from './index-MZPybX0H.esm.js';
import { s as sceneUboDeclarationWGSL } from './sceneUboDeclaration-F06dki1D.esm.js';
import { m as meshUboDeclarationWGSL } from './meshUboDeclaration-CCr-qXSL.esm.js';
import { d as defaultUboDeclarationWGSL } from './defaultUboDeclaration-DM5G_RrV.esm.js';
import { p as prePassDeclarationWGSL, o as oitDeclarationWGSL, t as textureRepetitionFunctionsWGSL, d as depthPrePassWGSL, a as oitFragmentWGSL } from './oitFragment-cYhnThGO.esm.js';
import { m as mainUVVaryingDeclarationWGSL } from './mainUVVaryingDeclaration-CJ-yOzpF.esm.js';
import { h as helperFunctionsWGSL } from './helperFunctions-CiGzvr6_.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 { s as samplerFragmentDeclarationWGSL } from './samplerFragmentDeclaration-3tdaMBSe.esm.js';
import { f as fresnelFunctionWGSL } from './fresnelFunction-IWnpfsH_.esm.js';
import { r as reflectionFunctionWGSL } from './reflectionFunction-M92qPCCu.esm.js';
import { i as imageProcessingDeclarationWGSL, a as imageProcessingFunctionsWGSL } from './imageProcessingFunctions-DmDAqk27.esm.js';
import { b as bumpFragmentMainFunctionsWGSL, a as bumpFragmentFunctionsWGSL, c as bumpFragmentWGSL } from './bumpFragment-BsOq3kZt.esm.js';
import { c as clipPlaneFragmentDeclarationWGSL, a as clipPlaneFragmentWGSL } from './clipPlaneFragment-C6Z5D7El.esm.js';
import { l as logDepthDeclarationWGSL } from './logDepthDeclaration-BPJH8Xtb.esm.js';
import { f as fogFragmentDeclarationWGSL, a as fogFragmentWGSL } from './fogFragment-Lnu5KyrF.esm.js';
import { d as decalFragmentWGSL } from './decalFragment-Bg57qmDF.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 = "defaultPixelShader";
const shader = `
varying vPositionW: vec3f;
varying vNormalW: vec3f;
varying vColor: vec4f;
varying vViewDepth: f32;
var refractionCubeSamplerSampler: sampler;var refractionCubeSampler: texture_cube<f32>;
var refraction2DSamplerSampler: sampler;var refraction2DSampler: texture_2d<f32>;
var reflectionCubeSamplerSampler: sampler;var reflectionCubeSampler: texture_cube<f32>;
var reflection2DSamplerSampler: sampler;var reflection2DSampler: texture_2d<f32>;
varying vPositionUVW: vec3f;
varying vDirectionW: vec3f;
@fragment
fn main(input: FragmentInputs)->FragmentOutputs {
var viewDirectionW: vec3f=normalize(scene.vEyePosition.xyz-fragmentInputs.vPositionW);var baseColor: vec4f= vec4f(1.,1.,1.,1.);var diffuseColor: vec3f=uniforms.vDiffuseColor.rgb;var alpha: f32=uniforms.vDiffuseColor.a;
var normalW: vec3f=normalize(fragmentInputs.vNormalW);
var normalW: vec3f=normalize(cross(dpdx(fragmentInputs.vPositionW),dpdy(fragmentInputs.vPositionW)))* scene.vEyePosition.w;
normalW=select(-normalW,normalW,fragmentInputs.frontFacing);
baseColor=TEXRD(diffuseSampler,diffuseSamplerSampler,fragmentInputs.vDiffuseUV+uvOffset);
if (baseColor.a<uniforms.alphaCutOff) {discard;}
alpha*=baseColor.a;
baseColor=vec4f(baseColor.rgb*uniforms.vDiffuseInfos.y,baseColor.a);
var decalColor: vec4f=textureSample(decalSampler,decalSamplerSampler,fragmentInputs.vDecalUV+uvOffset);
baseColor=vec4f(baseColor.rgb*fragmentInputs.vColor.rgb,baseColor.a);
baseColor=vec4f(baseColor.rgb*2.0*mix(0.5,detailColor.r,uniforms.vDetailInfos.y),baseColor.a);
var decalColor: vec4f=textureSample(decalSampler,decalSamplerSampler,fragmentInputs.vDecalUV+uvOffset);
var baseAmbientColor: vec3f= vec3f(1.,1.,1.);
baseAmbientColor=TEXRD(ambientSampler,ambientSamplerSampler,fragmentInputs.vAmbientUV+uvOffset).rgb*uniforms.vAmbientInfos.y;
var glossiness: f32=uniforms.vSpecularColor.a;var specularColor: vec3f=uniforms.vSpecularColor.rgb;
var specularMapColor: vec4f=TEXRD(specularSampler,specularSamplerSampler,fragmentInputs.vSpecularUV+uvOffset);specularColor=specularMapColor.rgb;
glossiness=glossiness*specularMapColor.a;
var diffuseBase: vec3f= vec3f(0.,0.,0.);var info: lightingInfo;
var specularBase: vec3f= vec3f(0.,0.,0.);
var shadow: f32=1.;var aggShadow: f32=0.;var numLights: f32=0.;
var lightmapColor: vec4f=TEXRD(lightmapSampler,lightmapSamplerSampler,fragmentInputs.vLightmapUV+uvOffset);
lightmapColor=vec4f(fromRGBD(lightmapColor),lightmapColor.a);
lightmapColor=vec4f(lightmapColor.rgb*uniforms.vLightmapInfos.y,lightmapColor.a);
aggShadow=aggShadow/numLights;var refractionColor: vec4f= vec4f(0.,0.,0.,1.);
var refractionVector: vec3f=normalize(refract(-viewDirectionW,normalW,uniforms.vRefractionInfos.y));
refractionVector=parallaxCorrectNormal(fragmentInputs.vPositionW,refractionVector,uniforms.vRefractionSize,uniforms.vRefractionPosition);
refractionVector.y=refractionVector.y*uniforms.vRefractionInfos.w;var refractionLookup: vec4f=textureSample(refractionCubeSampler,refractionCubeSamplerSampler,refractionVector);if (dot(refractionVector,viewDirectionW)<1.0) {refractionColor=refractionLookup;}
var vRefractionUVW: vec3f= (uniforms.refractionMatrix*(scene.view* vec4f(fragmentInputs.vPositionW+refractionVector*uniforms.vRefractionInfos.z,1.0))).xyz;var refractionCoords: vec2f=vRefractionUVW.xy/vRefractionUVW.z;refractionCoords.y=1.0-refractionCoords.y;refractionColor=textureSample(refraction2DSampler,refraction2DSamplerSampler,refractionCoords);
refractionColor=vec4f(fromRGBD(refractionColor),refractionColor.a);
refractionColor=vec4f(toGammaSpaceVec3(refractionColor.rgb),refractionColor.a);
refractionColor=vec4f(refractionColor.rgb*uniforms.vRefractionInfos.x,refractionColor.a);
var reflectionColor: vec4f= vec4f(0.,0.,0.,1.);
var vReflectionUVW: vec3f=computeReflectionCoords( vec4f(fragmentInputs.vPositionW,1.0),normalW);
vReflectionUVW=vec3f(vReflectionUVW.x,vReflectionUVW.y,vReflectionUVW.z*-1.0);
var bias: f32=uniforms.vReflectionInfos.y;
bias*=(1.0-specularMapColor.a);
reflectionColor=textureSampleLevel(reflectionCubeSampler,reflectionCubeSamplerSampler,vReflectionUVW,bias);
reflectionColor=textureSample(reflectionCubeSampler,reflectionCubeSamplerSampler,vReflectionUVW);
var coords: vec2f=vReflectionUVW.xy;
coords/=vReflectionUVW.z;
coords.y=1.0-coords.y;reflectionColor=textureSample(reflection2DSampler,reflection2DSamplerSampler,coords);
reflectionColor=vec4f(fromRGBD(reflectionColor),reflectionColor.a);
reflectionColor=vec4f(toGammaSpaceVec3(reflectionColor.rgb),reflectionColor.a);
reflectionColor=vec4f(reflectionColor.rgb*uniforms.vReflectionInfos.x,reflectionColor.a);
var reflectionFresnelTerm: f32=computeFresnelTerm(viewDirectionW,normalW,uniforms.reflectionRightColor.a,uniforms.reflectionLeftColor.a);
reflectionColor=vec4f(reflectionColor.rgb*specularColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*uniforms.reflectionRightColor.rgb,reflectionColor.a);
reflectionColor=vec4f(reflectionColor.rgb*uniforms.reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*uniforms.reflectionRightColor.rgb,reflectionColor.a);
reflectionColor=vec4f(reflectionColor.rgb*uniforms.reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*uniforms.reflectionRightColor.rgb,reflectionColor.a);
var refractionFresnelTerm: f32=computeFresnelTerm(viewDirectionW,normalW,uniforms.refractionRightColor.a,uniforms.refractionLeftColor.a);refractionColor=vec4f(refractionColor.rgb*uniforms.refractionLeftColor.rgb*(1.0-refractionFresnelTerm)+refractionFresnelTerm*uniforms.refractionRightColor.rgb,refractionColor.a);
var opacityMap: vec4f=TEXRD(opacitySampler,opacitySamplerSampler,fragmentInputs.vOpacityUV+uvOffset);
opacityMap=vec4f(opacityMap.rgb* vec3f(0.3,0.59,0.11),opacityMap.a);alpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* uniforms.vOpacityInfos.y;
alpha*=opacityMap.a*uniforms.vOpacityInfos.y;
alpha*=fragmentInputs.vColor.a;
var opacityFresnelTerm: f32=computeFresnelTerm(viewDirectionW,normalW,uniforms.opacityParts.z,uniforms.opacityParts.w);alpha+=uniforms.opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*uniforms.opacityParts.y;
if (alpha<uniforms.alphaCutOff) {discard;}
alpha=1.0;
var emissiveColor: vec3f=uniforms.vEmissiveColor;
emissiveColor+=TEXRD(emissiveSampler,emissiveSamplerSampler,fragmentInputs.vEmissiveUV+uvOffset).rgb*uniforms.vEmissiveInfos.y;
var emissiveFresnelTerm: f32=computeFresnelTerm(viewDirectionW,normalW,uniforms.emissiveRightColor.a,uniforms.emissiveLeftColor.a);emissiveColor*=uniforms.emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*uniforms.emissiveRightColor.rgb;
var diffuseFresnelTerm: f32=computeFresnelTerm(viewDirectionW,normalW,uniforms.diffuseRightColor.a,uniforms.diffuseLeftColor.a);diffuseBase*=uniforms.diffuseLeftColor.rgb*(1.0-diffuseFresnelTerm)+diffuseFresnelTerm*uniforms.diffuseRightColor.rgb;
var finalDiffuse: vec3f=clamp(diffuseBase*diffuseColor+uniforms.vAmbientColor,vec3f(0.0),vec3f(1.0))*baseColor.rgb;
var finalDiffuse: vec3f=clamp((diffuseBase+emissiveColor)*diffuseColor+uniforms.vAmbientColor,vec3f(0.0),vec3f(1.0))*baseColor.rgb;
var finalDiffuse: vec3f=clamp(diffuseBase*diffuseColor+emissiveColor+uniforms.vAmbientColor,vec3f(0.0),vec3f(1.0))*baseColor.rgb;
var finalSpecular: vec3f=specularBase*specularColor;
alpha=clamp(alpha+dot(finalSpecular, vec3f(0.3,0.59,0.11)),0.0,1.0);
var finalSpecular: vec3f= vec3f(0.0);
alpha=clamp(alpha+dot(reflectionColor.rgb, vec3f(0.3,0.59,0.11)),0.0,1.0);
var color: vec4f= vec4f(clamp(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor.rgb+emissiveColor+refractionColor.rgb,vec3f(0.0),vec3f(1.0)),alpha);
var color: vec4f= vec4f(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor.rgb+refractionColor.rgb,alpha);
color=vec4f(color.rgb*lightmapColor.rgb,color.a);
color=vec4f(color.rgb+lightmapColor.rgb,color.a);
color=vec4f(max(color.rgb,vec3f(0.)),color.a);
color=vec4f(toLinearSpaceVec3(color.rgb),color.a);
color=vec4f(toLinearSpaceVec3(color.rgb),color.a);color=applyImageProcessing(color);
color=vec4f(color.rgb,color.a*mesh.visibility);
color=vec4f(color.rgb*color.a, color.a);
var writeGeometryInfo: f32=select(0.0,1.0,color.a>0.4);var fragData: array<vec4<f32>,SCENE_MRT_COUNT>;
fragData[PREPASS_COLOR_INDEX]=color;
fragData[PREPASS_POSITION_INDEX]=vec4f(fragmentInputs.vPositionW,writeGeometryInfo);
fragData[PREPASS_LOCAL_POSITION_INDEX]=vec4f(fragmentInputs.vPosition,writeGeometryInfo);
var a: vec2f=(fragmentInputs.vCurrentPosition.xy/fragmentInputs.vCurrentPosition.w)*0.5+0.5;var b: vec2f=(fragmentInputs.vPreviousPosition.xy/fragmentInputs.vPreviousPosition.w)*0.5+0.5;var velocity: vec2f=abs(a-b);velocity= vec2f(pow(velocity.x,1.0/3.0),pow(velocity.y,1.0/3.0))*sign(a-b)*0.5+0.5;fragData[PREPASS_VELOCITY_INDEX]= vec4f(velocity,0.0,writeGeometryInfo);
var velocity : vec2f=vec2f(0.5)*((fragmentInputs.vPreviousPosition.xy/fragmentInputs.vPreviousPosition.w) -
(fragmentInputs.vCurrentPosition.xy/fragmentInputs.vCurrentPosition.w));fragData[PREPASS_VELOCITY_LINEAR_INDEX]=vec4f(velocity,0.0,writeGeometryInfo);
fragData[PREPASS_IRRADIANCE_INDEX]=vec4f(0.0,0.0,0.0,writeGeometryInfo);
fragData[PREPASS_DEPTH_INDEX]=vec4f(fragmentInputs.vViewPos.z,0.0,0.0,writeGeometryInfo);
fragData[PREPASS_SCREENSPACE_DEPTH_INDEX]=vec4f(fragmentInputs.position.z,0.0,0.0,writeGeometryInfo);
fragData[PREPASS_NORMALIZED_VIEW_DEPTH_INDEX]=vec4f(fragmentInputs.vNormViewDepth,0.0,0.0,writeGeometryInfo);
fragData[PREPASS_NORMAL_INDEX]=vec4f(normalW,writeGeometryInfo);
fragData[PREPASS_NORMAL_INDEX]=vec4f(normalize((scene.view*vec4f(normalW,0.0)).rgb),writeGeometryInfo);
fragData[PREPASS_WORLD_NORMAL_INDEX]=vec4f(normalW*0.5+0.5,writeGeometryInfo);
fragData[PREPASS_ALBEDO_INDEX]=vec4f(baseColor.rgb,writeGeometryInfo);
fragData[PREPASS_ALBEDO_SQRT_INDEX]=vec4f(sqrt(baseColor.rgb),writeGeometryInfo);
fragData[PREPASS_REFLECTIVITY_INDEX]=vec4f(toLinearSpaceVec4(specularMapColor))*writeGeometryInfo;
fragData[PREPASS_REFLECTIVITY_INDEX]=vec4f(toLinearSpaceVec3(specularColor),1.0)*writeGeometryInfo;
fragmentOutputs.fragData0=fragData[0];
fragmentOutputs.fragData1=fragData[1];
fragmentOutputs.fragData2=fragData[2];
fragmentOutputs.fragData3=fragData[3];
fragmentOutputs.fragData4=fragData[4];
fragmentOutputs.fragData5=fragData[5];
fragmentOutputs.fragData6=fragData[6];
fragmentOutputs.fragData7=fragData[7];
fragmentOutputs.color=color;
if (fragDepth==nearestDepth) {fragmentOutputs.frontColor=vec4f(fragmentOutputs.frontColor.rgb+color.rgb*color.a*alphaMultiplier,1.0-alphaMultiplier*(1.0-color.a));} else {fragmentOutputs.backColor+=color;}
}
`;
// Sideeffect
if (!ShaderStore.ShadersStoreWGSL[name]) {
ShaderStore.ShadersStoreWGSL[name] = shader;
}
const includes = [sceneUboDeclarationWGSL, meshUboDeclarationWGSL, defaultUboDeclarationWGSL, prePassDeclarationWGSL, oitDeclarationWGSL, mainUVVaryingDeclarationWGSL, helperFunctionsWGSL, lightUboDeclarationWGSL, ltcHelperFunctionsWGSL, clusteredLightingFunctionsWGSL, clusteredLightingComputeWGSL, lightsFragmentFunctionsWGSL, shadowsFragmentFunctionsWGSL, samplerFragmentDeclarationWGSL, fresnelFunctionWGSL, reflectionFunctionWGSL, imageProcessingDeclarationWGSL, imageProcessingFunctionsWGSL, textureRepetitionFunctionsWGSL, bumpFragmentMainFunctionsWGSL, bumpFragmentFunctionsWGSL, clipPlaneFragmentDeclarationWGSL, logDepthDeclarationWGSL, fogFragmentDeclarationWGSL, clipPlaneFragmentWGSL, bumpFragmentWGSL, decalFragmentWGSL, depthPrePassWGSL, lightFragmentWGSL, logDepthFragmentWGSL, fogFragmentWGSL, oitFragmentWGSL];
for (const inc of includes) {
if (!ShaderStore.IncludesShadersStoreWGSL[inc.name]) {
ShaderStore.IncludesShadersStoreWGSL[inc.name] = inc.shader;
}
}
/** @internal */
const defaultPixelShaderWGSL = { name, shader };
export { defaultPixelShaderWGSL };
//# sourceMappingURL=default.fragment-B-tUIRnr.esm.js.map