This page documents my exploration with ray marching. I have worked extensively with 3D rendering, and written all kinds of code for various things, even generating 3D geometry, however it has always been a dream of mine to write my own 3D render engine from scratch. This is topic is one that I am simply exploring with no final goal in plan. I'll explain a bit about what is happening alongside renders of the various states. Jump to the bottom of the page for the current and most advanced state. I'd like to give a huge thanks/reference to Inigo Quilez for providing fantastic reference material for this kind of work.
This program was written entirely in Processing and uses a ray marching algorithm and signed distance fields.
The first bits take so much work getting the structure of the objects and rendering algorithm all working together before you get to see any results, but finally, here is a circle!
Adding a light. Now parts of the sphere that are occluded by itself are in shadow.
I wanted everything to fit inside of a box because I think its cool and it helps keep my code efficient because the rays never have to travel too far. Lighting is still either on or off, so you can't really see that its a box other than the corner in the shadow.
Added some falloff to the light so points closer to the light receive more... light.
Added more primitives to the scene. More importantly, I started doing some Monte Carlo rendering to get soft shadows. The noise is just from not sampling enough... but that takes lots of time to do!
Added secondary bounces to the rays that grab light and color data.
Added Monte Carlo rendering to the camera for anti-aliasing and depth of field.
Created system for saving and generating different scenes. Started rendering more complex scenes.
Added system for transform matrices in order to rotate the camera. Also implemented some optimization by pre-computing which objects a ray might hit so it only check those objects for intersections instead of every object in the scene.
Added a few new features as well as quite a bit of cleaning up and restructuring.
The lights now feature inverse square falloff, which makes for really harsh light. The lights' effect is also now affected by incidence angle, so surfaces that are oblique to the light catch less of it. Added reflections with fresnel effect. Added a system for smooth boolean operations of primitives, implemented here as a bumpy sphere.
The color mixing was rewritten to be much cleaner. Originally each ray kept brightness, color, secondary brightness, secondary color, reflection brightness, and reflection color all as individual channels and mixed them for the final output. Now the brightness is gone and only one color value is kept per sample per ray. This hopefully mixes the colors in a more natural way.
Unfortunately it seems that with this new mixing there is a issue where corners get lighter than they should because the distance between secondary bounces is so short it does not fall off and ends up bouncing more light that it should.
I also implemented a system to displace spheres based on Perlin noise. It makes them look like rocks, which is fun.