ReflectiveVertexlitSimple

From Unify Community Wiki
Jump to: navigation, search


Author: Eric Haines (Eric5h5)...not really, as this is mostly UT's code, but if you want to blame someone, that's me :)

Description

This is similar to the Reflective VertexLit shader, except it uses a slider to control amount of reflection, instead of using the alpha channel of the texture. Naturally this means it's far less flexible, but can be useful if you just want the entire texture to be reflective to some amount (and therefore uses a little less VRAM since you don't need an alpha channel). Basically this is a trivial modification of the built-in shader, with the Radeon 9000 code removed, as I have no idea how to write shaders for that kind of card. Hence it needs a SM 2.0 or later card to work.

ShaderLab - ReflectiveVertexLitSimple.shader

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 "Reflective/VertexLit Simple" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_SpecColor ("Spec Color", Color) = (1,1,1,1)
	_Shininess ("Shininess", Range (0.03, 1)) = 0.7
	_ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
	_MainTex ("Base (RGB)", 2D) = "white" {}
	_Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect }
	_RefStrength ("Reflection Strength", Range (0.01, 1)) = 0.7
}

Category {
	Tags { "RenderType"="Opaque" }
	Blend AppSrcAdd AppDstAdd
	Fog { Color [_AddFog] }

	// ------------------------------------------------------------------
	// ARB fragment program
	
	SubShader {
	
		// First pass does reflection cubemap
		Pass { 
			Name "BASE"
			Tags {"LightMode" = "Always"}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_fog_exp2
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"

struct v2f {
	V2F_POS_FOG;
	float2 uv : TEXCOORD0;
	float3 I : TEXCOORD1;
};

uniform float4 _MainTex_ST;

v2f vert(appdata_tan v)
{
	v2f o;
	PositionFog( v.vertex, o.pos, o.fog );
	o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);

	// calculate object space reflection vector	
	float3 viewDir = ObjSpaceViewDir( v.vertex );
	float3 I = reflect( -viewDir, v.normal );
	
	// transform to world space reflection vector
	o.I = mul( (float3x3)_Object2World, I );
	
	return o; 
}

uniform sampler2D _MainTex;
uniform samplerCUBE _Cube;
uniform float4 _ReflectColor;
uniform float _RefStrength;

half4 frag (v2f i) : COLOR
{
	half4 texcol = tex2D (_MainTex, i.uv);
	half4 reflcol = texCUBE( _Cube, i.I );
	reflcol *= _RefStrength;
	return reflcol * _ReflectColor;
} 
ENDCG
		}
		
		// Second pass adds vertex lighting
		Pass {
			Lighting On
			Material {
				Diffuse [_Color]
				Emission [_PPLAmbient]
				Specular [_SpecColor]
				Shininess [_Shininess]
			}
			SeparateSpecular On
CGPROGRAM
#pragma fragment frag
#pragma fragmentoption ARB_fog_exp2
#pragma fragmentoption ARB_precision_hint_fastest

#include "UnityCG.cginc"

struct v2f {
	float2 uv : TEXCOORD0;
	float4 diff : COLOR0;
	float4 spec : COLOR1;
};

uniform sampler2D _MainTex : register(s0);
uniform float4 _ReflectColor;
uniform float4 _SpecColor;

half4 frag (v2f i) : COLOR
{
	half4 temp = tex2D (_MainTex, i.uv);	
	half4 c;
	c.xyz = (temp.xyz * i.diff.xyz + temp.w * i.spec.xyz ) * 2;
	c.w = temp.w * (i.diff.w + Luminance(i.spec.xyz) * _SpecColor.a);
	return c;
} 
ENDCG
			SetTexture[_MainTex] {}
		}		
	}
}

// Fallback for cards that don't do cubemapping
FallBack "VertexLit", 1

}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Tools