Revised Reality (Revision 2022 4Kb Graphics Demo)

I’ve been watching graphics demos for many years now, and never thought that one day I’d actually make one myself. But this year I finally plucked up enough courage to create an entry for the awesome Revision 2022 competition.

I figured the best category for me would be ‘4Kb Executable Graphics’. The challenge is to write a single executable in less than 4096 bytes (which is tiny!) which produces a single static image.

To put this into perspective, if you were to take a screenshot of the image it would come in at over 6,000,000 bytes. So the code that creates the image must be over 1,500 times smaller than the image itself!

As frame rate is not a problem here I had to use different techniques to make this image – I actually only get 2 FPS on my machine!
Instead of performance I had to keep in mind code compressibility. That means firstly writing a small amount of code (obviously), and secondly reusing terms so the data compressor can do a better job of compressing.

I came in 8th place, which I’m extremely happy with. It was awesome to compete with such great coders!

The GLSL shader source can be found here.

Demozoo link
Pouët link

GLSL Shader Shrinker

I have been writing a tool over the last few months which will take GLSL shader code and optimize it in a variety of ways.

It can apply a range of changes from simply code reformatting, optimizing maths and function calls, all the way to GOLFing code.

‘Code golf’ is where you make attempts to make the source code as small as possible. Making a tool do this automatically (without breaking the code!) is quite a challenge, but the latest incarnation of my app has got the ‘The Small Step‘ shader code down to a little over 2Kb.

GLSL Shader Shrinker – Feel free to check it out – It’s free!
https://github.com/deanthecoder/GLSLShaderShrinker

Aliens (Scanner scene)

GLSL Shadertoy Shader

Another Aliens-themed shader, motivated by me watching this clip from the movie.

I try to add add something new each time I make a shader, and this time it was the ‘frost’ effect on the cryo pod and the noise in the ‘laser’.

The reflective helmet glass and laser effect were calculated using ray-sphere ray-plane intersections, allowing me to keep the ray-marching loop simple and fast.

The GLSL shader source can be found here.

The Exorcist (1973)

GLSL Shadertoy Shader

This is my first black and white shader, and also the first time I’ve mixed 2D and 3D content.

As ever, in an attempt to keep the code small and frame rate fast I make heavy use of domain repetition. For example, there’s actually only one window pane, and that makes all the windows on both walls!

The man is defined using 2D functions, and has a subtle animation to add some realism.

The GLSL shader source can be found here.

Happy New Year!

Innerspace (1989)

GLSL Shadertoy Shader

I challenge anyone to not like the Innerspace movie!

There’s a lot of new (to me) lighting effects in this shader. The headlights of the ‘pod’ are light cones with analytically solved ray start/end points, used to calculate the amount of ‘glow’ to apply.

I also make heavy use of domain repetition (where you use math to ‘duplicate’ regions of space) to make a whole stream of blood cells using only three modelled originals.

This is one of my longer shaders, running in at just under a minute.

The GLSL shader source can be found here.

The Alien

GLSL Shadertoy Shader

Another shader based on Alien, this one was an exercise in modelling and animation.

I started off with the dome of the head and the texture on it. It’s actually a simple gyroid pattern with a few colors mixed into it, but quite effective!

My awesome cousin (Check out his art here) gave me some tips for the animation – I added some ‘anticipation’ before the alien strikes. This means the head pulls back before striking forward, showing a build up of ‘energy’ and really improving the effect.

The GLSL shader source can be found here.

The Abyss (1989)

GLSL Shadertoy Shader

Continuing the trend of making GLSL Shadertoy shaders from my favourite films, the next on my list was The Abyss (1989).

I was stretching myself a bit with this one, practising my reflection/refraction/caustics skills whilst (as always) trying to keep a decent frame rate.

I would have loved to make the ‘face’ as good as the one in the movie, but alas the effort needed to model out far outweighed my GPU.

The GLSL shader source can be found here, and a 360° VR view here.

Dune (Sand Worm)

GLSL Shadertoy Shader

There’s a new Dune movie coming out soon, so I thought I’d make a ‘Dune’ shader (based on the 1984 version).

Nothing too complex in this scene. It’s the first time I’ve used polar coordinates in an SDF (for the teeth and mouth segments), but the landscape is just a simple FBM noise. Ripples are added outside of the SDF to keep the frame rate higher.

The GLSL shader source can be found here, and a 360° VR view here.

Arduino Code – Performance

I’m currently making a self balancing robot, powered by an Arduino Nano, and decided to use NEMA 17 stepper motors to power it.

The DRV8825 motor drivers are great, but cannot be driven using a PWM signal. Consequently the Arduino code must send a ‘step’ signal to the correct pin many times per second – Easily in the thousands if you require a decent amount of speed, especially if you’re micro-stepping.

Performance is critical…

Continue reading “Arduino Code – Performance”