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)?