gpu-curtains
Version:
gpu-curtains is a 3D WebGPU rendering engine. It can be used as a standalone 3D engine, but also includes extra classes focused on mapping 3d objects to DOM elements; It allows users to synchronize values such as position, sizing, or scale between them.
31 lines (27 loc) • 1.12 kB
JavaScript
//#region src/core/shaders/chunks/fragment/head/get-PCF-spot-shadow-contribution.ts
/** Helper chunk to get the PCF soft shadow generated by a given {@link core/lights/SpotLight.SpotLight | SpotLight}. */
const getPCFSpotShadowContribution = `
fn getPCFSpotShadowContribution(index: i32, worldPosition: vec3f, fragmentPosition: vec2f, depthTexture: texture_depth_2d) -> f32 {
let spotShadow: SpotShadowsElement = spotShadows.spotShadowsElements[index];
// get shadow coords
let projectedShadowCoords: vec4f = spotShadow.projectionMatrix * spotShadow.viewMatrix * vec4(worldPosition, 1.0);
var shadowCoords: vec3f = projectedShadowCoords.xyz / projectedShadowCoords.w;
// Convert XY to (0, 1)
// Y is flipped because texture coords are Y-down.
shadowCoords = vec3(
shadowCoords.xy * vec2(0.5, -0.5) + vec2(0.5),
shadowCoords.z
);
return getPCFBaseShadowContribution(
shadowCoords,
fragmentPosition,
spotShadow.pcfSamples,
spotShadow.radius,
spotShadow.bias,
spotShadow.intensity,
depthTexture
);
}
`;
//#endregion
export { getPCFSpotShadowContribution };