[chbot] Scene description language for GPU's - a project failure
Geoff
sdfgeoff at gmail.com
Fri Jun 12 10:23:33 BST 2020
Hey all,
I recently discovered that the power of a modern GPU allows
brute-forcing constructive
solid geometry <https://en.wikipedia.org/wiki/Constructive_solid_geometry> (aka
how CAD programs work) on a per-pixel basis. As I know a bit of GLSL, I
endeavoured to create a small CAD program.
For those who know nothing about a GPU: you can treat it like a CPU with a
thousand cores, with the caveat that all the cores are performing the same
instruction at the same time. Typically you write a "shader" program that
gets executed for a region on the screen.
My idea was to define primitives (box, sphere), transformations (translate,
rotate) and boolean operations (union, intersect, difference) in a
declarative language. For example, you may say:
- Create An Entity
- Move the entity 3 units along the X axis
- The entity is a box
- The entity should be joined to the existing entities with a
"difference" operation
A mini version you can play with is available online here:
https://www.shadertoy.com/view/ttXcWH
The scene description begins on line 52.
Unfortunately I couldn't get the system performant enough to be useful. I
think this is because of the (by shader standards) high amount of memory
fetches required, or perhaps the instruction cache is getting hammered?
(There is zero information on the size of the instruction cache on modern
GPU's).
Anyway, there's a random failure that failed. If I could be bothered
continuing with making a CAD program, I'd probably dynamically generate the
shader. This would be slower when you edit the scene (as it would have to
recompile the shader), but would be faster on execution.
If nothing else, I learned a bunch of Rust, WebAssembly and WebGL and a
touch of the nightmare that is the web development ecosystem. Full project
repository https://github.com/sdfgeoff/sdf_designer_failed
Geoffrey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ourshack.com/pipermail/chchrobotics/attachments/20200612/11cec1c5/attachment.html>
More information about the Chchrobotics
mailing list