|
| 1 | +Shader "Reflective/Bumped Unlit" { |
| 2 | +Properties { |
| 3 | + _Color ("Main Color", Color) = (1,1,1,1) |
| 4 | + _ReflectColor ("Reflection Color", Color) = (1,1,1,0.5) |
| 5 | + _MainTex ("Base (RGB), RefStrength (A)", 2D) = "white" {} |
| 6 | + _Cube ("Reflection Cubemap", Cube) = "" { TexGen CubeReflect } |
| 7 | + _BumpMap ("Normalmap", 2D) = "bump" {} |
| 8 | +} |
| 9 | + |
| 10 | +Category { |
| 11 | + Tags { "RenderType"="Opaque" } |
| 12 | + LOD 250 |
| 13 | + |
| 14 | + // ------------------------------------------------------------------ |
| 15 | + // Shaders |
| 16 | + |
| 17 | + SubShader { |
| 18 | + // Always drawn reflective pass |
| 19 | + Pass { |
| 20 | + Name "BASE" |
| 21 | + Tags {"LightMode" = "Always"} |
| 22 | +CGPROGRAM |
| 23 | +#pragma vertex vert |
| 24 | +#pragma fragment frag |
| 25 | + |
| 26 | +#include "UnityCG.cginc" |
| 27 | + |
| 28 | +struct v2f { |
| 29 | + float4 pos : SV_POSITION; |
| 30 | + float2 uv : TEXCOORD0; |
| 31 | + float2 uv2 : TEXCOORD1; |
| 32 | + float3 I : TEXCOORD2; |
| 33 | + float3 TtoW0 : TEXCOORD3; |
| 34 | + float3 TtoW1 : TEXCOORD4; |
| 35 | + float3 TtoW2 : TEXCOORD5; |
| 36 | +}; |
| 37 | + |
| 38 | +uniform float4 _MainTex_ST, _BumpMap_ST; |
| 39 | + |
| 40 | +v2f vert(appdata_tan v) |
| 41 | +{ |
| 42 | + v2f o; |
| 43 | + o.pos = mul (UNITY_MATRIX_MVP, v.vertex); |
| 44 | + o.uv = TRANSFORM_TEX(v.texcoord,_MainTex); |
| 45 | + o.uv2 = TRANSFORM_TEX(v.texcoord,_BumpMap); |
| 46 | + |
| 47 | + o.I = -WorldSpaceViewDir( v.vertex ); |
| 48 | + |
| 49 | + TANGENT_SPACE_ROTATION; |
| 50 | + o.TtoW0 = mul(rotation, _Object2World[0].xyz * unity_Scale.w); |
| 51 | + o.TtoW1 = mul(rotation, _Object2World[1].xyz * unity_Scale.w); |
| 52 | + o.TtoW2 = mul(rotation, _Object2World[2].xyz * unity_Scale.w); |
| 53 | + |
| 54 | + return o; |
| 55 | +} |
| 56 | + |
| 57 | +uniform sampler2D _BumpMap; |
| 58 | +uniform sampler2D _MainTex; |
| 59 | +uniform samplerCUBE _Cube; |
| 60 | +uniform fixed4 _ReflectColor; |
| 61 | +uniform fixed4 _Color; |
| 62 | + |
| 63 | +fixed4 frag (v2f i) : SV_Target |
| 64 | +{ |
| 65 | + // Sample and expand the normal map texture |
| 66 | + fixed3 normal = UnpackNormal(tex2D(_BumpMap, i.uv2)); |
| 67 | + |
| 68 | + fixed4 texcol = tex2D(_MainTex,i.uv); |
| 69 | + |
| 70 | + // transform normal to world space |
| 71 | + half3 wn; |
| 72 | + wn.x = dot(i.TtoW0, normal); |
| 73 | + wn.y = dot(i.TtoW1, normal); |
| 74 | + wn.z = dot(i.TtoW2, normal); |
| 75 | + |
| 76 | + // calculate reflection vector in world space |
| 77 | + half3 r = reflect(i.I, wn); |
| 78 | + |
| 79 | + fixed4 c = UNITY_LIGHTMODEL_AMBIENT * texcol; |
| 80 | + c.rgb *= 2; |
| 81 | + fixed4 reflcolor = texCUBE(_Cube, r) * _ReflectColor * texcol.a; |
| 82 | + return c + reflcolor; |
| 83 | +} |
| 84 | +ENDCG |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + // ------------------------------------------------------------------ |
| 89 | + // No vertex or fragment programs |
| 90 | + |
| 91 | + SubShader { |
| 92 | + Pass { |
| 93 | + Tags {"LightMode" = "Always"} |
| 94 | + Name "BASE" |
| 95 | + BindChannels { |
| 96 | + Bind "Vertex", vertex |
| 97 | + Bind "Normal", normal |
| 98 | + } |
| 99 | + SetTexture [_Cube] { |
| 100 | + constantColor [_ReflectColor] |
| 101 | + combine texture * constant |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +FallBack "VertexLit", 1 |
| 108 | + |
| 109 | +} |
0 commit comments