Chinese introduction can be seen at draw light with C++.
This project illustrates light rendering in 2D with C++.
All samples output PNGs with svpng.
I learn a lot from miloyip's project light2d, and try to do the same thing with C++.
The main idea is similar with milo's, following are the differences:
- Ray intersection is used instead of ray marching to speed up, so no SDF(signed distance field), so only one calculation in one ray.
- Only Line and Circle are used as basic shapes. Polygons are generated from lines.
- Different refract indexes are given for different colors.
With the use of SDF, normal calculation can be written in less code , and easier to understand. While in my project, normals and intersect points are all calculated analytically. Maybe not so intuitive. C++ polymorphism is great help to calculate different kinds of normals and intersect points.
an example of reflection
some examples of refraction
an example of a scene with QuadTree
when more separate colors are calculated, results can be more visually natural.