How to apply multiple shader effects
I'm trying to learn about shaders but I'm stuck on this issue.
I have a green screen video that I want to key, and then apply a feathered mask to.
I have 2 shaders that work separately but when I merge them, it does both of the effects, but overlaid on one another, as if its 2 video clips.
What I want to achieve is to key the video first and then apply the feather mask to the keyed video.
I have tried to use a Pass to try and render the effect in between, but it doesn't seem to work.
Here is the shader I'm working with:
Shader "ChromaMask"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Alpha ("Alpha", Range(0,1)) = 1
_MaskTex ("Masking Texture", 2D) = "white"{}
_Sens ("Sensibilidad", Range (0,.9)) = .3
_Cutoff ("Recorte", Range (0,.9)) = .2
_Color ("Chroma", Color) = (0, 1.0, 0)
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
"PreviewType"="Plane"
"CanUseSpriteAtlas"="True"
}
Cull Off
Lighting Off
ColorMask RGBA
ZWrite Off
Blend One OneMinusSrcAlpha
Stencil
{
Ref 1
Comp always
Pass replace
}
Pass{
Name "Masking"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _ PIXELSNAP_ON
#include "UnityCG.cginc"
struct appdata_t
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
half2 texcoord : TEXCOORD0;
};
v2f vert(appdata_t IN)
{
v2f OUT;
OUT.vertex = UnityObjectToClipPos(IN.vertex);
OUT.color = IN.color;
OUT.texcoord = IN.texcoord;
return OUT;
}
sampler2D _MainTex;
sampler2D _MaskTex;
Float _Alpha;
fixed4 frag(v2f IN) : SV_Target
{
fixed4 original = tex2D(_MainTex, IN.texcoord);
fixed4 masked = tex2D(_MaskTex, IN.texcoord);
return fixed4(original.r * masked.a * _Alpha, original.g * masked.a * _Alpha,original.b * masked.a * _Alpha, masked.a * _Alpha);
}
ENDCG
}
CGPROGRAM
#pragma surface surf Lambert alpha:blend
sampler2D _MainTex;
float _Cutoff;
float _Sens;
half3 _Color;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
float aR = abs(c.r - _Color.r) < _Sens ? abs(c.r - _Color.r) : 1;
float aG = abs(c.g - _Color.g) < _Sens ? abs(c.g - _Color.g) : 1;
float aB = abs(c.b - _Color.b) < _Sens ? abs(c.b - _Color.b) : 1;
float a = (aR + aG + aB) / 3;
if(a < _Cutoff){
o.Alpha = 0;
}else{
o.Alpha = 1;
}
}
ENDCG
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613010627im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Weird bug with the refraction on my water shader 0 Answers
I need a two Color gradient shader with alpha settings for for the top color. 0 Answers
Combine 2 Shaders,Combine 2 shaders 0 Answers
When or how are we going to get Custom Functions on Shader Graph now 0 Answers
How to hide objects inside of- or behind another transparent object? 2 Answers