Shader recap

November 29, 2012

So far I've posted 9 articles here covering different techniques for making OpenGL shaders.

For those of you that have been following and trying things out, I thought this might be a good place for a recap.

I introduced the different built-in functions of GLSL as we needed them to achieve different goals, but at some point you might have been wishing for a compact reference to all the available functions.


More noise

November 23, 2012

Now we have a function which can give us a random-ish looking number between 0-1 for every pixel we render with a shader.

By using floor as we did earlier with continuous numbers, we can now have a random number for each different region of the image.



Noise from numbers

November 22, 2012


Sometimes, a little noise is all you need to go from synthetic to organic.

The world is unpredictable, and that makes it interesting.

The same rules applies to shaders - unpredictable output makes for more interesting and natural-looking results. So how do you make a shader output unpredictable results?


Continuously discrete

November 5, 2012


Smooth looking images have every pixel quite similar to the ones all around them, while still being different enough to form a picture that isn't just one solid colour.

When a shader program is used to make an image, it is typically fed with input values (say x and y coordinates) that are only slightly different for each pixel.

If those slight differences are preserved in the calculations the shader makes, the output image will be smooth.

Interesting images however need changes in them. Tools like step, mod and abs are good for creating those, but still they tend to generate quite predictable images, which are actually not so interesting.


Going round in squircles

October 29, 2012

If you were an N9 user, you might have noticed something about the shapes of many of the icons it used.

They weren't quite the usual squares, or even rectangles with rounded corners, but another shape called (I kid you not) a squircle, which if that wikipedia link is to be believed, is a kind of "superellipse".

Here's a picture of a squircle (in red) and a similar sized rounded rectangle (in green) so you can see the subtle differences:



Mixing it up a bit

October 29, 2012

With just a few shader functions like length, mod and max, I can make simple repeating shapes like squares, circles, and lines. With stretching and skewing of the coordinates, these can be moulded in all kinds of interesting ways.

But still, when I'm trying to create a more complex image, more techniques are needed.

One function that opens up a whole new world of possibilities is the GLSL blending function mix.


The Art of Repepetition

October 22, 2012


Sometimes, differences everywhere aren't what you need. Constraints, like limited memory, bandwidth or performance, call for a different strategy.

Filling large areas of space when you can't pick a unique colour for each point means mastering the art of repetition.


Square shaped shaders

October 16, 2012

We already saw how the GLSL (that's the OpenGL Shader Language) built-in function "length" can be used to calculate the distance of a point from the centre (0,0) - great for making circles.

GLSL has many other built in functions. Lets use a couple of those to make squarish shapes.:

vec2 r=abs(c.xy);


Learning to shade

October 10, 2012

A*(Note: ThNdl v1.0 had the live shader editor. thndl_3, which you are reading now, doesn't. Sorry)*

So far on ThNdl, I've shown you some simple OpenGL shaders, and teased you with some not-so-simple ones.

If the whole idea of shaders is new to you, you might be wondering how you can learn more about them. I think, as with most things, the best way to learn is by doing.