playcanvas
Version:
PlayCanvas WebGL game engine
70 lines (54 loc) • 1.97 kB
JavaScript
// main shader entry point for the lit material for shadow rendering
var litShadowMainPS = /* wgsl */ `
uniform view_position: vec3f;
uniform light_radius: f32;
@fragment
fn fragmentMain(input: FragmentInput) -> FragmentOutput {
var output: FragmentOutput;
evaluateFrontend();
// using non-standard depth, i.e gl_FragCoord.z
var depth: f32 = input.position.z;
// spot/omni shadows currently use linear depth.
// TODO: use perspective depth for spot/omni the same way as directional
depth = linearizeDepthWithParams(depth, camera_params);
var depth: f32 = min(distance(uniform.view_position, input.vPositionW) / uniform.light_radius, 0.99999);
var exponent: f32 = 15.0;
var exponent: f32 = 5.54;
var depth_vsm = 2.0 * depth - 1.0;
depth_vsm = exp(exponent * depth_vsm);
output.color = vec4f(depth_vsm, depth_vsm * depth_vsm, 1.0, 1.0);
output.color = vec4f(depth, 0.0, 0.0, 1.0);
// If we end up using modified depth, it needs to be explicitly written to gl_FragDepth
output.fragDepth = depth;
// just the simplest code, color is not written anyway
output.color = vec4f(1.0);
return output;
}
`;
export { litShadowMainPS as default };