@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.
484 lines (479 loc) • 19.2 kB
JavaScript
import { S as ShaderStore } from './index-MZPybX0H.esm.js';
import { d as decalFragmentDeclaration, p as prePassDeclaration, o as oitDeclaration, t as textureRepetitionFunctions, a as depthPrePass, b as oitFragment } from './oitFragment-DoYw4kgZ.esm.js';
import { s as sceneUboDeclaration } from './sceneUboDeclaration-D-TsHbOr.esm.js';
import { m as meshUboDeclaration } from './meshUboDeclaration-Bv_BtoSy.esm.js';
import { d as defaultUboDeclaration } from './defaultUboDeclaration-CtwsKbM_.esm.js';
import { m as mainUVVaryingDeclaration } from './mainUVVaryingDeclaration-Bm0UsfVq.esm.js';
import { h as helperFunctions } from './helperFunctions-BVaVsPjM.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 { s as samplerFragmentDeclaration } from './samplerFragmentDeclaration-79xnpfH1.esm.js';
import { r as reflectionFunction } from './reflectionFunction-B6TP4JGf.esm.js';
import { i as imageProcessingDeclaration, a as imageProcessingFunctions } from './imageProcessingFunctions-ZNIKNDtH.esm.js';
import { b as bumpFragmentMainFunctions, a as bumpFragmentFunctions, c as bumpFragment } from './bumpFragment-BfdS04jH.esm.js';
import { c as clipPlaneFragmentDeclaration, a as clipPlaneFragment } from './clipPlaneFragment-CKB1su_H.esm.js';
import { l as logDepthDeclaration } from './logDepthDeclaration-BdXvBJD5.esm.js';
import { f as fogFragmentDeclaration, a as fogFragment } from './fogFragment-C3YQIhnt.esm.js';
import { d as decalFragment } from './decalFragment-BtBYwdr_.esm.js';
import { l as logDepthFragment } from './logDepthFragment-4hdISSc_.esm.js';
// Do not edit.
const name$2 = "defaultFragmentDeclaration";
const shader$2 = `uniform vec4 vEyePosition;uniform vec4 vDiffuseColor;uniform vec4 vSpecularColor;uniform vec3 vEmissiveColor;uniform vec3 vAmbientColor;uniform float visibility;
uniform vec2 vDiffuseInfos;
uniform vec2 vAmbientInfos;
uniform vec2 vOpacityInfos;
uniform vec2 vEmissiveInfos;
uniform vec2 vLightmapInfos;
uniform vec3 vBumpInfos;uniform vec2 vTangentSpaceParams;
uniform float alphaCutOff;
uniform mat4 view;
uniform vec4 vRefractionInfos;
uniform mat4 refractionMatrix;
uniform vec4 refractionLeftColor;uniform vec4 refractionRightColor;
uniform vec3 vRefractionPosition;uniform vec3 vRefractionSize;
uniform vec2 vSpecularInfos;
uniform vec4 diffuseLeftColor;uniform vec4 diffuseRightColor;
uniform vec4 opacityParts;
uniform vec4 emissiveLeftColor;uniform vec4 emissiveRightColor;
uniform vec2 vReflectionInfos;
uniform mat4 reflectionMatrix;
uniform vec3 vReflectionPosition;uniform vec3 vReflectionSize;
uniform vec4 reflectionLeftColor;uniform vec4 reflectionRightColor;
uniform vec4 vDetailInfos;
uniform vec4 vTextureRepetitionHexTilingParams;
`;
// Sideeffect
if (!ShaderStore.IncludesShadersStore[name$2]) {
ShaderStore.IncludesShadersStore[name$2] = shader$2;
}
/** @internal */
const defaultFragmentDeclaration = { name: name$2, shader: shader$2 };
// Do not edit.
const name$1 = "fresnelFunction";
const shader$1 = `
float computeFresnelTerm(vec3 viewDirection,vec3 worldNormal,float bias,float power)
{float fresnelTerm=pow(bias+abs(dot(viewDirection,worldNormal)),power);return clamp(fresnelTerm,0.,1.);}
`;
// Sideeffect
if (!ShaderStore.IncludesShadersStore[name$1]) {
ShaderStore.IncludesShadersStore[name$1] = shader$1;
}
/** @internal */
const fresnelFunction = { name: name$1, shader: shader$1 };
// Do not edit.
const name = "defaultPixelShader";
const shader = `
varying vec3 vPositionW;
varying vec3 vNormalW;
varying vec4 vColor;
varying float vViewDepth;
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)))*vEyePosition.w;
normalW=gl_FrontFacing ? normalW : -normalW;
baseColor=TEXRD(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=TEXRD(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;
float glossiness=vSpecularColor.a;vec3 specularColor=vSpecularColor.rgb;
vec4 specularMapColor=TEXRD(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=TEXRD(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=TEXRD(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+=TEXRD(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;
}
const includes = [decalFragmentDeclaration, defaultFragmentDeclaration, sceneUboDeclaration, meshUboDeclaration, defaultUboDeclaration, prePassDeclaration, oitDeclaration, mainUVVaryingDeclaration, helperFunctions, lightFragmentDeclaration, lightUboDeclaration, ltcHelperFunctions, clusteredLightingFunctions, lightsFragmentFunctions, shadowsFragmentFunctions, samplerFragmentDeclaration, fresnelFunction, reflectionFunction, imageProcessingDeclaration, imageProcessingFunctions, textureRepetitionFunctions, bumpFragmentMainFunctions, bumpFragmentFunctions, clipPlaneFragmentDeclaration, logDepthDeclaration, fogFragmentDeclaration, clipPlaneFragment, bumpFragment, decalFragment, depthPrePass, lightFragment, logDepthFragment, fogFragment, oitFragment];
for (const inc of includes) {
if (!ShaderStore.IncludesShadersStore[inc.name]) {
ShaderStore.IncludesShadersStore[inc.name] = inc.shader;
}
}
/** @internal */
const defaultPixelShader = { name, shader };
export { defaultPixelShader };
//# sourceMappingURL=default.fragment-DTIR803i.esm.js.map