Variable: contactShadowBilateralBlur
constcontactShadowBilateralBlur:object
Defined in: modules/lighting/contact-shadow/contact-shadow.ts:183
Type Declaration
bindingLayout
readonlybindingLayout: readonly [{group:0;name:"depthTexture"; }, {group:0;name:"normalTexture"; }]
bindings
readonlybindings:ContactShadowBindings<unknown>
fs
readonlyfs: "\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
readonlyname:"contactShadowBilateralBlur"='contactShadowBilateralBlur'
props
readonlyprops:Partial<ContactBlurUniforms> &ContactShadowBindings<unknown>
propTypes
readonlypropTypes:object
propTypes.depthSigma
readonlydepthSigma:object
propTypes.depthSigma.min
readonlymin:0.0001=0.0001
propTypes.depthSigma.softMax
readonlysoftMax:0.05=0.05
propTypes.depthSigma.value
readonlyvalue:0.006=0.006
propTypes.direction
readonlydirection:object
propTypes.direction.private
readonlyprivate:true=true
propTypes.direction.value
readonlyvalue: readonly [1,0]
propTypes.normalPower
readonlynormalPower:object
propTypes.normalPower.min
readonlymin:1=1
propTypes.normalPower.softMax
readonlysoftMax:64=64
propTypes.normalPower.value
readonlyvalue:24=24
propTypes.radius
readonlyradius:object
propTypes.radius.max
readonlymax:6=6
propTypes.radius.min
readonlymin:1=1
propTypes.radius.value
readonlyvalue:4=4
source
readonlysource: "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
readonlyuniforms:ContactBlurUniforms
uniformTypes
readonlyuniformTypes:object
uniformTypes.depthSigma
readonlydepthSigma:"f32"='f32'
uniformTypes.direction
readonlydirection:"vec2<f32>"='vec2<f32>'
uniformTypes.normalPower
readonlynormalPower:"f32"='f32'
uniformTypes.radius
readonlyradius:"f32"='f32'