UNPKG

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

303 lines 15.1 kB
// Do not edit. import { ShaderStore } from "../Engines/shaderStore.js"; import "./ShadersInclude/prePassDeclaration.js"; import "./ShadersInclude/oitDeclaration.js"; import "./ShadersInclude/openpbrFragmentDeclaration.js"; import "./ShadersInclude/openpbrUboDeclaration.js"; import "./ShadersInclude/pbrFragmentExtraDeclaration.js"; import "./ShadersInclude/lightFragmentDeclaration.js"; import "./ShadersInclude/lightUboDeclaration.js"; import "./ShadersInclude/openpbrFragmentSamplersDeclaration.js"; import "./ShadersInclude/imageProcessingDeclaration.js"; import "./ShadersInclude/clipPlaneFragmentDeclaration.js"; import "./ShadersInclude/logDepthDeclaration.js"; import "./ShadersInclude/fogFragmentDeclaration.js"; import "./ShadersInclude/helperFunctions.js"; import "./ShadersInclude/subSurfaceScatteringFunctions.js"; import "./ShadersInclude/importanceSampling.js"; import "./ShadersInclude/pbrHelperFunctions.js"; import "./ShadersInclude/imageProcessingFunctions.js"; import "./ShadersInclude/shadowsFragmentFunctions.js"; import "./ShadersInclude/harmonicsFunctions.js"; import "./ShadersInclude/pbrDirectLightingSetupFunctions.js"; import "./ShadersInclude/pbrDirectLightingFalloffFunctions.js"; import "./ShadersInclude/pbrBRDFFunctions.js"; import "./ShadersInclude/hdrFilteringFunctions.js"; import "./ShadersInclude/pbrDirectLightingFunctions.js"; import "./ShadersInclude/pbrIBLFunctions.js"; import "./ShadersInclude/openpbrNormalMapFragmentMainFunctions.js"; import "./ShadersInclude/openpbrNormalMapFragmentFunctions.js"; import "./ShadersInclude/reflectionFunction.js"; import "./ShadersInclude/openpbrDielectricReflectance.js"; import "./ShadersInclude/openpbrConductorReflectance.js"; import "./ShadersInclude/openpbrAmbientOcclusionFunctions.js"; import "./ShadersInclude/openpbrGeometryInfo.js"; import "./ShadersInclude/openpbrIblFunctions.js"; import "./ShadersInclude/openpbrVolumeFunctions.js"; import "./ShadersInclude/clipPlaneFragment.js"; import "./ShadersInclude/pbrBlockNormalGeometric.js"; import "./ShadersInclude/openpbrNormalMapFragment.js"; import "./ShadersInclude/openpbrBlockNormalFinal.js"; import "./ShadersInclude/openpbrBaseLayerData.js"; import "./ShadersInclude/openpbrTransmissionLayerData.js"; import "./ShadersInclude/openpbrSubsurfaceLayerData.js"; import "./ShadersInclude/openpbrCoatLayerData.js"; import "./ShadersInclude/openpbrThinFilmLayerData.js"; import "./ShadersInclude/openpbrFuzzLayerData.js"; import "./ShadersInclude/openpbrAmbientOcclusionData.js"; import "./ShadersInclude/depthPrePass.js"; import "./ShadersInclude/openpbrBackgroundTransmission.js"; import "./ShadersInclude/openpbrEnvironmentLighting.js"; import "./ShadersInclude/openpbrDirectLightingInit.js"; import "./ShadersInclude/openpbrDirectLighting.js"; import "./ShadersInclude/logDepthFragment.js"; import "./ShadersInclude/fogFragment.js"; import "./ShadersInclude/pbrBlockImageProcessing.js"; import "./ShadersInclude/openpbrBlockPrePass.js"; import "./ShadersInclude/oitFragment.js"; import "./ShadersInclude/pbrDebug.js"; const name = "openpbrPixelShader"; const shader = `#define OPENPBR_FRAGMENT_SHADER #define CUSTOM_FRAGMENT_EXTENSION #if defined(GEOMETRY_NORMAL) || defined(GEOMETRY_COAT_NORMAL) || !defined(NORMAL) || defined(FORCENORMALFORWARD) || defined(SPECULARAA) #extension GL_OES_standard_derivatives : enable #endif #ifdef LODBASEDMICROSFURACE #extension GL_EXT_shader_texture_lod : enable #endif #define CUSTOM_FRAGMENT_BEGIN #ifdef LOGARITHMICDEPTH #extension GL_EXT_frag_depth : enable #endif #include<prePassDeclaration>[SCENE_MRT_COUNT] precision highp float; #include<oitDeclaration> #ifndef FROMLINEARSPACE #define FROMLINEARSPACE #endif #include<__decl__openpbrFragment> #include<pbrFragmentExtraDeclaration> #include<__decl__lightFragment>[0..maxSimultaneousLights] #include<openpbrFragmentSamplersDeclaration> #include<imageProcessingDeclaration> #include<clipPlaneFragmentDeclaration> #include<logDepthDeclaration> #include<fogFragmentDeclaration> #include<helperFunctions> #include<subSurfaceScatteringFunctions> #include<importanceSampling> #include<pbrHelperFunctions> #include<imageProcessingFunctions> #include<shadowsFragmentFunctions> #include<harmonicsFunctions> #include<pbrDirectLightingSetupFunctions> #include<pbrDirectLightingFalloffFunctions> #include<pbrBRDFFunctions> #include<hdrFilteringFunctions> #include<pbrDirectLightingFunctions> #include<pbrIBLFunctions> #include<openpbrNormalMapFragmentMainFunctions> #include<openpbrNormalMapFragmentFunctions> #ifdef REFLECTION #include<reflectionFunction> #endif #define CUSTOM_FRAGMENT_DEFINITIONS #include<openpbrDielectricReflectance> #include<openpbrConductorReflectance> #include<openpbrAmbientOcclusionFunctions> #include<openpbrGeometryInfo> #include<openpbrIblFunctions> #include<openpbrVolumeFunctions> vec3 layer(vec3 slab_bottom,vec3 slab_top,float lerp_factor,vec3 bottom_multiplier,vec3 top_multiplier) {return mix(slab_bottom*bottom_multiplier,slab_top*top_multiplier,lerp_factor);} void main(void) { #ifdef PREPASS_IRRADIANCE vec3 total_direct_diffuse=vec3(0.0); #endif #define CUSTOM_FRAGMENT_MAIN_BEGIN #include<clipPlaneFragment> #include<pbrBlockNormalGeometric> vec3 coatNormalW=normalW; #include<openpbrNormalMapFragment> #include<openpbrBlockNormalFinal> #include<openpbrBaseLayerData> #include<openpbrTransmissionLayerData> #include<openpbrSubsurfaceLayerData> #include<openpbrCoatLayerData> #include<openpbrThinFilmLayerData> #include<openpbrFuzzLayerData> #include<openpbrAmbientOcclusionData> #define CUSTOM_FRAGMENT_UPDATE_ALPHA #include<depthPrePass> #define CUSTOM_FRAGMENT_BEFORE_LIGHTS #ifdef ANISOTROPIC_COAT geometryInfoAnisoOutParams coatGeoInfo=geometryInfoAniso( coatNormalW,viewDirectionW.xyz,coat_roughness,geometricNormalW ,vec3(geometry_coat_tangent.x,geometry_coat_tangent.y,coat_roughness_anisotropy),TBN ); #else geometryInfoOutParams coatGeoInfo=geometryInfo( coatNormalW,viewDirectionW.xyz,coat_roughness,geometricNormalW ); #endif specular_roughness=mix(specular_roughness,pow(min(1.0,pow(specular_roughness,4.0)+2.0*pow(coat_roughness,4.0)),0.25),coat_weight); #ifdef ANISOTROPIC_BASE geometryInfoAnisoOutParams baseGeoInfo=geometryInfoAniso( normalW,viewDirectionW.xyz,specular_roughness,geometricNormalW ,vec3(geometry_tangent.x,geometry_tangent.y,specular_roughness_anisotropy),TBN ); #else geometryInfoOutParams baseGeoInfo=geometryInfo( normalW,viewDirectionW.xyz,specular_roughness,geometricNormalW ); #endif #ifdef FUZZ vec3 fuzzNormalW=normalize(mix(normalW,coatNormalW,coat_weight));vec3 fuzzTangent=normalize(TBN[0]);fuzzTangent=normalize(fuzzTangent-dot(fuzzTangent,fuzzNormalW)*fuzzNormalW);vec3 fuzzBitangent=cross(fuzzNormalW,fuzzTangent);geometryInfoOutParams fuzzGeoInfo=geometryInfo( fuzzNormalW,viewDirectionW.xyz,fuzz_roughness,geometricNormalW ); #endif ReflectanceParams coatReflectance;coatReflectance=dielectricReflectance( coat_ior ,1.0 ,vec3(1.0) ,coat_weight ); #ifdef THIN_FILM float thin_film_outside_ior=mix(1.0,coat_ior,coat_weight); #endif ReflectanceParams baseDielectricReflectance;{float effectiveCoatIor=mix(1.0,coat_ior,coat_weight);baseDielectricReflectance=dielectricReflectance( specular_ior ,effectiveCoatIor ,specular_color ,specular_weight );} ReflectanceParams baseConductorReflectance;baseConductorReflectance=conductorReflectance(base_color,specular_color,specular_weight);vec3 volume_absorption=vec3(1.0);vec3 transmission_tint=vec3(1.0);float surface_translucency_weight=0.0; #if defined(REFRACTED_BACKGROUND) || defined(REFRACTED_ENVIRONMENT) || defined(REFRACTED_LIGHTS) #if defined(GEOMETRY_THIN_WALLED) vec3 refractedViewVector=-viewDirectionW; #else #ifdef DISPERSION vec3 refractedViewVectors[3];float iorDispersionSpread=transmission_dispersion_scale/transmission_dispersion_abbe_number*(specular_ior-1.0);vec3 dispersion_iors=vec3(specular_ior-iorDispersionSpread,specular_ior,specular_ior+iorDispersionSpread);for (int i=0; i<3; i++) {refractedViewVectors[i]=double_refract(-viewDirectionW,normalW,dispersion_iors[i]); } #else vec3 refractedViewVector=double_refract(-viewDirectionW,normalW,specular_ior); #endif #endif #ifdef GEOMETRY_THIN_WALLED float transmission_roughness=specular_roughness; #else float transmission_roughness=specular_roughness*clamp(4.0*(specular_ior-1.0),0.001,1.0); #endif #if (defined(TRANSMISSION_SLAB) || defined(SUBSURFACE_SLAB)) OpenPBRHomogeneousVolume volumeParams;{ #if defined(TRANSMISSION_SLAB) OpenPBRHomogeneousVolume transmissionVolumeParams=computeOpenPBRTransmissionVolume( transmission_color.rgb, transmission_depth, transmission_scatter.rgb, transmission_scatter_anisotropy ); #endif #if defined(SUBSURFACE_SLAB) OpenPBRHomogeneousVolume subsurfaceVolumeParams=computeOpenPBRSubsurfaceVolume( subsurface_color.rgb, subsurface_radius, subsurface_radius_scale.rgb, subsurface_scatter_anisotropy ); #endif #if !defined(TRANSMISSION_SLAB) volumeParams=subsurfaceVolumeParams;surface_translucency_weight=subsurface_weight; #elif !defined(SUBSURFACE_SLAB) volumeParams=transmissionVolumeParams; #ifdef TRANSMISSION_SLAB_VOLUME volumeParams.multi_scatter_color=singleScatterToMultiScatterAlbedo(volumeParams.ss_albedo); #endif surface_translucency_weight=transmission_weight; #else float subsurface_fraction_of_dielectric=(1.0f-transmission_weight)*subsurface_weight;float subsurface_and_transmission_fraction_of_dielectric=subsurface_fraction_of_dielectric+transmission_weight;float reciprocal_of_subsurface_and_transmission_fraction_of_dielectric = 1.0f/maxEps(subsurface_and_transmission_fraction_of_dielectric);float trans_weight=transmission_weight*reciprocal_of_subsurface_and_transmission_fraction_of_dielectric;float subsurf_weight=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/maxEps(volumeParams.extinction_coeff);volumeParams.multi_scatter_color=singleScatterToMultiScatterAlbedo(volumeParams.ss_albedo);surface_translucency_weight=subsurface_and_transmission_fraction_of_dielectric; #endif } volume_absorption=exp(-volumeParams.absorption_coeff*geometry_thickness);vec3 backscatter_color=vec3(1.0);{vec3 reduced_scatter=volumeParams.scatter_coeff*vec3(1.0-volumeParams.anisotropy);vec3 reduced_albedo=reduced_scatter/(volumeParams.absorption_coeff+reduced_scatter);vec3 sqrt_term=max(sqrt(1.0-reduced_albedo),0.0001);backscatter_color=(1.0-sqrt_term)/(1.0+sqrt_term);} #elif defined(TRANSMISSION_SLAB) surface_translucency_weight=transmission_weight; #endif float refractionAlphaG=transmission_roughness*transmission_roughness; #ifdef SCATTERING #ifdef GEOMETRY_THIN_WALLED vec3 iso_scatter_density=vec3(1.0);float roughness_alpha_modified_for_scatter=1.0; #else #ifdef USE_IRRADIANCE_TEXTURE_FOR_SCATTERING vec3 mfp=vec3(100.0)/volumeParams.extinction_coeff;vec3 scattered_light_from_irradiance_texture=sss_convolve(sceneIrradianceSampler,sceneDepthSampler,renderTargetSize,mfp,projection,inverseProjection,16,noise.xy); #else vec3 scattered_light_from_irradiance_texture=vec3(0.0); #endif float back_to_iso_scattering_blend=min(1.0+volumeParams.anisotropy,1.0);float iso_to_forward_scattering_blend=max(volumeParams.anisotropy,0.0);vec3 iso_scatter_transmittance=pow(exp(-volumeParams.scatter_coeff*geometry_thickness),vec3(0.2));vec3 iso_scatter_density=clamp(vec3(1.0)-iso_scatter_transmittance,0.0,1.0);float roughness_alpha_modified_for_scatter=min(refractionAlphaG+(1.0-abs(volumeParams.anisotropy))*max3(iso_scatter_density*iso_scatter_density),1.0);roughness_alpha_modified_for_scatter=pow(roughness_alpha_modified_for_scatter,6.0);roughness_alpha_modified_for_scatter=clamp(roughness_alpha_modified_for_scatter,refractionAlphaG,1.0); #endif volumeParams.multi_scatter_color=mix(volumeParams.ss_albedo,volumeParams.multi_scatter_color,max3(iso_scatter_density)); #else float roughness_alpha_modified_for_scatter=refractionAlphaG; #endif #if defined(TRANSMISSION_SLAB) && (!defined(TRANSMISSION_SLAB_VOLUME) || defined(GEOMETRY_THIN_WALLED)) transmission_tint*=transmission_color.rgb*transmission_color.rgb; #ifdef SUBSURFACE_SLAB float unweighted_translucency=mix(subsurface_weight,1.0f,transmission_weight);transmission_tint=mix(vec3(1.0),transmission_tint,transmission_weight/unweighted_translucency);roughness_alpha_modified_for_scatter=mix(1.0,refractionAlphaG,transmission_weight/unweighted_translucency); #endif #ifdef GEOMETRY_THIN_WALLED float sin2=1.0-baseGeoInfo.NdotV*baseGeoInfo.NdotV;sin2=sin2/(specular_ior*specular_ior);float cos_t=sqrt(1.0-sin2);float pathLength=1.0/cos_t;transmission_tint=pow(transmission_tint,vec3(pathLength)); #endif #endif #endif #include<openpbrBackgroundTransmission> vec3 material_surface_ibl=vec3(0.,0.,0.); #include<openpbrEnvironmentLighting> vec3 material_surface_direct=vec3(0.,0.,0.); #ifdef REFLECTION slab_translucent_background=vec4(0.,0.,0.,1.); #else slab_translucent_background/=float(LIGHTCOUNT); #endif #if defined(LIGHT0) float aggShadow=0.; #include<openpbrDirectLightingInit>[0..maxSimultaneousLights] #include<openpbrDirectLighting>[0..maxSimultaneousLights] #endif vec3 material_surface_emission=vEmissionColor; #ifdef EMISSION_COLOR vec3 emissionColorTex=texture2D(emissionColorSampler,vEmissionColorUV+uvOffset).rgb; #ifdef EMISSION_COLOR_GAMMA material_surface_emission*=toLinearSpace(emissionColorTex.rgb); #else material_surface_emission*=emissionColorTex.rgb; #endif material_surface_emission*= vEmissionColorInfos.y; #endif material_surface_emission*=vLightingIntensity.y; #define CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION vec4 finalColor=vec4(material_surface_ibl+material_surface_direct+material_surface_emission,alpha); #define CUSTOM_FRAGMENT_BEFORE_FOG finalColor=max(finalColor,0.0); #include<logDepthFragment> #include<fogFragment>(color,finalColor) #include<pbrBlockImageProcessing> #define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR #ifdef PREPASS #include<openpbrBlockPrePass> #endif #if !defined(PREPASS) || defined(WEBGL2) gl_FragColor=finalColor; #endif #include<oitFragment> #if ORDER_INDEPENDENT_TRANSPARENCY if (fragDepth==nearestDepth) {frontColor.rgb+=finalColor.rgb*finalColor.a*alphaMultiplier;frontColor.a=1.0-alphaMultiplier*(1.0-finalColor.a);} else {backColor+=finalColor;} #endif #include<pbrDebug> #define CUSTOM_FRAGMENT_MAIN_END } `; // Sideeffect if (!ShaderStore.ShadersStore[name]) { ShaderStore.ShadersStore[name] = shader; } /** @internal */ export const openpbrPixelShader = { name, shader }; //# sourceMappingURL=openpbr.fragment.js.map