Doing some GLSL, again
Something like 5 years ago, I dabbled a little with glsl on the gl-transitions project of @greweb. It was really fun (the “I don’t really know what I’m doing” kind of fun :-D), and I learned a lot. Since, I didn’t had the time to do some low-level webGL stuff.
This week-end, I wanted to do some low-level 2D shaders again (I’m not very good at this, but it’s fun :-D ).
It was also a pretext to:
- port to typescript the WebGL utility methods from Gregg Tavares: https://webglfundamentals.org/webgl/resources/webgl-utils.js.
- wrapping it in a Svelte component, with editable GLSL code, to be able to easily use it in my Svelte projects.
Next things on the topic, I’ll probably try WebGL2/GLSL #version 300 es.
Examples
(please note: the examples below are in webGL/GLSL 1.0, not 2.0)
It’s always fun to poke around in shaders code, and see what happens when you change a value, a function here and there and see the result. Be sure to try editing the code !
A simple example, with a gradient, and lot of sin/cos functions:
(move your mouse over the drawing!).
GLSL code (editable)
A more complex example, with a Voronoi (from Inigo Quilez)
GLSL code (editable)
References
- https://thebookofshaders.com/, all the theory and the basics about WebGL and shaders, explained in a very clear and accessible way.
- https://webgl2fundamentals.org/, (and its v2: https://webgl2fundamentals.org/) , a very good reference on WebGL(2), with a lot of examples. A perfect complement to the book of shaders.
- https://shadertoyunofficial.wordpress.com/ Lot of examples and tips and ticks, usable also in other contexts than shadertoy.
- https://iquilezles.org/ , the blog/website of Inigo Quilez. Tons of algorithms and techniques to learn from. Applicable to any programming language, not only GLSL.