Sample - Ray Marching and Signed Distance Functions #13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a sample that renders a 3D torus and box using ray marching and signed distance functions. Ray marching iteratively projects a ray in space and uses signed distance functions of various shapes to decide whether it has hit them:
The
getDistance()function effectively renders the scene. It returns the distance to the nearest object in the scene. Since we have a torus and a box, we calculate the distance to both and return the minimum (we see whichever is nearest). We use a smooth min function to create a blending effect of the objects when they are close in distance. A similar smoothing technique is applied to blend the color of the two objects.The lighting is calculated using
getLight(), which uses the dot product of a vector from the light source to the surface of the object. The scene is animated using Cyfra's animation tools.The following is the result:
output.mp4