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.


The Pixel Swarm

October 3, 2012

Until quite recently, I was working a lot with Qt. One of the best and most fun features in the latest version - Qt5 - is the QML ShaderEffect, which lets you easily draw and animate almost anything to the screen using just a tiny OpenGL shader program.

If you aren't familiar with shaders, they are small programs - typically only a few lines of code - which are run directly on a GPU. But, be warned... once you start learning and writing them it's hard to stop!