Skip to content

Instantly share code, notes, and snippets.

@shadercoder
Forked from sebbbi/ConeTraceAnalytic.txt
Created August 29, 2018 07:03
Show Gist options
  • Save shadercoder/3d39bb9cf924e569ac9b313065670d72 to your computer and use it in GitHub Desktop.
Save shadercoder/3d39bb9cf924e569ac9b313065670d72 to your computer and use it in GitHub Desktop.

Revisions

  1. @sebbbi sebbbi created this gist Aug 27, 2018.
    23 changes: 23 additions & 0 deletions ConeTraceAnalytic.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    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.