playcanvas
Version:
PlayCanvas WebGL game engine
65 lines (52 loc) • 1.81 kB
JavaScript
// main shader entry point for the lit material for shadow rendering
var litShadowMainPS = /* glsl */ `
uniform vec3 view_position;
uniform float light_radius;
void main(void) {
evaluateFrontend();
// using non-standard depth, i.e gl_FragCoord.z
float depth = gl_FragCoord.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);
float depth = min(distance(view_position, vPositionW) / light_radius, 0.99999);
float exponent = 15.0;
float exponent = 5.54;
depth = 2.0 * depth - 1.0;
depth = exp(exponent * depth);
gl_FragColor = vec4(depth, depth*depth, 1.0, 1.0);
// store depth into R32
gl_FragColor.r = depth;
// If we end up using modified depth, it needs to be explicitly written to gl_FragDepth
gl_FragDepth = depth;
// just the simplest code, color is not written anyway
gl_FragColor = vec4(1.0);
}
`;
export { litShadowMainPS as default };