- Home /
Composit transparency triangles to dark fog of war plane
So I've been thinking about making a 2D platformer where the protagonist has a flashlight that casts a cone of light. A key idea in the design is that everything is black except for the cone of light (which needs to use raycast logic in order to collide with the right surfaces, etc.)
But then, this is proving to be very difficult. The main idea looks like this:
There is a fog of war plane in front of the entire scene, it is black.
The player has a flash light which sends N rays in a cone that check for collision with the environment. Each 2 adjacent rays' origin/collision points make a triangle whose vertexes each have "light intensity values", with vertexes further away from the flash light being "less bright".
Each triangle is projected against the black plane from camera view
Each projected triangle is composited with the black plane, giving the effect that the flashlight is "piercing" through the darkness.
And this should work for sphere-like light emission as well, and would allow for varying degrees of precision using more or less rays. But I barely know how to make half of these things, and I don't know which of these things can be made using shaders (supposedly making the algorithm faster).
Is there a way to do this (efficiently)?
Answer by Vincent_Jahjah · Oct 22, 2015 at 08:12 AM
Here is a tentative solution that does not imply compositing meshes together:
There is black plane at the BACK of the entire scene.
The scene is rendered in a first camera and into a texture.
Based on light sources, the CPU procedurally generates triangles (light cones, etc.)
A texture is applied on those triangles, with UVs being the screen coordinates.
A second camera (main camera) renders the triangles
Reasoning: Instead cutting holes into a mesh (which is hard), the algorithm literally turns the "holes/light triangles" into the view. Anything that is not lit will be non-existant, or "entirely transparent", and the back black plane will be the only thing that's rendered.
Your answer
Follow this Question
Related Questions
Help with Stencil shaders please 0 Answers
Fog Of War/ Visibility 0 Answers
[Line of Sight] Please evaluate my approach 1 Answer
Methods for doing fog of war? 1 Answer
2D Something like fog of war - things are invisible out of light stripe 1 Answer