Last active
May 24, 2016 06:04
-
-
Save arunkarnann/d7a1aedc4f824cc38971f9f56a57f6db to your computer and use it in GitHub Desktop.
Moving single channel in a Texture(RGB) Unity3d shader
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 "Custom/ThreeColorShaderBackUp" { | |
properties{ | |
//_MainTex("Main Texture",2D) = "white"{} | |
_MainTint ("Tint Color",color)=(1,1,1,1) | |
_ColorA ("Color A",color)=(1,1,1,1) | |
_ColorB ("Color B",color)=(1,1,1,1) | |
_RChannelTex("R Channel",2D)=""{} | |
_GChannelTex("G Channel",2D)=""{} | |
_BlendTex("AlphaGuide Texture",2D)=""{} | |
_ScrollXSpeed ("Scroll Speed in X",Range(0,10))=2 | |
_ScrollYSpeed ("Scroll Speed in Y",Range(0,10))=2 | |
} | |
SubShader{ | |
Tags { "RenderType"="Transparent" "RenderQueue"="Transparent"} | |
LOD 200 | |
CGPROGRAM | |
#pragma surface surf Lambert | |
float4 _MainTint; | |
float4 _ColorA; | |
float4 _ColorB; | |
float _ScrollXSpeed; | |
float _ScrollYSpeed; | |
sampler2D _RChannelTex; | |
sampler2D _GChannelTex; | |
sampler2D _BlendTex; | |
struct Input{ | |
float2 uv_RChannelTex; | |
float2 uv_GChannelTex; | |
float2 uv_BlendTex; | |
}; | |
void surf (Input IN, inout SurfaceOutput o) { | |
float4 rTexData = tex2D(_RChannelTex,IN.uv_RChannelTex); | |
float4 gTexData = tex2D(_GChannelTex,IN.uv_GChannelTex); | |
float4 blendTexData = tex2D(_BlendTex,IN.uv_BlendTex); | |
float4 finalColor; | |
finalColor = rTexData; | |
finalColor.a = 1.0; | |
fixed2 ScrolledUV = IN.uv_GChannelTex; | |
float XScrollValue = _ScrollXSpeed * _Time; | |
float YScrollValue = _ScrollYSpeed * _Time; | |
ScrolledUV += fixed2(XScrollValue,YScrollValue); | |
half4 c = tex2D(_GChannelTex, ScrolledUV); | |
float terrainLayers = lerp(_ColorA,_ColorB,blendTexData.r); | |
finalColor *= terrainLayers; | |
finalColor = saturate(finalColor); | |
o.Emission = c.rgb; | |
o.Albedo = (finalColor.rgb + c.rgb) * _MainTint.rgb; | |
o.Alpha = finalColor.a; | |
} | |
ENDCG | |
} | |
FallBack "Diffuse" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment