Hello,
I’ve been lurking around for years so I figured I should contribute something for a change!
So what we have here is a small collection of very, very simple shaders that I have ended up using extensively in every project I’ve done lately. Basically I wanted something that I can use to shade single quads that have a texture, a static color or a combination with alpha blending for the iDevices. Having zero experience in shader programming (I’m a designer) I did some research and came up with the following shaders:
Draw a texture as-is with no hassle:
Shader "2D/Texture Only"
{
Properties
{
_MainTex ("Texture", 2D) = ""
}
SubShader
{
ZWrite On // "Off" might make more sense in very specific games
Pass
{
SetTexture[_MainTex]
}
}
}
Use case:
Flat planes (quads) with textures. A background image in a 2D game perhaps?
Draw a texture as-is with alpha blending:
Shader "2D/Texture Only Alpha"
{
Properties
{
_MainTex ("Texture", 2D) = ""
}
Category
{
ZWrite Off
Tags {"Queue" = "Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
SubShader
{
Pass
{
SetTexture[_MainTex]
}
}
}
}
Use case:
Flat planes (quads) with textures that have transparency. For example UI elements and/or 2D sprites.
Draw a texture as-is with a color tint and alpha blending:
Shader "2D/Texture Color Alpha"
{
Properties
{
_Color ("Color Tint", Color) = (1,1,1,1)
_MainTex ("Texture", 2D) = ""
}
Category
{
ZWrite Off
Tags {"Queue" = "Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
SubShader
{
Pass
{
SetTexture[_MainTex] {Combine texture * constant ConstantColor[_Color]}
}
}
}
}
Use case:
Flat planes (quads) with textures that have transparency and need to be colored or faded. Combine with iTween animations for extremely smooth looking, fading UI elements! ![]()
Shader "2D/Color Only Alpha"
{
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
}
Category
{
ZWrite Off
Tags {"Queue" = "Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
SubShader
{
Pass
{
Color [_Color]
}
}
}
}
Use case:
Flat planes (quads) with solid colors that can be faded. Great for placeholder elements or a full screen fade-to-grey quad behind your pause menu for that extra smooth feel.
I would imagine that these aren’t a big help for people in this forum, but I sure would have wanted them back in the days. Any feedback is greatly appreciated. I was thinking of posting them to the wiki and possibly as a free pack to the asset store if they get the community’s blessing.
Also, alpha testing is off on each of these since apparently it’s very expensive on the iDevice GPU family.
Future ideas:
I was thinking of a set of additive blending shaders and an XNA-style color tint (it feels more like photoshop’s multiply-blend mode) but I’m not sure if they are actually useful for the general population ![]()
So there we go! Feel free to send me a love letter if you find these shaders useful. I know I do!