ReflectiveVertexlitSimple

From Unify Community Wiki
Revision as of 09:46, 1 October 2008 by Eric5h5 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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

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

  1. pragma vertex vert
  2. pragma fragment frag
  3. pragma fragmentoption ARB_fog_exp2
  4. pragma fragmentoption ARB_precision_hint_fastest
  5. 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

  1. pragma fragment frag
  2. pragma fragmentoption ARB_fog_exp2
  3. pragma fragmentoption ARB_precision_hint_fastest
  1. 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

} </shaderlab>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox