Remix.run Logo
kaoD 5 hours ago

Nitpick: "raymarching" is not "raytracing done in a shader" and it's not polygon-based.

Raymarching is a raytracing technique that takes advantage of Signed Distance Functions to have a minimum bound on the ray's distance to complex surfaces, letting you march rays by discrete amounts using this distance[0]. If the distance is still large after a set number of steps the ray is assumed to have escaped the scene.

This allows tracing complex geometry cheaply because, unlike in traditional raytracing, you don't have to calculate each ray's intersection with a large number of analytical shapes (SDFs are O(1), analytical raytracing is O(n)).

There are disadvantages to raymarching. In particular, many useful operations on SDFs only produce a bounded result, actually result in a pseudo-SDF that is not differentiable everywhere, might be non-Euclidean, etc. which might introduce artifacts on the rendering.

You can do analytical raytracing in fragment shaders[1].

[0] https://en.wikipedia.org/wiki/Ray_marching#Sphere_tracing Good visualization of raymarching steps

[1] https://www.shadertoy.com/view/WlXcRM Fragment shader using Monte Carlo raytracing (aka "path tracing")

dahart 3 hours ago | parent [-]

> Raymarching is a raytracing technique…

Did you mean ‘raymarching is a technique…’? Otherwise you’re somewhat contradicting the first sentence, and also ray marching and ray tracing are two different techniques, which is what you’re trying to say, right?

Raymarching can be polygon based, if you want. It’s not usually on ShaderToy, but there’s no technical reason or rule against raymarching polygons. And use of Monte Carlo with ray tracing doesn’t necessarily imply path tracing, FWIW.

kaoD an hour ago | parent [-]

Sorry, let me clarify, the terms are used imprecisely.

Some people use "raytracing" only for the ray intersection technique, but some people (me included, in the post above) consider it an umbrella term and raymarching, path tracing, etc. only as specific techniques of raytracing.

So what I meant is "'raymarching' is not 'raytracing in shaders' but just a technique of raytracing, in shaders or not".

I was not correcting OP, just adding clarifications on top.

> Raymarching can be polygon based, if you want

But not polygon-intersection-based, it'd still be a SDF (to an implicit polygon).