Hello
I have no programming experience of shaders but I need to chroma key a video that has been shot on green background.
I found that code in a forum http://forum.unity3d.com/threads/11512-Using-a-texture-s-RGB-as-an-Alpha
But I believe it was written for U2
I am on U3 now and I get an error that I mention in the title.
Is there somwhere I this related to the p rogramming model for shaders or is it a syntax error, in which case I need to find out where I can look for solving it?
Any help is welcome
yves
anyone, please?
Which code are we talking about?
Looks like you need to post the code.
I am struggling with a similar problem.
I have tried to add a “empty” vertex program on my own, with no success, since you are obliged to pass at least a Position output from vertex programs, and I can’t get it right.
He’s mentioning the following code:
Shader "FX/GreenToAlpha" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_Cutoff ("Cutoff", Range (0,1)) = .5
}
SubShader {
Pass {
CGPROGRAM
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
struct v2f {
float4 pos : POSITION;
float4 uv : TEXCOORD0;
};
half4 frag (v2f i) : COLOR
{
half4 color = tex2D(_MainTex, i.uv.xy);
return half4(color.r, color.g, color.b, color.g - ( (color.r * .5) + (color.b * .5)));
//return half4(color.r, color.g, color.b, color.g);
}
ENDCG
AlphaTest Less [_Cutoff]
} // pass
} // subshader
Fallback "Transparent/Diffuse"
} // shader
Looks like it’s ok, now.
I added the missing vertex program, and just passed the original position and uv to fragment.
Hope it helps.
Shader "FX/GreenToAlpha" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_Cutoff ("Cutoff", Range (0,1)) = .5
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#include "UnityCG.cginc"
sampler2D _MainTex;
struct v2f {
float4 pos : POSITION;
float4 uv : TEXCOORD0;
};
v2f vert (appdata_base v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv = float4( v.texcoord.xy, 0, 0 );
return o;
}
half4 frag (v2f i) : COLOR
{
half4 color = tex2D(_MainTex, i.uv.xy);
return half4(color.r, color.g, color.b, color.g - ( (color.r * .5) + (color.b * .5)));
}
ENDCG
AlphaTest Less [_Cutoff]
} // pass
} // subshader
Fallback "Transparent/Diffuse"
} // shader