The objective of this shader was to produce an effect like electricity moving across the surface of the material, with minimal looping or otherwise repeating landmark patterns.
Initially, I considered a few options, for example a shader that simply shifted the offsets of an emissive texture across the surface of a mesh but I dismissed it as too visually repetitive.
Researching further, I happened across an older concept called Color Cycling or Palette Shifting, a technique which indexes the colors of an image, and then rather than changing the final color of a given pixel (as per modern norm), it changes the value of the index which the pixel sources its color from.
For example, a given pixel might start at Index0, and Index0 is pure white (#FFFFFF). One frame passes, and Index0 changes to slightly grey (#EEEEEE) so the pixel becomes slightly grey, this can continue for a full range of colors, as long as there isn't more than the index limit on screen at a time.
Various websites have compiled a a number of these images, usually with resources to visualize the effect and the indices.
This incredibly efficient effect can be used to simulate animation in an image, but when used in that fashion, it has problems with landmarks in the pattern, making it easy to see where and how the pattern loops.
I ended up calculating colors as per (something similar to) the above method twice, and adding the effects together. This, combined with shifting the two source maps independently, causes very interesting, emergent effects that have difficult to confidently identify as looping.
This was used as per the specifications for a shifting electrical effect. using two textures to calculate the emissive intensity on an electrified panel.
If I were to rewrite the shader, I would attempt to remove the if statements, as I'm now well aware of their inefficiency on GPUs, but I've since gained a wealth of experience with shaders, specifically with unity.
Comments