I implemented a "shadow-casting" algorithm which looks like this (the video below):
What I want to achive is to create radial gradient effect in the visible area (or rather say area not shaded). Just like a real light source, of which the intensity decreases when the light propagates farther. Area close to the source point (where the cursor is) should be brighter, and the area farther from the light source (and should be visible) should be dimmer.
The input consists of two parts:
- The visible area. Represented by
Vec<Point2>
, an ordered vector for the corners of visible area. "Ordered" implies that the angles (from light source to the corner) of all the points in vec are sorted (increasing). - The position of the light source. Represented by
Point2
.
I am new to OpenGL (related stuffs) and Rust nannou therefore I have no idea how to implement this feature. I tried points_colored
function of nannou, which yielded strange results (by coloring all the corner points according to the distance between them and the light source). I read the code from nannou/example
, and found draw/draw_mesh.rs
most related and useful to my use case. Yet it invovles triangles and tessellation?(I guess?), which totally confuses me, though I think that might just be the way. So I wonder:
- How to implement radial gradient in nannou? How to create triangles (or quads) and why?
Any help is appreciated (it doesn't need to be lib-dependent). The code for shadow casting can be seen at Enigmatisms/ShadowCaster