When developing Domino Arena, I experimented with using diamond/crystal shaders for the dominoes while deciding the look and feel of the game. I found a mobile diamond shader at Wiki.unity3d.com by BurningThumb. It worked great for most PC's (there was one report of the dominoes not rendering however), but it was slow on my Asus EEE tablet. I could not get a frame rate better than 30 fps during normal game play.
The Unity profiler revealed that much of the time spent working in each frame was with transparent rendering; partly because of the dominoes, and partly because I called GUI.DrawTexture() way too much (which I fixed).
I'm very inexperienced with shader development, but I figured the least I could try was commenting out all code in the shader that had the word "Transparent" in it. To my surprise it actually had the desired effect: The frame rate went back up to 60 fps, and the diamond dominoes still looked like diamond dominoes with an unexpected caveat: They look transparent where they did not before. I don't exactly know why (again, I'm not an experienced shader developer) but it wasn't a big deal since dominoes don't obstruct each other during normal game play anyway.
Here's the shader code I ended up with (you can tell which parts I commented out):
{
Properties {
_Color ("Color", Color) = (1,1,1,1)
_Fog("Fog", Color) = (0,0,0,0)
_ReflectTex ("Reflection Texture", Cube) = "dummy.jpg" {
TexGen CubeReflect
}
_RefractTex ("Refraction Texture", Cube) = "dummy.jpg" {
TexGen CubeReflect
}
_RefractTexlow ("Refraction LowGPU", 2D) = "dummy.jpg" {
TexGen SphereMap
}
_ReflectTexlow ("Reflect LowGPU", 2D) = "dummy.jpg" {
TexGen SphereMap
}
_Shininess ("Shininess", Range (0.01, 1)) = 0.7
_SpecColor ("Specular", Color) = (1,1,1,1)
_Emission ("Emissive", Color) = (1,1,1,1)
}
SubShader {
//Tags {
//"Queue" = "Transparent"
//}
// First pass - here we render the backfaces of the diamonds. Since those diamonds are more-or-less
// convex objects, this is effectively rendering the inside of them
Pass {
Color (0,0,0,0)
Offset -1, -1
Cull Front
ZWrite Off
SetTexture [_RefractTex] {
constantColor [_Color]
combine texture * constant, primary
}
SetTexture [_ReflectTex] {
combine previous, previous +- texture
}
}
// Second pass - here we render the front faces of the diamonds.
Pass {
Fog { Color (0,0,0,0)}
ZWrite on
Blend One One
SetTexture [_RefractTex] {
constantColor [_Color]
combine texture * constant
}
SetTexture [_ReflectTex] {
combine texture + previous, previous +- texture
}
}
}
// Older cards. Here we remove the bright specular highlight
SubShader {
//Tags{"Queue" = "Transparent"}
// First pass - here we render the backfaces of the diamonds. Since those diamonds are more-or-less
// convex objects, this is effectively rendering the inside of them
Pass {
Color (0,0,0,0)
Cull Front
SetTexture [_RefractTex] {
constantColor [_Color]
combine texture * constant, primary
}
}
// Second pass - here we render the front faces of the diamonds.
Pass {
Fog { Color (0,0,0,0)}
ZWrite on
Blend DstColor Zero
SetTexture [_RefractTex] {
constantColor [_Color]
combine texture * constant
}
}
}
/////////// Start iphone code////////////////
//This will cause a nice gem texture to be rendered using the low-GPU textures defined in the inspector//
//This section of the code is provided by BURNING THUMB SOFTWARE, 2010//
SubShader {
Pass {
Lighting On
SeparateSpecular On
Color (0,0,0,0)
// Offset -1, -1
Cull Front
//Blend OneMinusSrcAlpha One
SetTexture [_ReflectTexlow] {
constantColor [_Color]
combine texture * constant, primary
}
}
// Second pass - here we render the front faces of the diamonds.
Pass {
Fog { Color [_Fog]}
ZWrite on
Blend One One
SetTexture [_RefractTexlow] {
constantColor [_Emission]
combine texture * constant
}
}
}
// We need this for shadows
FallBack "Diffuse"
}
If you want to see it in action, just check out my game Domino Arena when it comes to Android!