subscribe via rss
23 Jul 2010

[Unify Wiki] IPhoneGems

Author: Unity3D News Pipe | Filed under: Technology

Summary:


*--[[User:BurningThumb|BurningThumb]] 23:09, 22 July 2010 (PDT)
*Attribution would be appreciated : http://www.Burningthumb.com

==Description==
The code provided by unity creates really bland gems if the GPU does not support cubemaps, which is true of iPhones. This modification to the shader in the unity gem pack fixes that issue.

==Usage==

This code behaves like the unity gem pack, except it also works on the iphone.

*Download the [http://unity3d.com/support/resources/assets/gem-shader.html Gem Shader]
*The iphone subshader will be chosen if the others can't be run, which they won't because they use cubemaps.
*You can replace the gem shader entirely with this script, however you may wish to simply put the iphone code before the last subshader in the gemshader so if spheremaps aren't supported it still renders.
*Textures applied to the "lowGPU" boxes in the inspector are used for the iphone.
*The emissive color changes how bright the gem is.
*The fog color is the colour this shader turns when the fog blocks it's geometry.


==Code==
<shaderlab>
Shader "FX/Diamond"
{
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
}
}

}
}
</shaderlab>
==Disclaimer==
'''We make no claim to have created the gem shader''', however the iphone code was written by us. '''Attribution would be appreciated if you chose to use it in your project.
'''

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>