4.1 KiB
renderCsm
Replacement renderCsm_frag.glsl for Blockland v21. This is the fragment shader the high-quality cascaded shadow program uses. The stock file is the one shipped in shaders - default. This copy keeps the same uniforms and varyings the engine binds, and changes how bricks are lit and how the shadow map is sampled.
Ground plates are not this program. Those use the baked plate texture.
Install
Copy renderCsm_frag.glsl over shaders/renderCsm_frag.glsl in the Blockland folder. Keep the stock file somewhere else if you want to go back. Then change shader quality in Options so the game recompiles the shader. Launch from Steam.
Shadows
The stock shader takes one depth sample per cascade. The fragment is either lit or shadowed. Cascades mix only in the last tenth of a split, and the depth bias is a fixed fudge.
This shader filters that sample:
- Cascade 0 and 1 use an 8-tap Vogel disk.
- Cascade 2 uses 4 taps.
- The farthest cascade, and particles, use one tap.
- The disk grows slightly on later cascades. A slope term adds bias on grazing faces, and less bias on the nearest cascade.
- Cascade mixing starts earlier (at 12% of the split) and also fades in the next map when the shadow UV is near the atlas edge.
- Shadows fade out between view distances 16 and 88, so stud self-shadows do not turn into rings far away. Past that distance the pixel is treated as unshadowed.
fwidth is not used on the compare value, and shadow UVs are not snapped to texel centers. Those two showed up as cascade lines and moiré on studs.
Brick tops
On a top face whose texture is the stock brick top, or the five-color top map, the overlay is not drawn. The dark rim baked into that texture fought the moving highlight. The brick color is used instead, and a five-face bevel is built in the shader: a flat center and four sloped sides. That bevel becomes the normal for lighting and specular. Side faces, prints, and anything that is not that top texture still mix the overlay the way the stock shader does.
A degenerate UV, such as brickTOP stretched onto a side, does not perturb the normal. A tiny tangent frame there was the salt-and-pepper sparkle.
Lighting
Stock lighting is NdotL times the sun, plus ambient scaled by the shadow, plus the shadow color where the sun is blocked. Specular is a reflection-vector highlight, power 12, scaled by how bright the overlay is, and added after the color multiply. Fully dark faces (NdotL at or below 0.04) are the flat shadow color. The band from 0.04 to 0.1 blends into the sun. Point lights use a cubic falloff (ratio³ × 0.4) and do not specular. Glow bricks skip lighting and return the albedo. Fog mixes with fogColor.a. Particles clamp light at 1.2.
This shader changes that stack:
- Sun diffuse wraps a little onto the dark side (
NdotL * 0.88 + 0.12). - The terminator uses the geometric face, not the stud bevel, so each pyramid facet does not drop to shade as a solid polygon.
- Shadowed ambient is not black. A fill of 0.42 of the sky ambient remains, with a cooler tint. Faces pointing up get more sky light, and that bias fades with distance.
- The extra shade on sky-facing bevels runs only where the stud normal differs from the real face. Walls used to get it too, which crushed indoor corridors.
- Sun specular is a Blinn term,
NdotH^16, and most of it takes the brick color so a brown brick stays brown. - A small fresnel rim and a stud-only sky glint are added. Highlight values above 0.78 are compressed so white bricks and stacked lamps do not go solid white. Light is compressed before it multiplies the albedo, which keeps stud contrast.
- Point lights still die at the engine radius. Inside that radius the falloff is a mix of cubic and a longer quadratic, so light spills out of doorways. Each lamp also gets a tight Blinn glint. The bulb is treated as a fraction of the attenuation radius so the highlight stays small.
- Glow and emitter bricks return early, at 1.5 times the albedo, with no shadow sample.
- Fog alpha is remapped with a sine before the mix, instead of using
fogColor.adirectly.
Build
There is nothing to compile. The file is the shader the game loads from shaders/renderCsm_frag.glsl.