Skip to content

Instantly share code, notes, and snippets.

@jeedee
Created October 12, 2010 15:49
Show Gist options
  • Save jeedee/622405 to your computer and use it in GitHub Desktop.
Save jeedee/622405 to your computer and use it in GitHub Desktop.
Shader "Transparent/ReflectiveVertexLit" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
_Shininess ("Shininess", Range (0.01, 1)) = 0.078125
_ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
_MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
_Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect }
}
Category {
Tags {Queue=Transparent}
Blend AppSrcAdd OneMinusSrcAlpha
Fog { Color [_AddFog] }
// ------------------------------------------------------------------
// ARB fragment program
SubShader {
// First pass does reflection cubemap
Pass {
Name "BASE"
Tags {"LightMode" = "Always"}
CGPROGRAM
// profiles arbfp1
// fragment frag
// fragmentoption ARB_fog_exp2
// fragmentoption ARB_precision_hint_fastest
// vertex vert
#include "UnityCG.cginc"
struct v2f {
V2F_POS_FOG;
float2 uv : TEXCOORD0;
float3 I : TEXCOORD1;
};
v2f vert(appdata_tan v)
{
v2f o;
PositionFog( v.vertex, o.pos, o.fog );
o.uv = TRANSFORM_UV(0);
// 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 : register(s0);
uniform samplerCUBE _Cube : register(s1);
uniform float4 _ReflectColor;
half4 frag (v2f i) : COLOR
{
half4 texcol = tex2D (_MainTex, i.uv);
half4 reflcol = texCUBE( _Cube, i.I );
reflcol *= texcol.a;
return reflcol * _ReflectColor;
}
ENDCG
SetTexture[_MainTex] {combine texture}
SetTexture[_Cube] {combine texture}
}
// Second pass adds vertex lighting
Pass {
Lighting On
Material {
Diffuse [_Color]
Emission [_PPLAmbient]
Specular [_SpecColor]
Shininess [_Shininess]
}
SeparateSpecular On
CGPROGRAM
// profiles arbfp1
// fragment frag
// fragmentoption ARB_fog_exp2
// 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] {combine texture}
}
}
// ------------------------------------------------------------------
// Radeon 9000
SubShader {
// First pass does reflection cubemap
Pass {
Name "BASE"
Tags {"LightMode" = "Always"}
CGPROGRAM
// vertex vert
#include "UnityCG.cginc"
struct v2f {
V2F_POS_FOG;
float2 uv : TEXCOORD0;
float3 I : TEXCOORD1;
};
v2f vert(appdata_tan v)
{
v2f o;
PositionFog( v.vertex, o.pos, o.fog );
o.uv = TRANSFORM_UV(0);
// 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;
}
ENDCG
Program "" {
SubProgram {
Local 0, [_ReflectColor]
"!!ATIfs1.0
StartConstants;
CONSTANT c0 = program.local[0];
EndConstants;
StartOutputPass;
SampleMap r0, t0.str;
SampleMap r1, t1.str;
MUL r1, r1, r0.a;
MUL r0, r1, c0;
EndPass;
"
}
}
SetTexture [_MainTex] {combine texture}
SetTexture [_Cube] {combine texture}
}
// Second pass adds vertex lighting
Pass {
Material {
Diffuse [_Color]
Ambient [_Color]
Shininess [_Shininess]
Specular [_SpecColor]
Emission [_Emission]
}
Lighting On
SeperateSpecular On
SetTexture [_MainTex] {
constantColor [_Color]
Combine texture * previous DOUBLE, texture * constant
}
}
}
// ------------------------------------------------------------------
// Old cards
SubShader {
Pass {
Name "BASE"
Tags {"LightMode" = "Always"}
Material {
Diffuse [_Color]
Ambient (1,1,1,1)
Shininess [_Shininess]
Specular [_SpecColor]
}
Lighting On
SeparateSpecular on
SetTexture [_MainTex] {
combine texture * primary DOUBLE
}
SetTexture [_Cube] {
combine texture * previous alpha + previous
Matrix [_Reflection]
}
}
}
}
// Fallback for cards that don't do cubemapping
FallBack " VertexLit", 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment