Skip to main content

Variable: contactShadowBilateralBlur

const contactShadowBilateralBlur: object

Defined in: modules/lighting/contact-shadow/contact-shadow.ts:183

Type Declaration​

bindingLayout​

readonly bindingLayout: readonly [{ group: 0; name: "depthTexture"; }, { group: 0; name: "normalTexture"; }]

bindings​

readonly bindings: ContactShadowBindings<unknown>

fs​

readonly fs: "\nlayout(std140) uniform contactShadowBilateralBlurUniforms {\n vec2 direction;\n float radius;\n float depthSigma;\n float normalPower;\n} contactShadowBilateralBlur;\nuniform sampler2D depthTexture;\nuniform sampler2D normalTexture;\nvec4 contactShadowBilateralBlur_sampleColor(sampler2D sourceTexture,vec2 texSize,vec2 texCoord) {\n vec2 texel=contactShadowBilateralBlur.direction/vec2(textureSize(sourceTexture,0));\n float centerDepth=texture(depthTexture,texCoord).r;\n vec3 centerNormal=normalize(texture(normalTexture,texCoord).xyz*2.0-1.0);\n float result=texture(sourceTexture,texCoord).r;\n float totalWeight=1.0;\n for(int index=1;index<=6;index++) {\n if(float(index)>contactShadowBilateralBlur.radius)break;\n for(int side=-1;side<=1;side+=2) {\n vec2 sampleUv=clamp(texCoord+texel*float(index*side),vec2(0.0),vec2(1.0));\n float sampleDepth=texture(depthTexture,sampleUv).r;\n vec3 sampleNormal=normalize(texture(normalTexture,sampleUv).xyz*2.0-1.0);\n float depthDelta=abs(sampleDepth-centerDepth);\n float depthWeight=exp(-(depthDelta*depthDelta)/max(2.0*contactShadowBilateralBlur.depthSigma*contactShadowBilateralBlur.depthSigma,0.000001));\n float normalWeight=pow(max(dot(centerNormal,sampleNormal),0.0),contactShadowBilateralBlur.normalPower);\n float spatialWeight=exp(-float(index*index)/8.0);\n float weight=depthWeight*normalWeight*spatialWeight;\n result+=texture(sourceTexture,sampleUv).r*weight;totalWeight+=weight;\n }\n }\n return vec4(vec3(result/totalWeight),1.0);\n}\n"

name​

readonly name: "contactShadowBilateralBlur" = 'contactShadowBilateralBlur'

props​

readonly props: Partial<ContactBlurUniforms> & ContactShadowBindings<unknown>

propTypes​

readonly propTypes: object

propTypes.depthSigma​

readonly depthSigma: object

propTypes.depthSigma.min​

readonly min: 0.0001 = 0.0001

propTypes.depthSigma.softMax​

readonly softMax: 0.05 = 0.05

propTypes.depthSigma.value​

readonly value: 0.006 = 0.006

propTypes.direction​

readonly direction: object

propTypes.direction.private​

readonly private: true = true

propTypes.direction.value​

readonly value: readonly [1, 0]

propTypes.normalPower​

readonly normalPower: object

propTypes.normalPower.min​

readonly min: 1 = 1

propTypes.normalPower.softMax​

readonly softMax: 64 = 64

propTypes.normalPower.value​

readonly value: 24 = 24

propTypes.radius​

readonly radius: object

propTypes.radius.max​

readonly max: 6 = 6

propTypes.radius.min​

readonly min: 1 = 1

propTypes.radius.value​

readonly value: 4 = 4

source​

readonly source: "struct contactShadowBilateralBlurUniforms {\n direction: vec2f,\n radius: f32,\n depthSigma: f32,\n normalPower: f32,\n};\n@group(0) @binding(auto) var<uniform> contactShadowBilateralBlur: contactShadowBilateralBlurUniforms;\n@group(0) @binding(auto) var depthTexture: texture_depth_2d;\n@group(0) @binding(auto) var depthTextureSampler: sampler;\n@group(0) @binding(auto) var normalTexture: texture_2d<f32>;\n@group(0) @binding(auto) var normalTextureSampler: sampler;\n\nfn contactShadowBilateralBlur_sampleColor(\n sourceTexture: texture_2d<f32>, sourceTextureSampler: sampler, texSize: vec2f, texCoord: vec2f\n) -> vec4f {\n let sourceDimensions = vec2f(textureDimensions(sourceTexture));\n let texel = contactShadowBilateralBlur.direction / sourceDimensions;\n let centerDepth = textureSampleLevel(depthTexture, depthTextureSampler, texCoord, 0);\n let centerNormal = normalize(textureSampleLevel(normalTexture, normalTextureSampler, texCoord, 0.0).xyz * 2.0 - 1.0);\n var result = textureSampleLevel(sourceTexture, sourceTextureSampler, texCoord, 0.0).r;\n var totalWeight = 1.0;\n for (var index: i32 = 1; index <= 6; index++) {\n if (f32(index) > contactShadowBilateralBlur.radius) { break; }\n for (var side: i32 = -1; side <= 1; side += 2) {\n let sampleUv = clamp(texCoord + texel * f32(index * side), vec2f(0.0), vec2f(1.0));\n let sampleDepth = textureSampleLevel(depthTexture, depthTextureSampler, sampleUv, 0);\n let sampleNormal = normalize(textureSampleLevel(normalTexture, normalTextureSampler, sampleUv, 0.0).xyz * 2.0 - 1.0);\n let depthDelta = abs(sampleDepth - centerDepth);\n let depthWeight = exp(-(depthDelta * depthDelta) / max(2.0 * contactShadowBilateralBlur.depthSigma * contactShadowBilateralBlur.depthSigma, 0.000001));\n let normalWeight = pow(max(dot(centerNormal, sampleNormal), 0.0), contactShadowBilateralBlur.normalPower);\n let spatialWeight = exp(-f32(index * index) / 8.0);\n let weight = depthWeight * normalWeight * spatialWeight;\n result += textureSampleLevel(sourceTexture, sourceTextureSampler, sampleUv, 0.0).r * weight;\n totalWeight += weight;\n }\n }\n let visibility = result / totalWeight;\n return vec4f(vec3f(visibility), 1.0);\n}"

uniforms​

readonly uniforms: ContactBlurUniforms

uniformTypes​

readonly uniformTypes: object

uniformTypes.depthSigma​

readonly depthSigma: "f32" = 'f32'

uniformTypes.direction​

readonly direction: "vec2<f32>" = 'vec2<f32>'

uniformTypes.normalPower​

readonly normalPower: "f32" = 'f32'

uniformTypes.radius​

readonly radius: "f32" = 'f32'