Skip to content

Instantly share code, notes, and snippets.

@seece
Forked from sebbbi/ConeTraceAnalytic.txt
Created November 6, 2021 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seece/497629281f6c135d3644852bad03e46d to your computer and use it in GitHub Desktop.
Save seece/497629281f6c135d3644852bad03e46d to your computer and use it in GitHub Desktop.
Cone trace analytic solution
Spherical cap cone analytic solution is a 1d problem, since the cone cap sphere slides along the ray. The intersection point to empty space sphere is always on the ray.
S : radius of cone cap sphere at t=1
r(d) : cone cap sphere radius at distance d
r(d) = d*S
p = distance of current SDF sample
SDF(p) = sdf function result at location p
x = distance after conservative step
The equation:
p + SDF(p) = x + r(x)
Simplify:
p + SDF(p) = x + x*S ; substitute r(d) = d*S
x(1+S) = p + SDF(p)
x = (p + SDF(p)) / (1+S)
Substitute: C = 1 / (1+S)
x = (p + SDF(p)) * C ; <--- this is the code executed in shader
C is stored to constant buffer and precalculated on CPU.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment