I would like to darken parts of the scene which the main character cannot see for a “spy” game. The scene is viewed from third person view. By visiblity I mean a simple 2d ray casting from player location all around (like in Commands). Similar to this demo < 2d Visibility >.
Any suggestions how to implement this?
I image the solution along following lines (everything below is just my theory):
determine shape of field of vision using the algorithm from the linked site, or some other clever way. This step sounds relatively easy - if everything else fails, I can cast ~360 rays from the character standpoint for satisfactory results
render this polygon by WebGLRenderTarget in white against grayish background, producing a lightmap
multiply fragment color by this “lightmap” (x = u, y = v), z coordinate is up/down, the game takes place on the flat xy surface
No idea idea how to implement the third step. Maybe in postprocesing? Can I access/calculate world coordinates of a fragment during post-processing?
Wow! That was fast. Unfortunately the article stops when the things gets interesting.
However, the implementation, especially the shader seems like a practical approach.
Btw, seems like a great game! It’s refreshing to see someone working on a proper game for the web, and not cheating on graphics by making it retro-themed!