0
\$\begingroup\$

I am working on a sandbox app that model stuff using SDF and its operators. I want to do the actual rendering on GPU. So once the SDF is defined (ex. box union with sphere, etc.) how do I push it to the GPU?

What currently comes in my mind is to define all possible SDF functions also on the GPU shader and map them to short command strings, send an array of commands to GPU (union, box, sphere, etc.) and call the mapped functions. Is there a better way?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Normally the way this would be done is to compose the code you want your SDF shader to evaluate, as text or shader intermediate language, then ask the graphics driver to compile the generated code into a bespoke shader.

That's for instance how all the SDF demos on ShaderToy work: at runtime, on page load or after a modification by the user, the user-provided shader text is compiled to a new shader and executed.

\$\endgroup\$
2
  • \$\begingroup\$ Compiling shader takes some time, i need it to be instant. So there needs to be another way. I wonder how magicaCSG does it. \$\endgroup\$
    – trshmanx
    Dec 21, 2021 at 4:18
  • \$\begingroup\$ Try editing your question to tell us more about your game's use case. The better we can understand your circumstances, the better we may be able to identify special case solutions that fit those circumstances, and might be faster than a fully general solution like this one. \$\endgroup\$
    – DMGregory
    Dec 21, 2021 at 4:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .