First implementation of a Ray Tracing in 2D using Box Engine with Lua and GLSL
Box engine is developed by me to create 2D and 3d applications
- Click in an object to move it
- To delete an object click it and press delete
- To create a new object press space
- To scale a selected object press Q/W or A/S
- To move the light press L
- To configure resolution, number of casted rays or others, execute the engine editor and edit 'begin_frame' or 'ray_tracer' game object
- Direct light is calculated by casting a ray from the pixel to the light, and checking if no collisions are detected with the rectangles.
- Indirect light is done by casting N rays (configurable) from the pixel and when it intersect with some rectangle, it checks if it reaches the light from the intersection point. From there the calculation with angle (dot product) and attenuation is made and the average of light is calculated from all directions.
- Indirect light have only a single bounce.
- Take a look at the file shader.frag for mor implementation info
- This image describes how light interact in the real world (direct vs indirect), note that in the shader, the calculations starts from the pixels being draw and not from the actual light
- Box Engine is available in Engine Folders with a release and the source code is in my repository (note that versions might differ)
- To run use
start.bat
or usestart_editor.bat
to use the engine editor and change settings better - The complete source code of the ray tracing is in Assets folder