A quick test to see if gravitational lensing would be a nice effect in 3d.
Another render here.
The surface of the shape has a very high mass/volume density. That is why light is bend around the shape.
For this effect, I build on a raymarching tutorial that uses SDF (Signed Distance Field). The light bending is done by using a characteristic of SDF tracing. When a render-ray approaches a surface in SDF tracing, the steps get smaller. At each step, I change the ray direction with a fixed value, and the bending occurs. This kind of works, because close at the surface of the shape, there will be a stronger banding effect.
But that is a very cheap way of rendering it.
A more correct approach will be to make a static scene in a voxel octree. Each cell will contain air or mass.
– Cells with mass must define a colors
– Cells with air could contain a pre-calculated gravity-vector. Pointing towards the closest mass.
When a ray is marching trough the octree, it would at each step see if it is stil marching trough air. If it is, then it takes the gravity-vector and applies it to its current direction. This way, the ray will be bend towards the closest mass.
Once that ray hits a cell with mass, it stops and uses it’s color value to return as pixel color.
If the ray is marching on a sparse area, it can make bigger steps.
This is al assuming that light follows Newtonian logic, but that is not completely the reality. However, Schwarzschild equations are too complex to me for this hobby project.