Created
April 22, 2013 22:59
-
-
Save Petethegoat/5439317 to your computer and use it in GitHub Desktop.
Shader for Unity that vertex blends two textures with a mask. Imperfect.
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/VertexBlendMaskedCleanEdges" { | |
Properties | |
{ | |
_Over ("Over", 2D) = "white" {} | |
_Under ("Under", 2D) = "white" {} | |
_Mask ("Mask", 2D) = "white" {} | |
_Bias ("Edge Bias", Range(0.5, 30.0)) = 4.0 | |
_Edge ("Edge Sharpness", Float) = 10.0 | |
_Fall ("Blend Falloff", Float) = 1.0 | |
} | |
SubShader | |
{ | |
Tags | |
{ | |
"Queue" = "Geometry-100" | |
"RenderType" = "Opaque" | |
} | |
CGPROGRAM | |
#pragma surface surf Lambert | |
struct Input | |
{ | |
float2 uv_Under : TEXCOORD0; | |
float2 uv_Over : TEXCOORD1; | |
float2 uv_Mask : TEXCOORD2; | |
float4 color : COLOR; | |
}; | |
sampler2D _Over,_Under,_Mask; | |
float _Edge; | |
float _Bias; | |
float _Fall; | |
void surf (Input IN, inout SurfaceOutput o) | |
{ | |
fixed3 mask = tex2D (_Mask, IN.uv_Mask); | |
fixed3 col; | |
mask = mask.r; | |
mask *= IN.color.r; | |
mask *= _Bias; | |
mask = pow(mask, _Edge); | |
mask = clamp((mask.r - IN.color.r) / _Fall, 0.0, 1.0); | |
col = tex2D (_Under, IN.uv_Under).rgb * 1 - mask.r; | |
col = max(tex2D (_Over, IN.uv_Over).rgb * mask.r, col); | |
o.Albedo = col; | |
o.Alpha = 0.0; | |
} | |
ENDCG | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome!
ایول حال کردم