I am trying to figure it out if and how would be possible to calculate hard shadows from multiple light-sources off-screen.
preamble: scene is very complex, up to several million of triangles, up to hundred different light-sources, lights, material and depth enabled and maximum precision (at least 10kx10k pixel ground resolution). Shadows are nothing else than planar projected shadow, that is I am rendering the objects themselves by pre-multiplying by a shadow matrix (given a light-source position and a plane). Multiple objects, multiple light-sources but just a single plane.
For this reason real-time is impossible. Also impossible is to think about an incremental stencil value, since I have only one byte (255 useful values) and I may have more than 255 light-sources.
Therefore my idea was to render off-screen (to texture or render-buffer image).
For each light source, I calculate my shadow matrix and apply it. Then I render my first object with a specific stencil number (i.e. 1). Then I render my second object. I need to render it only where the stencil number is 1 and I need to zero all the other pixels, because I am interested in the hard shadow only. Then the third object and so on. At the end I repeat all the process for the second light source and so on.
Is it possible? Better texture or render-buffer image? Once hard shadow is calculated I need to retrieve it back on the cpu to analyze it and render it also on the ground in my scene.
Ideally I would need only the stencil buffer attached to my FBO but they say here https://www.opengl.org/wiki/Framebuffer_Object_Examples:
Stencil NEVER EVER MAKE A STENCIL buffer. All GPUs and all drivers do not support an independent stencil buffer. If you need a stencil buffer, then you need to make a Depth=24, Stencil=8 buffer, also called D24S8. Please search for the example about GL_EXT_packed_depth_stencil on this age.
Is this still valid today?
Looking around, I found here http://stackoverflow.com/questions/7570215/opengl-es-stencil-operations a way of zeroing all the other pixels by render a full screen polygon between each object, but I wonder if there is anything more efficient…?