Dynamic Shadow
From C4 Engine Wiki
Contents |
Pictures
Goal
This shader permits to simulate shadows by offsetting the lightmap. This is approximative but it looks great to see shadows moving depending on lights. Moreover, as your shadows are in texture you can have soft/strong/colored/whatever shadow you want at less cost.
Shader
This is the explanation of the shader for planes and shadows cast by object contained into the texture. (Window picture)
Shadow Offset
This first step controls the direction (tangent light direction) and the size of the offset. The offset (distance between objects) can be set by a texture to allow multiple distance => better simulation.
Shadow Calculation
Shadows are contained into the alpha channel.
This step calculates where and how the shadows should be applied.
Play with Shadow Strength parameter for the shadow intensity.
Specular Reflection
Just don't forget here to multiply the specular reflection with the shadow to avoid specular onto the shadow.
On the shader picture, there is a mistake because I multiply the specular reflection with the shadow after the shadow has been multiply by Shadow Strength.
Next steps
- Use a texture for shadow offset
- Use multiple layer for shadows
limitations
- You can use this technique for planes only or simple geometries.
- Lightmap UVs has to be oriented and at the same scale.



