UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

87 lines (85 loc) 4.25 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{AnalyticalSkyModel as e}from"./AnalyticalSkyModel.glsl.js";import{PBRMode as o}from"./PhysicallyBasedRenderingParameters.glsl.js";import{PiUtils as t}from"./PiUtils.glsl.js";import{glsl as a}from"../../shaderModules/glsl.js";function n(n,r){const l=n.fragment.code;n.include(t),r.pbrMode!==o.Normal&&r.pbrMode!==o.Schematic&&r.pbrMode!==o.Simplified&&r.pbrMode!==o.TerrainWithWater||(l.add(a`float normalDistribution(float NdotH, float roughness) { float a = NdotH * roughness; float b = roughness / (1.0 - NdotH * NdotH + a * a); return b * b * INV_PI; }`),l.add(a`const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022); const vec4 c1 = vec4( 1.0, 0.0425, 1.040, -0.040); const vec2 c2 = vec2(-1.04, 1.04); vec2 prefilteredDFGAnalytical(float roughness, float NdotV) { vec4 r = roughness * c0 + c1; float a004 = min(r.x * r.x, exp2(-9.28 * NdotV)) * r.x + r.y; return c2 * a004 + r.zw; }`)),r.pbrMode!==o.Normal&&r.pbrMode!==o.Schematic||(n.include(e),l.add(a`struct PBRShadingInfo { float NdotV; float LdotH; float NdotNG; float RdotNG; float NdotAmbDir; float NdotH_Horizon; vec3 skyRadianceToSurface; vec3 groundRadianceToSurface; vec3 skyIrradianceToSurface; vec3 groundIrradianceToSurface; float averageAmbientRadiance; float ssao; vec3 albedoLinear; vec3 f0; vec3 f90; vec3 diffuseColor; float metalness; float roughness; };`),l.add(a`vec3 evaluateEnvironmentIllumination(PBRShadingInfo inputs) { vec3 indirectDiffuse = evaluateDiffuseIlluminationHemisphere(inputs.groundIrradianceToSurface, inputs.skyIrradianceToSurface, inputs.NdotNG); vec3 indirectSpecular = evaluateSpecularIlluminationHemisphere(inputs.groundRadianceToSurface, inputs.skyRadianceToSurface, inputs.RdotNG, inputs.roughness); vec3 diffuseComponent = inputs.diffuseColor * indirectDiffuse * INV_PI; vec2 dfg = prefilteredDFGAnalytical(inputs.roughness, inputs.NdotV); vec3 specularColor = inputs.f0 * dfg.x + inputs.f90 * dfg.y; vec3 specularComponent = specularColor * indirectSpecular; return (diffuseComponent + specularComponent); }`),l.add(a`float gamutMapChanel(float x, vec2 p){ return (x < p.x) ? mix(0.0, p.y, x/p.x) : mix(p.y, 1.0, (x - p.x) / (1.0 - p.x) ); }`),l.add(a`vec3 blackLevelSoftCompression(vec3 inColor, PBRShadingInfo inputs){ vec3 outColor; vec2 p = vec2(0.02 * (inputs.averageAmbientRadiance), 0.0075 * (inputs.averageAmbientRadiance)); outColor.x = gamutMapChanel(inColor.x, p) ; outColor.y = gamutMapChanel(inColor.y, p) ; outColor.z = gamutMapChanel(inColor.z, p) ; return outColor; }`))}function r(e,o){const n=e.fragment.code;e.include(t),n.add(a` struct PBRShadingWater { float NdotL; // cos angle between normal and light direction float NdotV; // cos angle between normal and view direction float NdotH; // cos angle between normal and half vector float VdotH; // cos angle between view direction and half vector float LdotH; // cos angle between light direction and half vector float VdotN; // cos angle between view direction and normal vector }; float dtrExponent = ${o.useCustomDTRExponentForWater?"2.2":"2.0"}; `),n.add(a`vec3 fresnelReflection(float angle, vec3 f0, float f90) { return f0 + (f90 - f0) * pow(1.0 - angle, 5.0); }`),n.add(a`float normalDistributionWater(float NdotH, float roughness) { float r2 = roughness * roughness; float NdotH2 = NdotH * NdotH; float denom = pow((NdotH2 * (r2 - 1.0) + 1.0), dtrExponent) * PI; return r2 / denom; }`),n.add(a`float geometricOcclusionKelemen(float LoH) { return 0.25 / (LoH * LoH); }`),n.add(a`vec3 brdfSpecularWater(in PBRShadingWater props, float roughness, vec3 F0, float F0Max) { vec3 F = fresnelReflection(props.VdotH, F0, F0Max); float dSun = normalDistributionWater(props.NdotH, roughness); float V = geometricOcclusionKelemen(props.LdotH); float diffusionSunHaze = mix(roughness + 0.045, roughness + 0.385, 1.0 - props.VdotH); float strengthSunHaze = 1.2; float dSunHaze = normalDistributionWater(props.NdotH, diffusionSunHaze) * strengthSunHaze; return ((dSun + dSunHaze) * V) * F; }`)}export{n as PhysicallyBasedRendering,r as PhysicallyBasedRenderingWater};