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.

31 lines (27 loc) 1.24 kB
//#region src/core/shaders/chunks/fragment/head/get-PCF-directional-shadow-contribution.ts /** Helper chunk to get the PCF soft shadow generated by a given {@link core/lights/DirectionalLight.DirectionalLight | DirectionalLight}. */ const getPCFDirectionalShadowContribution = ` fn getPCFDirectionalShadowContribution(index: i32, worldPosition: vec3f, fragmentPosition: vec2f, depthTexture: texture_depth_2d) -> f32 { let directionalShadow: DirectionalShadowsElement = directionalShadows.directionalShadowsElements[index]; // get shadow coords let projectedShadowCoords: vec4f = directionalShadow.projectionMatrix * directionalShadow.viewMatrix * vec4(worldPosition, 1.0); var shadowCoords: vec3f = projectedShadowCoords.xyz / projectedShadowCoords.w; // Convert XY to (0, 1) // Y is flipped because texture coords are Y-down. shadowCoords = vec3( shadowCoords.xy * vec2(0.5, -0.5) + vec2(0.5), shadowCoords.z ); return getPCFBaseShadowContribution( shadowCoords, fragmentPosition, directionalShadow.pcfSamples, directionalShadow.radius, directionalShadow.bias, directionalShadow.intensity, depthTexture ); } `; //#endregion export { getPCFDirectionalShadowContribution };