- Home /
shader problem
I need to remove the green screen behind the character ...
I tried this code
Shader "Chromakey/Mask" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
//_MaskCol ("Mask Color", Color) = (1.0, 0.0, 0.0, 1.0)
Transparency ("Transparency", Range (0,1.0)) = 0.5
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 100
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
CGINCLUDE
#include "UnityCG.cginc"
uniform float Transparency;
half3 NormalizeColor (half3 color) {
//return color / max(dot(color, half3(1.0f/3.0f)), 0.0001);
return color / dot(color, fixed3(0.5,0.5,0.01));
}
half4 MaskColor (half3 mCol, half3 cCol) {
//half4 d = distance(NormalizeColor(mCol.rgb), NormalizeColor(cCol.rgb));
//return ((mCol.g - (mCol.r + mCol.b)) > Transparency ) ? d : half4(mCol.rgb,1.0);
return ((mCol.g - (mCol.r + mCol.b)) > Transparency ) ? half4(mCol.rgb,0.0) : half4(mCol.rgb,1.0);
//float e = 0.04f;
//return ( mCol.g <= e && mCol.r <= e && mCol.b <= e) ? half4(mCol.rgb,0.0) : half4(mCol.rgb,1.0);
//float f = 1.0f;
//if ((mCol.g - (mCol.r + mCol.b)) > Transparency )
// f = 0.0;
//return half4(mCol.rgb,f);
//return ((mCol.g - (mCol.r + mCol.b)) < Transparency ) ? half4(mCol.rgb,0.0) : half4(mCol.rgb,1.0);
}
ENDCG
Pass {
Lighting Off
//Cull Off ZWrite On Lighting Off Fog { Mode off }
//Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
uniform sampler2D _MainTex;
uniform float4 _MaskCol;
half4 frag (v2f_img i) : COLOR {
half4 col = tex2D(_MainTex, i.uv);
half4 mask = MaskColor(col.rgb, _MaskCol.rgb);
//return col * mask;
return mask;
}
ENDCG
}
}
Fallback off
}
but the problem , some green line around the character didn't disapper , is there away to change it to clear all the green layer ?
then I searched a lot and found this site talk about the same situation , but by using mask at the same image ( normal image and mask at the same image )
but the shader dosen't work fine
Shader "Custom/VideoAlpha" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_AlphaOffsetX ("alpha offset x", float) = 0.5
_AlphaOffsetY ("alpha offset y", float) = 0
_Cutoff ("Cutoff", Range (0,1)) = .5
}
SubShader {
AlphaTest Less [_Cutoff]
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
float _AlphaOffsetX;
float _AlphaOffsetY;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
half4 c = tex2D (_MainTex, IN.uv_MainTex);
IN.uv_MainTex.x += _AlphaOffsetX;
IN.uv_MainTex.y += _AlphaOffsetY;
half4 d = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = (d.r*-1)+1;
}
ENDCG
}
FallBack "Diffuse"
}
i added to the material then add this image
but no change at all , where the problem ?
thank you ...
Note : I need it to work with Images and video
soizickeytest-400.jpg
(47.9 kB)
Comment