IPhoneGems

From Unify Community Wiki
Jump to: navigation, search

Contents

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

Invalid language.

You need to specify a language like this: <source lang="html4strict">...</source>

Supported languages for syntax highlighting:

4cs, 6502acme, 6502kickass, 6502tasm, 68000devpac, abap, actionscript, actionscript3, ada, algol68, apache, applescript, apt_sources, asm, asp, autoconf, autohotkey, autoit, avisynth, awk, bascomavr, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, c_loadrunner, c_mac, caddcl, cadlisp, cfdg, cfm, chaiscript, cil, clojure, cmake, cobol, coffeescript, cpp, cpp-qt, csharp, css, cuesheet, d, dcs, delphi, diff, div, dos, dot, e, ecmascript, eiffel, email, epc, erlang, euphoria, f1, falcon, fo, fortran, freebasic, fsharp, gambas, gdb, genero, genie, gettext, glsl, gml, gnuplot, go, groovy, gwbasic, haskell, hicest, hq9plus, html4strict, html5, icon, idl, ini, inno, intercal, io, j, java, java5, javascript, jquery, kixtart, klonec, klonecpp, latex, lb, lisp, llvm, locobasic, logtalk, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, magiksf, make, mapbasic, matlab, mirc, mmix, modula2, modula3, mpasm, mxml, mysql, newlisp, nsis, oberon2, objc, objeck, ocaml, ocaml-brief, oobas, oracle11, oracle8, oxygene, oz, pascal, pcre, per, perl, perl6, pf, php, php-brief, pic16, pike, pixelbender, pli, plsql, postgresql, povray, powerbuilder, powershell, proftpd, progress, prolog, properties, providex, purebasic, pycon, python, q, qbasic, rails, rebol, reg, robots, rpmspec, rsplus, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, systemverilog, tcl, teraterm, text, thinbasic, tsql, typoscript, unicon, uscript, vala, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xbasic, xml, xorg_conf, xpp, yaml, z80, zxbasic


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
			}
		}
	           
	}
}

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.

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Tools