<div dir="ltr">Hey all,<div><br></div><div>I recently discovered that the power of a modern GPU allows brute-forcing <a href="https://en.wikipedia.org/wiki/Constructive_solid_geometry">constructive solid geometry</a> (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.</div><div><br></div><div>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.</div><div><br></div><div>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:</div><div><ul><li>Create An Entity</li><li>Move the entity 3 units along the X axis</li><li>The entity is a box</li><li>The entity should be joined to the existing entities with a "difference" operation</li></ul></div><div>A mini version you can play with is available online here: <a href="https://www.shadertoy.com/view/ttXcWH">https://www.shadertoy.com/view/ttXcWH</a> </div><div>The scene description begins on line 52.</div><div><br></div><div>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).</div><div><br></div><div>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.</div><div><br></div><div>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 <a href="https://github.com/sdfgeoff/sdf_designer_failed">https://github.com/sdfgeoff/sdf_designer_failed</a> </div><div><br></div><div>Geoffrey</div><div><br></div><div><br></div><div><br></div><div><br></div></div>