I’m having trouble on figuring out how to scroll a texture in a surface shader. What I’m trying to make is a surface shader that has both rim lighting (which is implemented) and has a texture which scrolls around the object it’s on. This is my shader up to now:
Shader "Custom/StarShader" {
Properties{
_Color("Color", Color) = (1,1,1,1)
_MainTex("Texture", 2D) = "white" {}
_SubTex("Texture", 2D) = "white" {}
_RimColor("Rim Color", Color) = (0.26,0.19,0.16,0.0)
_RimPower("Rim Power", Range(0.1,2.0)) = 3.0
_ScrollXSpeed("X", Range(0,10)) = 2
_ScrollYSpeed("Y", Range(0,10)) = 3
}
SubShader{
Tags{ "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert
struct Input {
float2 uv_MainTex;
float2 uv_SubTex;
float3 viewDir;
fixed _ScrollXSpeed;
fixed _ScrollYSpeed;
};
sampler2D _MainTex;
sampler2D _SubTex;
float4 _RimColor;
float _RimPower;
fixed4 _Color;
void surf(Input IN, inout SurfaceOutput o) {
fixed2 scrolledUV = IN.uv_MainTex;
fixed xScrollValue = _ScrollXSpeed * _Time;
fixed yScrollValue = _ScrollYSpeed * _Time;
scrolledUV += fixed2(xScrollValue, yScrollValue);
half4 c = tex2D(_MainTex, scrolledUV);
o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
o.Albedo += c.rbg;
half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal));
o.Emission = _RimColor.rgb * pow(rim, _RimPower);
}
ENDCG
}
Fallback "Diffuse"
}
I simply want to find a way on how to scroll the texture around the object via a shader. I’m getting multiple “Undefined variable” errors trying it this way.