@babylonjs/core
Version:
Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.
305 lines • 19.6 kB
JavaScript
// Do not edit.
import { ShaderStore } from "../Engines/shaderStore.js";
import { prePassDeclarationWGSL } from "./ShadersInclude/prePassDeclaration.js";
import { oitDeclarationWGSL } from "./ShadersInclude/oitDeclaration.js";
import { sceneUboDeclarationWGSL } from "./ShadersInclude/sceneUboDeclaration.js";
import { meshUboDeclarationWGSL } from "./ShadersInclude/meshUboDeclaration.js";
import { openpbrUboDeclarationWGSL } from "./ShadersInclude/openpbrUboDeclaration.js";
import { mainUVVaryingDeclarationWGSL } from "./ShadersInclude/mainUVVaryingDeclaration.js";
import { pbrFragmentExtraDeclarationWGSL } from "./ShadersInclude/pbrFragmentExtraDeclaration.js";
import { lightUboDeclarationWGSL } from "./ShadersInclude/lightUboDeclaration.js";
import { samplerFragmentDeclarationWGSL } from "./ShadersInclude/samplerFragmentDeclaration.js";
import { pbrFragmentReflectionDeclarationWGSL } from "./ShadersInclude/pbrFragmentReflectionDeclaration.js";
import { openpbrFragmentSamplersDeclarationWGSL } from "./ShadersInclude/openpbrFragmentSamplersDeclaration.js";
import { imageProcessingDeclarationWGSL } from "./ShadersInclude/imageProcessingDeclaration.js";
import { clipPlaneFragmentDeclarationWGSL } from "./ShadersInclude/clipPlaneFragmentDeclaration.js";
import { logDepthDeclarationWGSL } from "./ShadersInclude/logDepthDeclaration.js";
import { fogFragmentDeclarationWGSL } from "./ShadersInclude/fogFragmentDeclaration.js";
import { textureRepetitionFunctionsWGSL } from "./ShadersInclude/textureRepetitionFunctions.js";
import { helperFunctionsWGSL } from "./ShadersInclude/helperFunctions.js";
import { subSurfaceScatteringFunctionsWGSL } from "./ShadersInclude/subSurfaceScatteringFunctions.js";
import { importanceSamplingWGSL } from "./ShadersInclude/importanceSampling.js";
import { pbrHelperFunctionsWGSL } from "./ShadersInclude/pbrHelperFunctions.js";
import { imageProcessingFunctionsWGSL } from "./ShadersInclude/imageProcessingFunctions.js";
import { shadowsFragmentFunctionsWGSL } from "./ShadersInclude/shadowsFragmentFunctions.js";
import { harmonicsFunctionsWGSL } from "./ShadersInclude/harmonicsFunctions.js";
import { ltcHelperFunctionsWGSL } from "./ShadersInclude/ltcHelperFunctions.js";
import { pbrDirectLightingSetupFunctionsWGSL } from "./ShadersInclude/pbrDirectLightingSetupFunctions.js";
import { pbrDirectLightingFalloffFunctionsWGSL } from "./ShadersInclude/pbrDirectLightingFalloffFunctions.js";
import { pbrBRDFFunctionsWGSL } from "./ShadersInclude/pbrBRDFFunctions.js";
import { hdrFilteringFunctionsWGSL } from "./ShadersInclude/hdrFilteringFunctions.js";
import { clusteredLightingFunctionsWGSL } from "./ShadersInclude/clusteredLightingFunctions.js";
import { pbrBlockReflectance0WGSL } from "./ShadersInclude/pbrBlockReflectance0.js";
import { pbrDirectLightingFunctionsWGSL } from "./ShadersInclude/pbrDirectLightingFunctions.js";
import { pbrIBLFunctionsWGSL } from "./ShadersInclude/pbrIBLFunctions.js";
import { openpbrNormalMapFragmentMainFunctionsWGSL } from "./ShadersInclude/openpbrNormalMapFragmentMainFunctions.js";
import { openpbrNormalMapFragmentFunctionsWGSL } from "./ShadersInclude/openpbrNormalMapFragmentFunctions.js";
import { reflectionFunctionWGSL } from "./ShadersInclude/reflectionFunction.js";
import { openpbrDielectricReflectanceWGSL } from "./ShadersInclude/openpbrDielectricReflectance.js";
import { openpbrConductorReflectanceWGSL } from "./ShadersInclude/openpbrConductorReflectance.js";
import { openpbrAmbientOcclusionFunctionsWGSL } from "./ShadersInclude/openpbrAmbientOcclusionFunctions.js";
import { openpbrGeometryInfoWGSL } from "./ShadersInclude/openpbrGeometryInfo.js";
import { openpbrIblFunctionsWGSL } from "./ShadersInclude/openpbrIblFunctions.js";
import { openpbrVolumeFunctionsWGSL } from "./ShadersInclude/openpbrVolumeFunctions.js";
import { clipPlaneFragmentWGSL } from "./ShadersInclude/clipPlaneFragment.js";
import { pbrBlockNormalGeometricWGSL } from "./ShadersInclude/pbrBlockNormalGeometric.js";
import { openpbrNormalMapFragmentWGSL } from "./ShadersInclude/openpbrNormalMapFragment.js";
import { openpbrBlockNormalFinalWGSL } from "./ShadersInclude/openpbrBlockNormalFinal.js";
import { openpbrBaseLayerDataWGSL } from "./ShadersInclude/openpbrBaseLayerData.js";
import { openpbrTransmissionLayerDataWGSL } from "./ShadersInclude/openpbrTransmissionLayerData.js";
import { openpbrSubsurfaceLayerDataWGSL } from "./ShadersInclude/openpbrSubsurfaceLayerData.js";
import { openpbrCoatLayerDataWGSL } from "./ShadersInclude/openpbrCoatLayerData.js";
import { openpbrThinFilmLayerDataWGSL } from "./ShadersInclude/openpbrThinFilmLayerData.js";
import { openpbrFuzzLayerDataWGSL } from "./ShadersInclude/openpbrFuzzLayerData.js";
import { openpbrAmbientOcclusionDataWGSL } from "./ShadersInclude/openpbrAmbientOcclusionData.js";
import { depthPrePassWGSL } from "./ShadersInclude/depthPrePass.js";
import { openpbrBackgroundTransmissionWGSL } from "./ShadersInclude/openpbrBackgroundTransmission.js";
import { openpbrEnvironmentLightingWGSL } from "./ShadersInclude/openpbrEnvironmentLighting.js";
import { openpbrDirectLightingInitWGSL } from "./ShadersInclude/openpbrDirectLightingInit.js";
import { openpbrDirectLightingWGSL } from "./ShadersInclude/openpbrDirectLighting.js";
import { logDepthFragmentWGSL } from "./ShadersInclude/logDepthFragment.js";
import { fogFragmentWGSL } from "./ShadersInclude/fogFragment.js";
import { pbrBlockImageProcessingWGSL } from "./ShadersInclude/pbrBlockImageProcessing.js";
import { openpbrBlockPrePassWGSL } from "./ShadersInclude/openpbrBlockPrePass.js";
import { oitFragmentWGSL } from "./ShadersInclude/oitFragment.js";
import { pbrDebugWGSL } from "./ShadersInclude/pbrDebug.js";
const name = "openpbrPixelShader";
const shader = `
fn layer(slab_bottom: vec3f,slab_top: vec3f,lerp_factor: f32,bottom_multiplier: vec3f,top_multiplier: vec3f)->vec3f {return mix(slab_bottom*bottom_multiplier,slab_top*top_multiplier,lerp_factor);}
@fragment
fn main(input: FragmentInputs)->FragmentOutputs {
var total_direct_diffuse: vec3f=vec3f(0.0f);
var coatNormalW: vec3f=normalW;
let coatGeoInfo: geometryInfoAnisoOutParams=geometryInfoAniso(
coatNormalW,viewDirectionW.xyz,coat_roughness,geometricNormalW
,vec3f(geometry_coat_tangent.x,geometry_coat_tangent.y,coat_roughness_anisotropy),TBN
);
let coatGeoInfo: geometryInfoOutParams=geometryInfo(
coatNormalW,viewDirectionW.xyz,coat_roughness,geometricNormalW
);
specular_roughness=mix(specular_roughness,pow(min(1.0f,pow(specular_roughness,4.0f)+2.0f*pow(coat_roughness,4.0f)),0.25f),coat_weight);
let baseGeoInfo: geometryInfoAnisoOutParams=geometryInfoAniso(
normalW,viewDirectionW.xyz,specular_roughness,geometricNormalW
,vec3f(geometry_tangent.x,geometry_tangent.y,specular_roughness_anisotropy),TBN
);
let baseGeoInfo: geometryInfoOutParams=geometryInfo(
normalW,viewDirectionW.xyz,specular_roughness,geometricNormalW
);
let fuzzNormalW=normalize(mix(normalW,coatNormalW,coat_weight));var fuzzTangent=normalize(TBN[0]);fuzzTangent=normalize(fuzzTangent-dot(fuzzTangent,fuzzNormalW)*fuzzNormalW);let fuzzBitangent=cross(fuzzNormalW,fuzzTangent);let fuzzGeoInfo: geometryInfoOutParams=geometryInfo(
fuzzNormalW,viewDirectionW.xyz,fuzz_roughness,geometricNormalW
);
let coatReflectance: ReflectanceParams=dielectricReflectance(
coat_ior
,1.0f
,vec3f(1.0f)
,coat_weight
);
let thin_film_outside_ior: f32=mix(1.0f,coat_ior,coat_weight);
let baseDielectricReflectance: ReflectanceParams=dielectricReflectance(
specular_ior
,mix(1.0f,coat_ior,coat_weight)
,specular_color
,specular_weight
);let baseConductorReflectance: ReflectanceParams=conductorReflectance(base_color,specular_color,specular_weight);var volume_absorption: vec3f=vec3f(1.0f);var transmission_tint: vec3f=vec3f(1.0f);var surface_translucency_weight: f32=0.0f;
let refractedViewVector: vec3f=-viewDirectionW;
var refractedViewVectors: array<vec3f,3>;let iorDispersionSpread: f32=transmission_dispersion_scale/transmission_dispersion_abbe_number*(specular_ior-1.0f);let dispersion_iors: vec3f=vec3f(specular_ior-iorDispersionSpread,specular_ior,specular_ior+iorDispersionSpread);for (var i: i32=0; i<3; i++) {refractedViewVectors[i]=double_refract(-viewDirectionW,normalW,dispersion_iors[i]); }
let refractedViewVector: vec3f=double_refract(-viewDirectionW,normalW,specular_ior);
var transmission_roughness: f32=specular_roughness;
var transmission_roughness: f32=specular_roughness*clamp(4.0f*(specular_ior-1.0f),0.001f,1.0f);
var volumeParams: OpenPBRHomogeneousVolume;{
let transmissionVolumeParams: OpenPBRHomogeneousVolume=computeOpenPBRTransmissionVolume(
transmission_color.rgb,
transmission_depth,
transmission_scatter.rgb,
transmission_scatter_anisotropy
);
let subsurfaceVolumeParams: OpenPBRHomogeneousVolume=computeOpenPBRSubsurfaceVolume(
subsurface_color.rgb,
subsurface_radius,
subsurface_radius_scale.rgb,
subsurface_scatter_anisotropy
);
volumeParams=subsurfaceVolumeParams;surface_translucency_weight=subsurface_weight;
volumeParams=transmissionVolumeParams;
volumeParams.multi_scatter_color=singleScatterToMultiScatterAlbedo(volumeParams.ss_albedo);
surface_translucency_weight=transmission_weight;
let subsurface_fraction_of_dielectric: f32=(1.0f-transmission_weight)*subsurface_weight;let subsurface_and_transmission_fraction_of_dielectric: f32=subsurface_fraction_of_dielectric+transmission_weight;let reciprocal_of_subsurface_and_transmission_fraction_of_dielectric: f32 =
1.0f/maxEps(subsurface_and_transmission_fraction_of_dielectric);let trans_weight: f32=transmission_weight*reciprocal_of_subsurface_and_transmission_fraction_of_dielectric;let subsurf_weight: f32=subsurface_fraction_of_dielectric*reciprocal_of_subsurface_and_transmission_fraction_of_dielectric;volumeParams.scatter_coeff=transmissionVolumeParams.scatter_coeff*trans_weight+subsurfaceVolumeParams.scatter_coeff*subsurf_weight;volumeParams.absorption_coeff=transmissionVolumeParams.absorption_coeff*trans_weight+subsurfaceVolumeParams.absorption_coeff*subsurf_weight;volumeParams.anisotropy=(transmissionVolumeParams.anisotropy*trans_weight+subsurfaceVolumeParams.anisotropy*subsurf_weight)/maxEps(trans_weight+subsurf_weight);volumeParams.extinction_coeff=volumeParams.absorption_coeff+volumeParams.scatter_coeff;volumeParams.ss_albedo=volumeParams.scatter_coeff/maxEpsVec3(volumeParams.extinction_coeff);volumeParams.multi_scatter_color=singleScatterToMultiScatterAlbedo(volumeParams.ss_albedo);surface_translucency_weight=subsurface_and_transmission_fraction_of_dielectric;
}
volume_absorption=exp(-volumeParams.absorption_coeff*geometry_thickness);var backscatter_color: vec3f=vec3f(1.0f);{let reduced_scatter: vec3f=volumeParams.scatter_coeff*vec3f(1.0f-volumeParams.anisotropy);let reduced_albedo: vec3f=reduced_scatter/(volumeParams.absorption_coeff+reduced_scatter);let sqrt_term: vec3f=max(sqrt(vec3f(1.0f)-reduced_albedo),vec3f(0.0001f));backscatter_color=(vec3f(1.0f)-sqrt_term)/(vec3f(1.0f)+sqrt_term);}
surface_translucency_weight=transmission_weight;
var iso_scatter_density: vec3f=vec3f(1.0f);
let mfp: vec3f=vec3f(100.0f)/volumeParams.extinction_coeff;var scattered_light_from_irradiance_texture: vec3f=sss_convolve(sceneIrradianceSampler,sceneDepthSampler,uniforms.renderTargetSize,mfp,scene.projection,scene.inverseProjection,SSS_SAMPLE_COUNT,noise.xy);var numLights=f32(LIGHTCOUNT);
numLights+=1.0f;
scattered_light_from_irradiance_texture/=vec3f(numLights);
let scattered_light_from_irradiance_texture: vec3f=vec3f(0.0f);
let back_to_iso_scattering_blend: f32=min(1.0f+volumeParams.anisotropy,1.0f);let iso_to_forward_scattering_blend: f32=max(volumeParams.anisotropy,0.0f);let iso_scatter_transmittance: vec3f=pow(exp(-volumeParams.scatter_coeff*geometry_thickness),vec3f(0.2f));var iso_scatter_density: vec3f=clamp(vec3f(1.0f)-iso_scatter_transmittance,vec3f(0.0f),vec3f(1.0f));transmission_roughness=min(transmission_roughness+pow((1.0f-abs(volumeParams.anisotropy))*max3(iso_scatter_density*iso_scatter_density),3.0f),1.0f);
volumeParams.multi_scatter_color=mix(volumeParams.ss_albedo,volumeParams.multi_scatter_color,max3(iso_scatter_density));
transmission_tint*=transmission_color.rgb;
var sin2: f32=1.0f-baseGeoInfo.NdotV*baseGeoInfo.NdotV;sin2=sin2/(specular_ior*specular_ior);let cos_t: f32=sqrt(1.0f-sin2);let pathLength: f32=1.0f/cos_t;transmission_tint=pow(transmission_tint,vec3f(pathLength));
transmission_tint*=transmission_color.rgb;
let unweighted_translucency: f32=max(mix(subsurface_weight,1.0f,transmission_weight),0.0001f);transmission_tint=mix(vec3f(1.0f),transmission_tint,transmission_weight/unweighted_translucency);transmission_roughness=mix(1.0f,transmission_roughness,transmission_weight/unweighted_translucency);
let transmission_roughness_alpha: f32=transmission_roughness*transmission_roughness;
var material_surface_ibl: vec3f=vec3f(0.f,0.f,0.f);
var material_surface_direct: vec3f=vec3f(0.f,0.f,0.f);
var aggShadow: f32=0.f;
var material_surface_emission: vec3f=uniforms.vEmissionColor;
let emissionColorTex: vec3f=textureSample(emissionColorSampler,emissionColorSamplerSampler,fragmentInputs.vEmissionColorUV+uvOffset).rgb;
material_surface_emission*=toLinearSpaceVec3(emissionColorTex.rgb);
material_surface_emission*=emissionColorTex.rgb;
material_surface_emission*= uniforms.vEmissionColorInfos.y;
material_surface_emission*=uniforms.vLightingIntensity.y;
var finalColor: vec4f=vec4f(material_surface_ibl+material_surface_direct+material_surface_emission,alpha);
finalColor=max(finalColor,vec4f(0.0));
fragmentOutputs.color=finalColor;
if (fragDepth==nearestDepth) {fragmentOutputs.frontColor=vec4f(fragmentOutputs.frontColor.rgb+finalColor.rgb*finalColor.a*alphaMultiplier,1.0-alphaMultiplier*(1.0-finalColor.a));} else {fragmentOutputs.backColor+=finalColor;}
}
`;
// Sideeffect
if (!ShaderStore.ShadersStoreWGSL[name]) {
ShaderStore.ShadersStoreWGSL[name] = shader;
}
const includes = [prePassDeclarationWGSL, oitDeclarationWGSL, sceneUboDeclarationWGSL, meshUboDeclarationWGSL, openpbrUboDeclarationWGSL, mainUVVaryingDeclarationWGSL, pbrFragmentExtraDeclarationWGSL, lightUboDeclarationWGSL, samplerFragmentDeclarationWGSL, pbrFragmentReflectionDeclarationWGSL, openpbrFragmentSamplersDeclarationWGSL, imageProcessingDeclarationWGSL, clipPlaneFragmentDeclarationWGSL, logDepthDeclarationWGSL, fogFragmentDeclarationWGSL, textureRepetitionFunctionsWGSL, helperFunctionsWGSL, subSurfaceScatteringFunctionsWGSL, importanceSamplingWGSL, pbrHelperFunctionsWGSL, imageProcessingFunctionsWGSL, shadowsFragmentFunctionsWGSL, harmonicsFunctionsWGSL, ltcHelperFunctionsWGSL, pbrDirectLightingSetupFunctionsWGSL, pbrDirectLightingFalloffFunctionsWGSL, pbrBRDFFunctionsWGSL, hdrFilteringFunctionsWGSL, clusteredLightingFunctionsWGSL, pbrBlockReflectance0WGSL, pbrDirectLightingFunctionsWGSL, pbrIBLFunctionsWGSL, openpbrNormalMapFragmentMainFunctionsWGSL, openpbrNormalMapFragmentFunctionsWGSL, reflectionFunctionWGSL, openpbrDielectricReflectanceWGSL, openpbrConductorReflectanceWGSL, openpbrAmbientOcclusionFunctionsWGSL, openpbrGeometryInfoWGSL, openpbrIblFunctionsWGSL, openpbrVolumeFunctionsWGSL, clipPlaneFragmentWGSL, pbrBlockNormalGeometricWGSL, openpbrNormalMapFragmentWGSL, openpbrBlockNormalFinalWGSL, openpbrBaseLayerDataWGSL, openpbrTransmissionLayerDataWGSL, openpbrSubsurfaceLayerDataWGSL, openpbrCoatLayerDataWGSL, openpbrThinFilmLayerDataWGSL, openpbrFuzzLayerDataWGSL, openpbrAmbientOcclusionDataWGSL, depthPrePassWGSL, openpbrBackgroundTransmissionWGSL, openpbrEnvironmentLightingWGSL, openpbrDirectLightingInitWGSL, openpbrDirectLightingWGSL, logDepthFragmentWGSL, fogFragmentWGSL, pbrBlockImageProcessingWGSL, openpbrBlockPrePassWGSL, oitFragmentWGSL, pbrDebugWGSL];
for (const inc of includes) {
if (!ShaderStore.IncludesShadersStoreWGSL[inc.name]) {
ShaderStore.IncludesShadersStoreWGSL[inc.name] = inc.shader;
}
}
/** @internal */
export const openpbrPixelShaderWGSL = { name, shader };
//# sourceMappingURL=openpbr.fragment.js.map