- Home /
How do I create an unlit reflective shader.
I need a shader that has maincolor, reflection color, Base (RGB) texture, and a reflection cubemap.
Basically the built in "reflective/ bumped unlit" shader, minus the normal map support.
However, in my failed attempts to modify and remove the normal map input, I found that i shouldn't use a surface shader if the material is not going to use lighting. Alas, I cannot find a vertex-fragment, or fixed function shader anywhere that supports cubemapped reflections.
Does anyone know where to find one?
I already have a simple unlit textured shader (obviously), but no reference in how to add cubemapped reflections to it. Help please. It would be much appreciated.
Or if someone can show me how to remove the normal map from this shader I would take that as well. Even though it sounds like that might not be best practice, it will work for me for now. Thanks.
Shader "Custom/Reflective-NOTBumped_Unlit_rf" {
Properties {
_Color ("$$anonymous$$ain Color", Color) = (1,1,1,1)
_ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
_$$anonymous$$ainTex ("Base (RGB), RefStrength (A)", 2D) = "white" {}
_Cube ("Reflection Cubemap", Cube) = "" { TexGen CubeReflect }
_Bump$$anonymous$$ap ("Normalmap", 2D) = "bump" {}
}
Category {
Tags { "RenderType"="Opaque" }
LOD 250
// ------------------------------------------------------------------
// Shaders
SubShader {
// Always drawn reflective pass
Pass {
Name "BASE"
Tags {"Light$$anonymous$$ode" = "Always"}
CGPROGRA$$anonymous$$
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float2 uv2 : TEXCOORD1;
float3 I : TEXCOORD2;
float3 TtoW0 : TEXCOORD3;
float3 TtoW1 : TEXCOORD4;
float3 TtoW2 : TEXCOORD5;
};
uniform float4 _$$anonymous$$ainTex_ST, _Bump$$anonymous$$ap_ST;
v2f vert(appdata_tan v)
{
v2f o;
o.pos = mul (UNITY_$$anonymous$$ATRIX_$$anonymous$$VP, v.vertex);
o.uv = TRANSFOR$$anonymous$$_TEX(v.texcoord,_$$anonymous$$ainTex);
o.uv2 = TRANSFOR$$anonymous$$_TEX(v.texcoord,_Bump$$anonymous$$ap);
o.I = -WorldSpaceViewDir( v.vertex );
TANGENT_SPACE_ROTATION;
o.TtoW0 = mul(rotation, _Object2World[0].xyz * unity_Scale.w);
o.TtoW1 = mul(rotation, _Object2World[1].xyz * unity_Scale.w);
o.TtoW2 = mul(rotation, _Object2World[2].xyz * unity_Scale.w);
return o;
}
uniform sampler2D _Bump$$anonymous$$ap;
uniform sampler2D _$$anonymous$$ainTex;
uniform samplerCUBE _Cube;
uniform fixed4 _ReflectColor;
uniform fixed4 _Color;
fixed4 frag (v2f i) : COLOR
{
// Sample and expand the normal map texture
fixed3 normal = UnpackNormal(tex2D(_Bump$$anonymous$$ap, i.uv2));
fixed4 texcol = tex2D(_$$anonymous$$ainTex,i.uv);
// transform normal to world space
half3 wn;
wn.x = dot(i.TtoW0, normal);
wn.y = dot(i.TtoW1, normal);
wn.z = dot(i.TtoW2, normal);
// calculate reflection vector in world space
half3 r = reflect(i.I, wn);
fixed4 c = UNITY_LIGHT$$anonymous$$O$$anonymous$$_A$$anonymous$$BIENT * texcol;
c.rgb *= 2;
fixed4 reflcolor = texCUBE(_Cube, r) * _ReflectColor * texcol.a;
return c + reflcolor;
}
ENDCG
}
}
// ------------------------------------------------------------------
// No vertex or fragment programs
SubShader {
Pass {
Tags {"Light$$anonymous$$ode" = "Always"}
Name "BASE"
BindChannels {
Bind "Vertex", vertex
Bind "Normal", normal
}
SetTexture [_Cube] {
constantColor [_ReflectColor]
combine texture * constant
}
}
}
}
FallBack "VertexLit", 1
}