I tried… but nope… The thing is… When I put the camera simulating the light position everything look fine… the problem is all the pixels that are NOT inside the “light” viewport cause problems when I render from the camera position…
How can I get rid of the pixels outside the light viewport?!
I’ve been trying to cut theses frags with:
if( projCoord.t > ???
and
if( projCoord.q > ???
but no success it seems that it will always have some artifacts left…
You always need to discard (or set to black) fragments with negative value of Q coordinate. The removal of remaining bad fragments can be done by combination of black border around the edge of the projected texture and clamping texture mode (e.g. GL_CLAMP_TO_EDGE) as mentioned by Y-tension. Alternatively you can use test in shader to discard fragment if any component of (projCoord.st / projCoord.q) is outside of the <0,1> range.
There is one catch if you use the texture based method. Do not use mipmaps for that texture. The projection causes big differences between texture coordinates on fragments which are near the light plane. This causes selection of smaller mipmap levels and unless those levels are black around theirs edges, the light will become visible outside of its view.
Ok got it… that was all about the clamp to edge… errr anyway tks guys!, and for the record, the following shader work like charm after that, if you still want to have the back projection take out the IF statement: