Reveal Non-Uniform Texture
Author: Joe Schultz
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).
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.
- Reveal Texture shader in action! The pain bar (skeleton) to the left uses this shader.
ShaderLab - RevealTexture_Alpha.shader
- 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.