UNPKG

@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.

403 lines (395 loc) 17.9 kB
import { S as ShaderStore } from './index-MZPybX0H.esm.js'; // Do not edit. const name$5 = "sceneFragmentDeclaration"; const shader$5 = `uniform mat4 viewProjection; #ifdef MULTIVIEW uniform mat4 viewProjectionR; #endif uniform mat4 view;uniform mat4 projection;uniform vec4 vEyePosition;uniform mat4 inverseProjection; `; // Sideeffect if (!ShaderStore.IncludesShadersStore[name$5]) { ShaderStore.IncludesShadersStore[name$5] = shader$5; } /** @internal */ const sceneFragmentDeclaration = { name: name$5, shader: shader$5 }; // Do not edit. const name$4 = "openpbrDielectricReflectance"; const shader$4 = `struct ReflectanceParams {float F0;float F90;vec3 coloredF0;vec3 coloredF90;}; #define pbr_inline ReflectanceParams dielectricReflectance( in float insideIOR,in float outsideIOR,in vec3 specularColor,in float specularWeight ) {ReflectanceParams outParams;float dielectricF0=pow((insideIOR-outsideIOR)/(insideIOR+outsideIOR),2.0);float f90Scale=clamp(2.0*abs(insideIOR-outsideIOR),0.0,1.0); #if (DIELECTRIC_SPECULAR_MODEL==DIELECTRIC_SPECULAR_MODEL_OPENPBR) vec3 dielectricColorF90=specularColor.rgb*vec3(f90Scale); #else vec3 dielectricColorF90=vec3(f90Scale); #endif #if DIELECTRIC_SPECULAR_MODEL==DIELECTRIC_SPECULAR_MODEL_GLTF float maxF0=max(specularColor.r,max(specularColor.g,specularColor.b));outParams.F0=dielectricF0*specularWeight*maxF0; #else outParams.F0=dielectricF0*specularWeight; #endif outParams.F90=f90Scale*specularWeight;outParams.coloredF0=vec3(dielectricF0*specularWeight)*specularColor.rgb;outParams.coloredF90=dielectricColorF90*vec3(specularWeight);return outParams;} `; // Sideeffect if (!ShaderStore.IncludesShadersStore[name$4]) { ShaderStore.IncludesShadersStore[name$4] = shader$4; } /** @internal */ const openpbrDielectricReflectance = { name: name$4, shader: shader$4 }; // Do not edit. const name$3 = "openpbrGeometryInfo"; const shader$3 = `struct geometryInfoOutParams {float NdotV;float NdotVUnclamped;vec3 environmentBrdf;float horizonOcclusion;};struct geometryInfoAnisoOutParams {float NdotV;float NdotVUnclamped;vec3 environmentBrdf;float horizonOcclusion;float anisotropy;vec3 anisotropicTangent;vec3 anisotropicBitangent;mat3 TBN;}; #define pbr_inline geometryInfoOutParams geometryInfo( in vec3 normalW,in vec3 viewDirectionW,in float roughness,in vec3 geometricNormalW ) {geometryInfoOutParams outParams;outParams.NdotVUnclamped=dot(normalW,viewDirectionW);outParams.NdotV=absEps(outParams.NdotVUnclamped); #if defined(ENVIRONMENTBRDF) outParams.environmentBrdf=getBRDFLookup(outParams.NdotV,roughness); #else outParams.environmentBrdf=vec3(0.0); #endif outParams.horizonOcclusion=1.0; #if defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX) #ifdef HORIZONOCCLUSION #if defined(GEOMETRY_NORMAL) || defined(GEOMETRY_COAT_NORMAL) #ifdef REFLECTIONMAP_3D outParams.horizonOcclusion=environmentHorizonOcclusion(-viewDirectionW,normalW,geometricNormalW); #endif #endif #endif #endif return outParams;} #define pbr_inline geometryInfoAnisoOutParams geometryInfoAniso( in vec3 normalW,in vec3 viewDirectionW,in float roughness,in vec3 geometricNormalW ,in vec3 vAnisotropy,in mat3 TBN ) {geometryInfoOutParams geoInfo=geometryInfo(normalW,viewDirectionW,roughness,geometricNormalW);geometryInfoAnisoOutParams outParams;outParams.NdotV=geoInfo.NdotV;outParams.NdotVUnclamped=geoInfo.NdotVUnclamped;outParams.environmentBrdf=geoInfo.environmentBrdf;outParams.horizonOcclusion=geoInfo.horizonOcclusion;outParams.anisotropy=vAnisotropy.b;vec3 anisotropyDirection=vec3(vAnisotropy.xy,0.);mat3 anisoTBN=mat3(normalize(TBN[0]),normalize(TBN[1]),normalize(TBN[2]));outParams.anisotropicTangent=normalize(anisoTBN*anisotropyDirection);outParams.anisotropicBitangent=normalize(cross(anisoTBN[2],outParams.anisotropicTangent));outParams.TBN=TBN;return outParams;}`; // Sideeffect if (!ShaderStore.IncludesShadersStore[name$3]) { ShaderStore.IncludesShadersStore[name$3] = shader$3; } /** @internal */ const openpbrGeometryInfo = { name: name$3, shader: shader$3 }; // Do not edit. const name$2 = "openpbrIblFunctions"; const shader$2 = `#ifdef REFLECTION vec3 sampleIrradiance( in vec3 surfaceNormal #if defined(NORMAL) && defined(USESPHERICALINVERTEX) ,in vec3 vEnvironmentIrradianceSH #endif #if (defined(USESPHERICALFROMREFLECTIONMAP) && (!defined(NORMAL) || !defined(USESPHERICALINVERTEX))) || (defined(USEIRRADIANCEMAP) && defined(REFLECTIONMAP_3D)) ,in mat4 iblMatrix #endif #ifdef USEIRRADIANCEMAP #ifdef REFLECTIONMAP_3D ,in samplerCube irradianceSampler #else ,in sampler2D irradianceSampler #endif #ifdef USE_IRRADIANCE_DOMINANT_DIRECTION ,in vec3 reflectionDominantDirection #endif #endif #ifdef REALTIME_FILTERING ,in vec2 vReflectionFilteringInfo #ifdef IBL_CDF_FILTERING ,in sampler2D icdfSampler #endif #endif ,in vec2 vReflectionInfos ,in vec3 viewDirectionW ,in float diffuseRoughness ,in vec3 surfaceAlbedo ) {vec3 environmentIrradiance=vec3(0.,0.,0.); #if (defined(USESPHERICALFROMREFLECTIONMAP) && (!defined(NORMAL) || !defined(USESPHERICALINVERTEX))) || (defined(USEIRRADIANCEMAP) && defined(REFLECTIONMAP_3D)) vec3 irradianceVector=(iblMatrix*vec4(surfaceNormal,0)).xyz;vec3 irradianceView=(iblMatrix*vec4(viewDirectionW,0)).xyz; #if !defined(USE_IRRADIANCE_DOMINANT_DIRECTION) && !defined(REALTIME_FILTERING) #if BASE_DIFFUSE_MODEL != BRDF_DIFFUSE_MODEL_LAMBERT && BASE_DIFFUSE_MODEL != BRDF_DIFFUSE_MODEL_LEGACY {float NdotV=max(dot(surfaceNormal,viewDirectionW),0.0);irradianceVector=mix(irradianceVector,irradianceView,(0.5*(1.0-NdotV))*diffuseRoughness);} #endif #endif #ifdef REFLECTIONMAP_OPPOSITEZ irradianceVector.z*=-1.0;irradianceView.z*=-1.0; #endif #ifdef INVERTCUBICMAP irradianceVector.y*=-1.0;irradianceView.y*=-1.0; #endif #endif #ifdef USESPHERICALFROMREFLECTIONMAP #if defined(NORMAL) && defined(USESPHERICALINVERTEX) environmentIrradiance=vEnvironmentIrradianceSH; #else #if defined(REALTIME_FILTERING) environmentIrradiance=irradiance(reflectionSampler,irradianceVector,vReflectionFilteringInfo,diffuseRoughness,surfaceAlbedo,irradianceView #ifdef IBL_CDF_FILTERING ,icdfSampler #endif ); #else environmentIrradiance=computeEnvironmentIrradiance(irradianceVector); #endif #endif #elif defined(USEIRRADIANCEMAP) #ifdef REFLECTIONMAP_3D vec4 environmentIrradianceFromTexture=sampleReflection(irradianceSampler,irradianceVector); #else vec4 environmentIrradianceFromTexture=sampleReflection(irradianceSampler,reflectionCoords); #endif environmentIrradiance=environmentIrradianceFromTexture.rgb; #ifdef RGBDREFLECTION environmentIrradiance.rgb=fromRGBD(environmentIrradianceFromTexture); #endif #ifdef GAMMAREFLECTION environmentIrradiance.rgb=toLinearSpace(environmentIrradiance.rgb); #endif #ifdef USE_IRRADIANCE_DOMINANT_DIRECTION vec3 Ls=normalize(reflectionDominantDirection);float NoL=dot(irradianceVector,Ls);float NoV=dot(irradianceVector,irradianceView);vec3 diffuseRoughnessTerm=vec3(1.0); #if BASE_DIFFUSE_MODEL==BRDF_DIFFUSE_MODEL_EON float LoV=dot (Ls,irradianceView);float mag=length(reflectionDominantDirection)*2.0;vec3 clampedAlbedo=clamp(surfaceAlbedo,vec3(0.1),vec3(1.0));diffuseRoughnessTerm=diffuseBRDF_EON(clampedAlbedo,diffuseRoughness,NoL,NoV,LoV)*PI;diffuseRoughnessTerm=diffuseRoughnessTerm/clampedAlbedo;diffuseRoughnessTerm=mix(vec3(1.0),diffuseRoughnessTerm,sqrt(clamp(mag*NoV,0.0,1.0))); #elif BASE_DIFFUSE_MODEL==BRDF_DIFFUSE_MODEL_BURLEY vec3 H=(irradianceView+Ls)*0.5;float VoH=dot(irradianceView,H);diffuseRoughnessTerm=vec3(diffuseBRDF_Burley(NoL,NoV,VoH,diffuseRoughness)*PI); #endif environmentIrradiance=environmentIrradiance.rgb*diffuseRoughnessTerm; #endif #endif environmentIrradiance*=vReflectionInfos.x;return environmentIrradiance;} #define pbr_inline #ifdef REFLECTIONMAP_3D vec3 createReflectionCoords( #else vec2 createReflectionCoords( #endif in vec3 vPositionW ,in vec3 normalW ) {vec3 reflectionVector=computeReflectionCoords(vec4(vPositionW,1.0),normalW); #ifdef REFLECTIONMAP_OPPOSITEZ reflectionVector.z*=-1.0; #endif #ifdef REFLECTIONMAP_3D vec3 reflectionCoords=reflectionVector; #else vec2 reflectionCoords=reflectionVector.xy; #ifdef REFLECTIONMAP_PROJECTION reflectionCoords/=reflectionVector.z; #endif reflectionCoords.y=1.0-reflectionCoords.y; #endif return reflectionCoords;} #define pbr_inline #define inline vec3 sampleRadiance( in float alphaG ,in vec3 vReflectionMicrosurfaceInfos ,in vec2 vReflectionInfos ,in geometryInfoOutParams geoInfo #ifdef REFLECTIONMAP_3D ,in samplerCube reflectionSampler ,const vec3 reflectionCoords #else ,in sampler2D reflectionSampler ,const vec2 reflectionCoords #endif #ifdef REALTIME_FILTERING ,in vec2 vReflectionFilteringInfo #endif ) {vec4 environmentRadiance=vec4(0.,0.,0.,0.); #if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX) float reflectionLOD=getLodFromAlphaG(vReflectionMicrosurfaceInfos.x,alphaG,geoInfo.NdotVUnclamped); #elif defined(LINEARSPECULARREFLECTION) float reflectionLOD=getLinearLodFromRoughness(vReflectionMicrosurfaceInfos.x,roughness); #else float reflectionLOD=getLodFromAlphaG(vReflectionMicrosurfaceInfos.x,alphaG); #endif reflectionLOD=reflectionLOD*vReflectionMicrosurfaceInfos.y+vReflectionMicrosurfaceInfos.z; #ifdef REALTIME_FILTERING environmentRadiance=vec4(radiance(alphaG,reflectionSampler,reflectionCoords,vReflectionFilteringInfo),1.0); #else environmentRadiance=sampleReflectionLod(reflectionSampler,reflectionCoords,reflectionLOD); #endif #ifdef RGBDREFLECTION environmentRadiance.rgb=fromRGBD(environmentRadiance); #endif #ifdef GAMMAREFLECTION environmentRadiance.rgb=toLinearSpace(environmentRadiance.rgb); #endif environmentRadiance.rgb*=vec3(vReflectionInfos.x);return environmentRadiance.rgb;} #if defined(ANISOTROPIC) #define pbr_inline #define inline vec3 sampleRadianceAnisotropic( in float alphaG ,in vec3 vReflectionMicrosurfaceInfos ,in vec2 vReflectionInfos ,in geometryInfoAnisoOutParams geoInfo ,const vec3 normalW ,const vec3 viewDirectionW ,const vec3 positionW ,const vec3 noise ,bool isRefraction ,float ior #ifdef REFLECTIONMAP_3D ,in samplerCube reflectionSampler #else ,in sampler2D reflectionSampler #endif #ifdef REALTIME_FILTERING ,in vec2 vReflectionFilteringInfo #endif ) {vec4 environmentRadiance=vec4(0.,0.,0.,0.);float alphaT=alphaG*sqrt(2.0/(1.0+(1.0-geoInfo.anisotropy)*(1.0-geoInfo.anisotropy)));float alphaB=(1.0-geoInfo.anisotropy)*alphaT;alphaG=alphaB; #if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX) float reflectionLOD=getLodFromAlphaG(vReflectionMicrosurfaceInfos.x,alphaG,geoInfo.NdotVUnclamped); #elif defined(LINEARSPECULARREFLECTION) float reflectionLOD=getLinearLodFromRoughness(vReflectionMicrosurfaceInfos.x,roughness); #else float reflectionLOD=getLodFromAlphaG(vReflectionMicrosurfaceInfos.x,alphaG); #endif reflectionLOD=reflectionLOD*vReflectionMicrosurfaceInfos.y+vReflectionMicrosurfaceInfos.z; #ifdef REALTIME_FILTERING vec3 view=(reflectionMatrix*vec4(viewDirectionW,0.0)).xyz;vec3 tangent=(reflectionMatrix*vec4(geoInfo.anisotropicTangent,0.0)).xyz;vec3 bitangent=(reflectionMatrix*vec4(geoInfo.anisotropicBitangent,0.0)).xyz;vec3 normal=(reflectionMatrix*vec4(normalW,0.0)).xyz; #ifdef REFLECTIONMAP_OPPOSITEZ view.z*=-1.0;tangent.z*=-1.0;bitangent.z*=-1.0;normal.z*=-1.0; #endif environmentRadiance = vec4(radianceAnisotropic(alphaT,alphaB,reflectionSampler, view,tangent, bitangent,normal, vReflectionFilteringInfo,noise.xy,isRefraction,ior), 1.0); #else const int samples=16;vec4 radianceSample=vec4(0.0);vec3 reflectionCoords=vec3(0.0);float sample_weight=0.0;float total_weight=0.0;float step=1.0/float(max(samples-1,1));for (int i=0; i<samples; ++i) {float t=mix(-1.0,1.0,float(i)*step);t+=step*2.0*noise.x;sample_weight=max(1.0-abs(t),0.001);sample_weight*=sample_weight;t*=min(4.0*alphaT*geoInfo.anisotropy,1.0);vec3 bentNormal;if (t<0.0) {float blend=t+1.0;bentNormal=normalize(mix(-geoInfo.anisotropicTangent,normalW,blend));} else if (t>0.0) {float blend=t;bentNormal=normalize(mix(normalW,geoInfo.anisotropicTangent,blend));} else {bentNormal=normalW;} if (isRefraction) {reflectionCoords=double_refract(-viewDirectionW,bentNormal,ior);} else {reflectionCoords=reflect(-viewDirectionW,bentNormal);} reflectionCoords=vec3(reflectionMatrix*vec4(reflectionCoords,0)); #ifdef REFLECTIONMAP_OPPOSITEZ reflectionCoords.z*=-1.0; #endif radianceSample=sampleReflectionLod(reflectionSampler,reflectionCoords,reflectionLOD); #ifdef RGBDREFLECTION environmentRadiance.rgb+=sample_weight*fromRGBD(radianceSample); #elif defined(GAMMAREFLECTION) environmentRadiance.rgb+=sample_weight*toLinearSpace(radianceSample.rgb); #else environmentRadiance.rgb+=sample_weight*radianceSample.rgb; #endif total_weight+=sample_weight;} environmentRadiance=vec4(environmentRadiance.xyz/float(total_weight),1.0); #endif environmentRadiance.rgb*=vec3(vReflectionInfos.x);return environmentRadiance.rgb;} #endif #endif #if defined(ENVIRONMENTBRDF) #define pbr_inline float computeDielectricIblFresnel(in ReflectanceParams reflectance,in vec3 environmentBrdf) {float dielectricIblFresnel=getReflectanceFromBRDFLookup(vec3(reflectance.F0),vec3(reflectance.F90),environmentBrdf).r;float dielectricECF=1.0+reflectance.F0*(1.0/environmentBrdf.y-1.0);return clamp(dielectricIblFresnel*dielectricECF,0.0,1.0);} #define pbr_inline vec3 computeConductorIblFresnel(in ReflectanceParams reflectance,in vec3 environmentBrdf) { #if (CONDUCTOR_SPECULAR_MODEL==CONDUCTOR_SPECULAR_MODEL_OPENPBR) && defined(ENVIRONMENTBRDF) vec3 openPBRBrdf=vec3(environmentBrdf.xy,environmentBrdf.z/BRDF_Z_SCALE);vec3 b =getF82B(reflectance.coloredF0,reflectance.coloredF90);vec3 E_F82=getF82DirectionalAlbedo(reflectance.coloredF0,vec3(1.0),b,openPBRBrdf);vec3 F_avg=getF82AverageFresnel(reflectance.coloredF0,b);vec3 ECF =vec3(1.0)+F_avg*(vec3(1.0)/openPBRBrdf.y-vec3(1.0));return clamp(E_F82*ECF,vec3(0.0),vec3(1.0)); #else return getReflectanceFromBRDFLookup(reflectance.coloredF0,reflectance.coloredF90,environmentBrdf); #endif } #endif `; // Sideeffect if (!ShaderStore.IncludesShadersStore[name$2]) { ShaderStore.IncludesShadersStore[name$2] = shader$2; } /** @internal */ const openpbrIblFunctions = { name: name$2, shader: shader$2 }; // Do not edit. const name$1 = "openpbrSubsurfaceLayerData"; const shader$1 = `float subsurface_weight=vSubsurfaceWeight;vec3 subsurface_color=vSubsurfaceColor.rgb;float subsurface_radius=vSubsurfaceRadius;vec3 subsurface_radius_scale=vSubsurfaceRadiusScale;float subsurface_scatter_anisotropy=clamp(vSubsurfaceScatterAnisotropy,-0.9999,0.9999); #ifdef SUBSURFACE_WEIGHT vec4 subsurfaceWeightFromTexture=TEXRD(subsurfaceWeightSampler,vSubsurfaceWeightUV+uvOffset); #endif #ifdef SUBSURFACE_COLOR vec4 subsurfaceColorFromTexture=TEXRD(subsurfaceColorSampler,vSubsurfaceColorUV+uvOffset); #endif #ifdef SUBSURFACE_RADIUS_SCALE vec4 subsurfaceRadiusScaleFromTexture=TEXRD(subsurfaceRadiusScaleSampler,vSubsurfaceRadiusScaleUV+uvOffset); #endif #ifdef SUBSURFACE_WEIGHT #ifdef SUBSURFACE_WEIGHT_FROM_TEXTURE_ALPHA subsurface_weight*=subsurfaceWeightFromTexture.a; #else subsurface_weight*=subsurfaceWeightFromTexture.r; #endif #endif #ifdef SUBSURFACE_COLOR #ifdef SUBSURFACE_COLOR_GAMMA subsurface_color*=toLinearSpace(subsurfaceColorFromTexture.rgb); #else subsurface_color*=subsurfaceColorFromTexture.rgb; #endif subsurface_color*=vSubsurfaceColorInfos.y; #endif #ifdef SUBSURFACE_RADIUS_SCALE subsurface_radius_scale*=subsurfaceRadiusScaleFromTexture.rgb; #endif `; // Sideeffect if (!ShaderStore.IncludesShadersStore[name$1]) { ShaderStore.IncludesShadersStore[name$1] = shader$1; } /** @internal */ const openpbrSubsurfaceLayerData = { name: name$1, shader: shader$1 }; // Do not edit. const name = "openpbrTransmissionLayerData"; const shader = `float transmission_weight=vTransmissionWeight;vec3 transmission_color=vTransmissionColor.rgb;float transmission_depth=vTransmissionDepth;vec3 transmission_scatter=vTransmissionScatter.rgb;float transmission_scatter_anisotropy=clamp(vTransmissionScatterAnisotropy,-0.9999,0.9999);float transmission_dispersion_scale=vTransmissionDispersionScale;float transmission_dispersion_abbe_number=vTransmissionDispersionAbbeNumber; #ifdef TRANSMISSION_WEIGHT vec4 transmissionWeightFromTexture=TEXRD(transmissionWeightSampler,vTransmissionWeightUV+uvOffset); #endif #ifdef TRANSMISSION_COLOR vec4 transmissionColorFromTexture=TEXRD(transmissionColorSampler,vTransmissionColorUV+uvOffset); #endif #ifdef TRANSMISSION_DEPTH vec4 transmissionDepthFromTexture=TEXRD(transmissionDepthSampler,vTransmissionDepthUV+uvOffset); #endif #ifdef TRANSMISSION_SCATTER vec4 transmissionScatterFromTexture=TEXRD(transmissionScatterSampler,vTransmissionScatterUV+uvOffset); #endif #ifdef TRANSMISSION_DISPERSION_SCALE vec4 transmissionDispersionScaleFromTexture=TEXRD(transmissionDispersionScaleSampler,vTransmissionDispersionScaleUV+uvOffset); #endif #ifdef TRANSMISSION_WEIGHT transmission_weight*=transmissionWeightFromTexture.r; #endif #ifdef TRANSMISSION_COLOR #ifdef TRANSMISSION_COLOR_GAMMA transmission_color*=toLinearSpace(transmissionColorFromTexture.rgb); #else transmission_color*=transmissionColorFromTexture.rgb; #endif transmission_color*=vTransmissionColorInfos.y; #endif #ifdef TRANSMISSION_DEPTH transmission_depth*=transmissionDepthFromTexture.r; #endif #ifdef TRANSMISSION_SCATTER transmission_scatter*=transmissionScatterFromTexture.rgb; #endif #ifdef TRANSMISSION_DISPERSION_SCALE transmission_dispersion_scale*=transmissionDispersionScaleFromTexture.r; #endif `; // Sideeffect if (!ShaderStore.IncludesShadersStore[name]) { ShaderStore.IncludesShadersStore[name] = shader; } /** @internal */ const openpbrTransmissionLayerData = { name, shader }; export { openpbrGeometryInfo as a, openpbrIblFunctions as b, openpbrSubsurfaceLayerData as c, openpbrTransmissionLayerData as d, openpbrDielectricReflectance as o, sceneFragmentDeclaration as s }; //# sourceMappingURL=openpbrTransmissionLayerData-BO64I2B5.esm.js.map