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.
24 lines (18 loc) • 786 B
JavaScript
const getDefaultPointShadowDepthFs = (lightIndex = 0) => (
/* wgsl */
`
struct PointShadowVSOutput {
position: vec4f,
worldPosition: vec3f,
}
fn main(fsInput: PointShadowVSOutput) -> f32 {
let pointShadow: PointShadowsElement = pointShadows.pointShadowsElements[${lightIndex}];
// get distance between fragment and light source
var lightDistance: f32 = length(fsInput.worldPosition - pointShadow.position);
// map to [0, 1] range by dividing by far plane - near plane
lightDistance = (lightDistance - pointShadow.cameraNear) / (pointShadow.cameraFar - pointShadow.cameraNear);
// write this as modified depth
return saturate(lightDistance);
}`
);
export { getDefaultPointShadowDepthFs };