Monday 10 July 2017

Side Project: Random Shaders


Side Project: Random Shaders


Shaders can be very rewarding, I think mostly because of their inherent visuality; the results are instantly visible (or not, if something has gone wrong). It can also be highly experimental - the level of documentation varies wildly, requiring a lot of hands-on learning and exploration (which can be fun too).

As part of my experimentation with shader programming, I created some utility / random shaders. Some were made to solve particular problems, others were simply experiments / exercises to develop my knowledge or test theories I had on possible shaders. Here are some of my favourites (in no particular order).

1) Dynamic Text Recolouring.

I found I had a problem with text readability; if the font's colour didn't contrast enough with the background, the text was difficult or even impossible to read.
To fix this, I made a simple shader to be applied to the text which uses a grab pass to perform a per-pixel contrast check, and then swap the text based on the background colour. This means that text is (usually) readable, regardless of the background colour.
There are some cases (contrast-noisy textures, as with bright, but normal-mapped textures), which cause some issues with this method - the text can become noisy as well. To fix this problem, I am hoping to create a compute shader version in the future - which will swap the whole text if more than 50% of its pixels requires the contrast boost.



2) Color 'Rotation'

After theorising the results, I decided to try and create a shader which would rotate the color vector (rgb) of a light source by a specifiied amount. The result is a texture which receives a color-wheel from light sources. The frequency of the colors can be adjusted for some very strange effects!


Here is the same light, but with the frequency massively increased:



3) "Grey Light"

After playing around with light sources inside material shaders, I came up with an interesting project idea - a material which would fade to greyscale based on its illumination by lightsources. The end goal being a shader which allows the user to specify a lightsource to receive this effect from - and which otherwise behaves normally.



4) Additive Alpha Removal

When creating a range overlay effect for a strategy game, I encountered a lot of problems with additive alpha blending on transparent objects. This meant that the range area markers would overlap horribly. to fix this, I created a simple shader which uses the stencil buffer to limit the alpha of all pixels to the same amount - the results have been very useful.


5) Targeted Dynamic Colour Replacement

Another exercise, this shader has actually proven useful to several artist friends of mine (or so they tell me - maybe they're just being nice). This material shader will dynamically replace all instances of a specified colour with another specified colour. The accuracy of the colour comparison can be specified for artifact removal / experimentation.


The inspector is fairly self-explanatory, but just in case, ReplaceThis is the colour to be swapped out, and Replacement is the color to swap it to. The above settings provide this output:-



Well, that's all the shaders I wanted to show off for now. Hopefully you found some of them interesting!

No comments:

Post a Comment