Created
November 4, 2019 11:19
-
-
Save gonchar/7490ac707cd09de2b75978521971c377 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/BlendTextures" | |
{ | |
Properties | |
{ | |
_MainTex ("Texture", 2D) = "white" {} | |
_MainTex2 ("Texture", 2D) = "white" {} | |
} | |
SubShader | |
{ | |
Tags { "Queue"="Transparent" "RenderType"="Transparent" "IgnoreProjector"="True" } | |
LOD 200 | |
ZWrite Off | |
Blend SrcAlpha OneMinusSrcAlpha | |
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; | |
sampler2D _MainTex2; | |
float4 _MainTex_ST; | |
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 | |
{ | |
float4 dst = tex2D (_MainTex, i.uv); | |
float4 src = tex2D (_MainTex2, i.uv); | |
float final_alpha = clamp(src.a + dst.a * (1.0 - src.a), 0.0, 1.0); | |
float3 finalColor = float3(0.0, 0.0, 0.0); | |
if (final_alpha > 0.0) { | |
finalColor = (src.rgb * src.a + dst.rgb * dst.a * (1.0 - src.a)) / final_alpha; | |
} | |
return float4(finalColor, final_alpha); | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment