I've been wanting to try out raymarching on real 3D scenes to implement effects like AO, soft-shadows and such.

I pretty much know how to use signed distance functions (as described by Inigo Quilez) to approximate a model and raymarch it, but I want to have way more precision and have the distance field of my scene.

How would you go about generating a (un)signed distance field from the depth buffer in screen space ? Or would the usual depth buffer be usable as a distance field (I don't think so) ? Or there might be better ways that don't use the depth buffer ?

  • \$\begingroup\$ Quoting an Inigo Quilez article you've probably read, "One of the many [advantages] of distance fields, is that they naturally provide global information" - but a depth buffer generated from traditional rasterized geometry does not. There are techniques for approximating neighbourhood information from a depth buffer, eg. Screen Space Ambient Occlusion (SSAO), but there's no simple way to "upgrade" a depth buffer into a distance field representation of your scene (in particular, depth buffers omit all information about occluded / off-screen details) \$\endgroup\$ – DMGregory Dec 18 '16 at 16:25
  • \$\begingroup\$ Surprisingly, I haven't seen this quote. And, in fact, it definitely makes sense. So, the depth buffer is almost out of question. \$\endgroup\$ – CpCd0y Dec 18 '16 at 22:57
  • \$\begingroup\$ Bear in mind, most games achieve their effects just fine with traditional rasterized geometry. Even games that use distance fields under the hood (like MediaMolecule's Dreams) tend to do their rendering with a more conventional pipeline. So, if there's a visual effect you want, there's probably a way to do it with a depth buffer — you'd just use different methods than you would with a signed distance field representation. \$\endgroup\$ – DMGregory Dec 18 '16 at 23:44
  • \$\begingroup\$ Well, I was reading UE4's ray traced distance field shadows page and I was asking myself what method they use to generate a distance field per mesh even when using a conventional rendering pipeline. \$\endgroup\$ – CpCd0y Dec 19 '16 at 10:27
  • \$\begingroup\$ This is in their docs: "a small volume texture is mapped to every [static] object." — so they generate a 3D grid approximation of the distance field around static meshes in the scene before render time, separate from the conventional pipeline. \$\endgroup\$ – DMGregory Dec 19 '16 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.