from Hacker News

Domain Repetition

by ianthehenry on 8/24/23, 5:35 AM with 10 comments

  • by ianthehenry on 8/25/23, 5:12 AM

    If you aren't familiar with SDFs, some rough intuition for what's going on here: you have some primitive functions that define shapes, you have combinators that distort shapes, and you then have combinators that distort space. And then when you trace rays through distorted space, you render an image that looks like your combinators distorted the shapes themselves, but really you're distorting the path that your rays travel along.

    The operation here is that you distort space with the modulo operator. So now you have space that repeats -- and when you trace rays through this repeated space, you're basically teleporting the rays back to the origin (using mod in the classic "wrapping around" fashion) every time they pass out of a section of space.

    And then ultimately the ray will collide with the shape -- the one shape -- that exists in this distorted space, after wrapping around some number of times.

    If the idea of "taking the mod of space" is intriguing, I would encourage you to try playing with SDFs! It's a really incredible technique for real-time rendering of "3D vector graphics."

    Also shameless plug for my SDF playground https://bauble.studio, and an example program that uses instanced repetition to render an "infinite" number of varying shapes:

        (tile [400 0 300] (fn [i]
          (torus :z 60 30
          | twist :y (sin (t + (hash i * 10)) * 0.05)
          | rotate :pi :y (t * hash i) :z 0.05
          | move :x 50
          | mirror :r 10 :x
          | fresnel
          | slow 0.5)))
    
    Obviously a lot less compelling than the author's examples...
  • by Liquix on 8/25/23, 2:41 AM

    "The Timeless" [0] is an example of what can be achieved with domain repetition over signed distance functions - the video is of a self-contained 64kb executable running in realtime! One of the authors Johann "Cupe" Korndörfer also gave a great talk [1] regarding the creative/development process.

    [0] https://yewtu.be/watch?v=ie4u2i_5OdE

    [1] https://yewtu.be/watch?v=s8nFqwOho-s

  • by jasonjmcghee on 8/25/23, 4:24 AM

    I remember stumbling upon the “64k demo” phenomenon on YouTube where people created animations that were astronomically small (in code) compared with their rendered video representation.

    At some point that led me to iq and his work is just incredible- not to mention he’s a great educator and freely shares his work and techniques with others.

    Similar to his many under tutorials, this is a really great resource for generative artists and game developers.

  • by nick__m on 8/25/23, 12:31 AM

    Wow, the shadertoy at the end are incredible!
  • by wildpeaks on 8/25/23, 12:15 PM

    The same author also has some great references for SDF primitives to learn from: https://iquilezles.org/articles/distfunctions/

    An example of how different thinking in SDF is: in classic modeling, you define a 3D sphere mesh using a bunch of 3D coordinates (vertices), grouped into triangles for the surface. Therefore you need more vertices to make the sphere appear smoother.

    On the other hand with SDF, you have a function that takes an arbitrary 3D coordinate and returns whether the coordinate is inside the sphere or not (easily done by comparing the distance from the center), meaning the smoothness of the sphere is already the maximum it can be.

  • by binary132 on 8/25/23, 3:15 PM

    IQ is amazing