Created
September 3, 2019 06:12
-
-
Save Demkeys/61201a27a23162d9d3450b446225e64d to your computer and use it in GitHub Desktop.
Simple texture blending shader that blends 3 textures of varying tiling and offsets.
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/TextureBlendShader" | |
{ | |
Properties | |
{ | |
_MainTex01 ("Texture01", 2D) = "white" {} | |
_MainTex02 ("Texture02", 2D) = "white" {} | |
_MainTex03 ("Texture03", 2D) = "white" {} | |
[Header(Fragment RGBA Multipliers)] | |
_FragR ("FragR", Range(0,5)) = 1 | |
_FragG ("FragG", Range(0,5)) = 1 | |
_FragB ("FragB", Range(0,5)) = 1 | |
_FragA ("FragA", Range(0,5)) = 1 | |
} | |
SubShader | |
{ | |
Tags { "RenderQueue"="Geometry" } | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
sampler2D _MainTex01; float4 _MainTex01_ST; | |
sampler2D _MainTex02; float4 _MainTex02_ST; | |
sampler2D _MainTex03; float4 _MainTex03_ST; | |
float _FragR; float _FragG; float _FragB; float _FragA; | |
float Remap(float value, float low1, float high1, float low2, float high2) | |
{ | |
return low2 + (value - low1) * (high2 - low2) / (high1 - low1); | |
} | |
void vert ( | |
float4 pos : POSITION, | |
out float4 opos : SV_POSITION, | |
float2 texCoord0 : TEXCOORD0, | |
out float4 otexCoord0 : TEXCOORD0, | |
out float4 otexCoord1 : TEXCOORD1 | |
) | |
{ | |
opos = UnityObjectToClipPos(pos); | |
_MainTex01_ST.z = sin(radians(_Time.x)); | |
_MainTex01_ST.w = sin(radians(_Time.x/10)); | |
_MainTex02_ST.z = _Time.x/5; | |
_MainTex02_ST.w = -(_Time.x/10); | |
_MainTex03_ST.z = -(_Time.x/9); | |
_MainTex03_ST.w = sin(radians(_Time.x/5))*2; | |
_MainTex01_ST.x = Remap(sin(radians(_Time.y)),-1,1,1,1.5); | |
_MainTex01_ST.y = Remap(sin(radians(_Time.z/2)),-1,1,0.6,1.2); | |
_MainTex02_ST.x = Remap(sin(radians(_Time.x/5)),-1,1,0.5,1); | |
_MainTex02_ST.y = Remap(sin(radians(_Time.x/7)),-1,1,1,2); | |
_MainTex03_ST.x = Remap(sin(radians(_Time.x/15)),-1,1,1,1.5); | |
_MainTex03_ST.y = Remap(cos(radians(_Time.x/15)),-1,1,0.6,1.5); | |
otexCoord0.xy = texCoord0.xy * _MainTex01_ST.xy + _MainTex01_ST.zw; | |
otexCoord0.zw = texCoord0.xy * _MainTex02_ST.xy + _MainTex02_ST.zw; | |
otexCoord1.xy = texCoord0.xy * _MainTex03_ST.xy + _MainTex03_ST.zw; | |
otexCoord1.zw = 0; | |
} | |
float4 frag ( | |
float4 pos : SV_POSITION, | |
float4 texCoord0 : TEXCOORD0, | |
float4 texCoord1 : TEXCOORD1 | |
) : SV_TARGET | |
{ | |
float4 col1 = tex2D(_MainTex01, texCoord0.xy); | |
float4 col2 = tex2D(_MainTex01, texCoord0.zw); | |
float4 col3 = tex2D(_MainTex01, texCoord1.xy); | |
float4 fcol = float4(lerp(col1.rgb, col2.rgb, min(col1.r, col2.r)),1); | |
fcol.rgb = lerp(fcol.rgb, col3.rgb, min(col2.r, col3.r)); | |
fcol.r *= _FragR; | |
fcol.g *= _FragG; | |
fcol.b *= _FragB; | |
fcol.a *= _FragA; | |
return fcol; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment