In DirectX, I pasted some generic light sampling functions at the top of each shader before compiling them.
Pasted as in you paste in on every shader files, or you have some sort of a function that contains light texts in strings and combine it with every shader files to be linked during the first load?
I haven't got into shadow mapping yet, but thank you for your extra information, I'm pretty sure I'm getting there after this.
Pasted as text into every shader that is used for materials. I made it fast by saving pre-compiled shaders with check sums that tell if the shader has changed since the last compilation. The hard thing was to maintain backward compability without bloating the code to insert so try to have a powerful interface from the start that is compatible with, amibient, diffuse and specular light for solid, thin and fog materials. Fog will sample the light without caring much about the direction of the light. Thin materials like fabric will sample the light on 2 sides of the surface. I did not implement anisotropic light but think about how you can implement it later on top of the old interface just in case.
For sampling the depth maps, I sampled with both bilinear interpolation and the percentage closer method. I took the maximum intensity of both to remove acne from the percentage closer method. The depth bias was calculated dynamically, based on depth map resolution and dimensions of the light source. For a spot light, the bias must be multiplied by the depth (not distance) from the light source.
Edited by Dawoodoz, 02 January 2014 - 10:51 AM.