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.

26 lines (21 loc) 1.09 kB
//#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 { @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); }`; //#endregion export { getDefaultPointShadowDepthFs };