Last active
May 10, 2022 15:13
-
-
Save TheCuttlefish/11fd4a195c6788460bdc22e1eafe293c to your computer and use it in GitHub Desktop.
Scroll Shader in Unity Standard Rendering Pipeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Unlit/Scroll" | |
{ | |
Properties | |
{ | |
_MainTex ("Texture", 2D) = "white" {} | |
_SpeedX ("_SpeedX", float) = 0.5 | |
_SpeedY("_SpeedY", float) = 0 | |
_Color("Color (RGBA)", Color) = (1, 1, 1, 1) | |
} | |
SubShader | |
{ | |
Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" } | |
ZWrite Off | |
//Blend SrcAlpha OneMinusSrcAlpha | |
LOD 100 | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
float2 uv : TEXCOORD0; | |
}; | |
struct v2f | |
{ | |
float2 uv : TEXCOORD0; | |
float4 vertex : SV_POSITION; | |
}; | |
sampler2D _MainTex; | |
float4 _MainTex_ST; | |
float _SpeedX,_SpeedY; | |
float4 _Color; | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
o.vertex = UnityObjectToClipPos(v.vertex); | |
o.uv = TRANSFORM_TEX(v.uv, _MainTex); | |
return o; | |
} | |
fixed4 frag (v2f i) : SV_Target | |
{ | |
half4 sub; | |
half2 uv = i.uv; | |
half t = (_Time.x * _SpeedX) - floor(_Time.x); | |
uv.x = i.uv.x + t; | |
half t2 = (_Time.x * _SpeedY) - floor(_Time.x); | |
uv.y = i.uv.y + t2; | |
fixed4 col = tex2D(_MainTex , uv) * _Color; | |
return col; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment