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.
26 lines (21 loc) • 1.09 kB
JavaScript
//#region src/core/shaders/full/fragment/get-default-point-shadow-depth-fragment-code.ts
/**
* Get {@link core/lights/PointLight.PointLight | PointLight} shadow map pass fragment shader.
* @param lightIndex - Index of the {@link core/lights/PointLight.PointLight | PointLight} for which to render the depth pass.
*/
const getDefaultPointShadowDepthFs = (lightIndex = 0) => `
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);
}`;
//#endregion
export { getDefaultPointShadowDepthFs };