UNPKG

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
const getDefaultPointShadowDepthFs = (lightIndex = 0) => ( /* wgsl */ ` struct PointShadowVSOutput { @builtin(position) position: vec4f, @location(0) worldPosition: vec3f, } @fragment fn main(fsInput: PointShadowVSOutput) -> @builtin(frag_depth) 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 };