Hello Guest  /  Join  /  Sign In  /  Get Desura
Avatar

Gamieon

Christopher joined Mar 14, 2009

Offline Since
Jul 24, 2014
Country
United States United States
Gender
Male
Homepage
Gamieon.com
Contact
Private Message
Email
Members Only
ICQ
387263084
AIM
DrgnSlyr188

Red Orchestra Level

12

Gamieon is a privately owned entertainment software development company located in Tampa, Florida. Since October of 2004, we have aimed to provide quality video game software which emphasizes both intellectual and action-driven challenge to the gaming community. Gamieon depends on the talent of individuals working as a team to develop video games and video game engines with a focus on exceptional game play and surrealism.

Blog RSS Report abuse Fast Diamond Shader For Unity Android

0 comments by Gamieon on Nov 14th, 2013

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):

code:
Shader "FX/Diamond Mobile"
{
  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!

Check out my homepage and social feeds

And my projects!

Comments
ArtisanCodesmith
ArtisanCodesmith Sep 24 2012, 7:38am said:

I'm new to IndieDB and ModDB and wish to invite a few people (random people picked from the online list lol) to view my game and start generating a few opinions, do you mind taking a quick look? The game is called Arkanius. Thanks, Artisan Codesmith. :)

+2 votes     reply to
AlexVSharp
AlexVSharp Jan 30 2012, 6:07pm said:

Wow, well written. You should include this article in the Unity Dev's group. ;)

+3 votes     reply to
Post a Comment
click to sign in and comment

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Desura
Desura Official group with 11,513 members
Unity devs
Unity devs Hobbies & Interests group with 1,040 members
Desura Publishing
Desura Publishing Official group with 185 members
Gamieon
Gamieon Developer with 4 members
Friends
Namelessness
Namelessness friends since Apr 26, 2013
swiftseraph
swiftseraph friends since Jun 3, 2011
Original_Speeder
Original_Speeder friends since Jun 4, 2011
hermesdavidms
hermesdavidms friends since Jan 2, 2011
shaulhadar
shaulhadar friends since Nov 29, 2011
NullSoldier
NullSoldier friends since Jun 4, 2011
Accolades
Desura
Statistics
Activity Points
879
Rank
2,192 of 466,389
Watchers
5 members
Time Online
13 hours
Comments
12
Site Visits
2,002
Profile Visitors
52,169 (1 today)
Twitter
Latest tweets from @gamieon
Finally got a basic 3v3 AI soccer match working in Unreal. Next milestone will have weapons. T.co #indiedev Sep 26 2014, 10:24pm
Finished my first Unreal Editor AI soccer milestone. Read my journal and download the project T.co #indiedev Sep 15 2014, 8:01pm
Teaching Unreal Editor AI how to play soccer; so far so good! T.co #indiegame #indiedev Sep 11 2014, 9:22pm
Posted new images plus the video on Reddit #screenshotsaturday as well T.co Aug 23 2014, 12:00am
Got prototype bots and a soccer ball on the field for my Unreal game T.co #indiegame #indiedev Aug 22 2014, 11:36pm
Starting a new prototype for a #indiegame I came up with a few days ago. Unreal makes it easy to do! T.co Aug 21 2014, 8:52pm
Also posted some screenshots for Screenshot Saturday on Reddit T.co Aug 16 2014, 12:03am
Spent a few more hours making another zone in my Unreal game prototype. Good content, good engine! T.co Aug 15 2014, 10:47pm
Decided to learn Unreal Editor 4 development for fun. Made this in about 20 hrs from scratch w/ their assets T.co Aug 15 2014, 5:50pm
Taking a long break from Unity development. Tinkering with Unreal Engine while I try to form a team for #papercowboys Aug 1 2014, 8:12am