Advice - GLSL Shaping functions

Hey guys,

Is there somebody here who is working with GLSL ? If yes, I would like to get some advices from you.
Let’s say if you want to create a particular or a complex shape. How do you think in making it ? How do you combine different functions like mod, abs, fract, floor etc… ? Where do you know which function to use and when ?

I already started to read thebookofshaders, but I can’t figure out the way of thinking in creating shapes.

Hope you can help me!
Thank you!

Typically (and certainly when first starting out with shaders) you don’t procedural generate shapes using functions in the shader. You launch draw calls to which you provide mesh data (vertex data and connections) which define those shapes, and this causes the shaders to be run under-the-hood to process them (specifically, to process their vertices, or shade the pixels they cover).

I’d suggest getting some simple, basic GLSL experience under your belt with these typical use cases. That’ll teach you a lot. Then go looking at procedural modification in the shader of incoming mesh shape. And after that if you want, you can look at completely GPU-side generation of shape form and shading inside of shaders.

1 Like

Hi,
Thank you for your reply. I already worked with opengl, made some tutorials from learnopengl.com, so i know how the things work. What I want to do, are things like those you find on shadertoy or in the website mentioned when i opened the topic.
It would be helpful if the replies are strictly on what I asked for. :stuck_out_tongue:

1 Like

Learn math. It’s hard to give more a specific answer to such a vague question.

Hi, probably you should look into a technique called ‘raymarching’ where you can write "distance fields’ for basic primitives (sphere, cube, etc) and use operations like union, intersection or exclusion to combine them into more complex shapes. A good intro into raymarching and SDF’s (SDF = Signed Distance Field) is Inigo Quilez’s talk “Rendering Worlds with Two Triangles” or his website… unfortunately its forbidden to post links here, but you’ll find it easily.

As for what function to use when - start with a simple scene and try to understand how various SDF’s work - you can find libraries with many primitives and operations online - such as MERCURY’s HG_SDF…

No, it’s not forbidden. New users just can’t post them (largely because that’s the first thing spammers want to do).