Reveal Non-Uniform Texture

Author: Joe Schultz

Description
This simple shader & script is useful if you want to make a loading or progress bar using textures that are not rectilinear (i.e. boring). There's probably an easier / better way to do this, but this is what I came up with and it works fine. This is my first shader, so if you can refine it and make it better, please do!

Should work on vertex program capable hardware (Radeon 8500, GeForce3/4Ti, Intel 9xx) no problemo (though untested).

Usage
Use this shader on a base object, set the textures you want to use in the material properties, and finally use the script below (or similar) to "reveal" your base texture, based on some game parameter (percentage complete, love amount, etc.).


 * Create a material that uses the shader below (GUI/Reveal _Alpha).
 * Use this material on an object.
 * Set the Base (RGB) texture slot to the texture that you want to reveal (usually your colorful progress bar).
 * Set the Mix Mask (A) texture slot to the texture that you want to use to reveal; only the alpha of this texture matters, so get the alpha channel as you want the reveal edge to be. You can do jagged reveals, smooth blended, etc. (as you wish!)
 * NOTE: Mix Mask (A) texture should be set to Clamp via the texture properties in the Inspector for most use cases.
 * Update the Offset of the Mix Mask (A) texture in a script, such as the one provided below.
 * Enjoy!

Example
Larger version here...Updated image here
 * Reveal Texture shader in action! The pain bar (skeleton) to the left uses this shader.

ShaderLab - Alternate RevealTexture_Alpha.shader
In this alternate shader, I decided to use a Surface Shader (which allows for lighting support and tinting with very few steps, you can fake normals ad hoc since the sprite would be always facing the camera) and keep the pipeline premultiplied alpha friendly. This shader could be a bit faster than the fixed function inspired one due to the lower texture fetches and color combining operations. Note: with surface shaders you must specify a custom lighting function to avoid the system messing up with elements without proper vertex normal data available.

History

 * Looks like I originally had pasted an old version. Here is the latest that actually uses Diffuse _Color. Still would like to figure a way to use the diffuse color's Alpha, but don't have a pressing need at the moment.