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.

38 lines (33 loc) 1.51 kB
//#region src/core/shaders/chunks/fragment/head/get-PCF-directional-shadows.ts /** * Get the global PCF soft shadows contributions from all the current {@link CameraRenderer} {@link DirectionalLight}. * @param renderer - {@link CameraRenderer} used by the {@link DirectionalLight}. */ const getPCFDirectionalShadows = (renderer) => { const directionalLights = renderer.shadowCastingLights.filter((light) => light.type === "directionalLights"); const minDirectionalLights = Math.max(renderer.lightsBindingParams.directionalLights.max, 1); return ` fn getPCFDirectionalShadows(worldPosition: vec3f, fragmentPosition: vec2f) -> array<f32, ${minDirectionalLights}> { var directionalShadowContribution: array<f32, ${minDirectionalLights}>; var lightDirection: vec3f; ${directionalLights.map((light, index) => { return `lightDirection = worldPosition - directionalLights.elements[${index}].direction; ${light.shadow.isActive ? ` if(directionalShadows.directionalShadowsElements[${index}].isActive > 0) { directionalShadowContribution[${index}] = getPCFDirectionalShadowContribution( ${index}, worldPosition, fragmentPosition, directionalShadowDepthTexture${index} ); } else { directionalShadowContribution[${index}] = 1.0; } ` : `directionalShadowContribution[${index}] = 1.0;`}`; }).join("\n")} return directionalShadowContribution; } `; }; //#endregion export { getPCFDirectionalShadows };