Live data from Hacker News

Ray Marching Soft Shadows in 2D

rykap.com

11–20 of 37 posts

Re: Ray Marching Soft Shadows in 2D

#14
The algorithm discussed here reminds me very much of the "Line of Sight" problem.

Line of Sight is calculated on a 2-d topographical map, where each 2d point is a height-map. The question is: does location "X" have a line-of-sight to location "Y" ?? You solve this question by marching rays from X towards Y, and seeing if any intermediate 2d point has a height that would block the sight.

I bring this up because line-of-sight has been SIMD-optimized and is highly efficient to calculate now. Line-of-sight is similar enough that the large body of research behind that problem can probably serve as inspiration to algorithms in this 'ray marching shadows' algorithm.

Its quite possible that your calculation here is "just" a 2-value line of sight: where 0 means "sight is not blocked" and 1 means "sight is blocked".

------

Ray Marching itself seems innately "sequential", because you need to calculate the closest "solid object" to know how far to march.

In contrast, the naive "try every pixel" approach is easily parallelized if you understand prefix-sum style computations (see: https://en.wikipedia.org/wiki/Prefix_sum). If you could easily group pixels into 1-bit objects (see PEXT or PDEP: https://www.felixcloutier.com/x86/pdep), I'm sure that a SIMD-parallel version would be outstandingly fast to compute for "small" 256-pixel (aka: AVX2) bit-vectors.

-------

EDIT: Now that I think of it: the computation of the distance field is likely sequential. But the use of the distance-field is probably read-only / parallel. A SIMD-line of sight style algorithm using the distance field could be "scheduled" using a sequential algorithm, but then computed with SIMD techniques.

Re: Ray Marching Soft Shadows in 2D

#16
Uncaught Error: Failed to get uniform location for name O

    get graphics.ts:822
    value graphics.ts:950
    value graphics.ts:1234
    value graphics.ts:493
    value renderer.ts:355
    value renderer.ts:471
    onFrame app.ts:631
    t app.ts:501
    QCba index.ts:4
    QCba index.ts:3
    f src.515687e2.js:1
    parcelRequire src.515687e2.js:1
     src.515687e2.js:1
graphics.ts:822:14

firefox, ubuntu 20.04

Re: Ray Marching Soft Shadows in 2D

#17

Uncaught Error: Failed to get uniform location for name O get graphics.ts:822 value graphics.ts:950 value graphics.ts:1234 value graphics.ts:493 value renderer.ts:355 value renderer.ts:471 onFrame app.ts:631 t app.ts:501 QCba index.ts:4 QCba index.ts:3 f src.515687e2.js:1 parcelRequire src.515687e2.js:1 src.515687e2.js:1 graphics.ts:822:14 firefox, ubuntu 20.04

Thanks! I just pushed a fix. Does it work now?

Re: Ray Marching Soft Shadows in 2D

#20

That’s pretty nice. And impressive how this just runs on my iPad Air 2. For anyone getting interested in distance functions and ray marching, whether it is in 2D or 3D, Inigo Quilez [1] is the authority in this field. [1]: https://www.iquilezles.org/

Thanks! I've learned a ton from iq's writing. He's such an inspiration!

I find that his articles are best for folks who already know a thing or two about computer graphics. Here's a post that I think is pretty good for beginners: http://jamie-wong.com/2016/07/15/ray-marching-signed-distanc...

Post reply on HN