- Home /
Can i make this shader an alpha cutout
hi guys i was wondering that can i make this shader's _MainTex to a alpha cutout and if yes then how can i do it plz guide me on this i am realy new to shader writing so i cant figure out how to do it i ws trying to merge transparent cutout shader and the shader given below but it result in desater plz help code given below
Shader "Cg shader for billboards" {
Properties {
_MainTex ("Texture Image", 2D) = "white" {}
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// User-specified uniforms
uniform sampler2D _MainTex;
struct vertexInput {
float4 vertex : POSITION;
float4 tex : TEXCOORD0;
};
struct vertexOutput {
float4 pos : SV_POSITION;
float4 tex : TEXCOORD0;
};
vertexOutput vert(vertexInput input)
{
vertexOutput output;
output.pos = mul(UNITY_MATRIX_P,
mul(UNITY_MATRIX_MV, float4(0.0, 0.0, 0.0, 1.0))
- float4(input.vertex.x, input.vertex.z, 0.0, 0.0));
output.tex = input.tex;
return output;
}
float4 frag(vertexOutput input) : COLOR
{
return tex2D(_MainTex, float2(input.tex.xy));
}
ENDCG
}
}
}
any help wud b much appreciated.. thanks
I would suggest to post this question in shaderlab(Forum). http://forum.unity3d.com/forums/16-ShaderLab
Answer by whydoidoit · Aug 24, 2013 at 11:50 AM
Try something like this:
Shader "Cg shader for billboards" {
Properties {
_MainTex ("Texture Image", 2D) = "white" {}
_CutOff("Cut off", float) = 0.1
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// User-specified uniforms
uniform sampler2D _MainTex;
uniform float _CutOff;
struct vertexInput {
float4 vertex : POSITION;
float4 tex : TEXCOORD0;
};
struct vertexOutput {
float4 pos : SV_POSITION;
float4 tex : TEXCOORD0;
};
vertexOutput vert(vertexInput input)
{
vertexOutput output;
output.pos = mul(UNITY_MATRIX_P,
mul(UNITY_MATRIX_MV, float4(0.0, 0.0, 0.0, 1.0))
- float4(input.vertex.x, input.vertex.z, 0.0, 0.0));
output.tex = input.tex;
return output;
}
float4 frag(vertexOutput input) : COLOR
{
float4 color = tex2D(_MainTex, float2(input.tex.xy));
if(color.a < _CutOff) discard;
return color;
}
ENDCG
}
}
}
Thank you sooo much its working perfectly i asked for help that how can i do it but u came up with a a complet solution thanks once again cheers AR
But i have a slight problem with this shader coz in playmode my trees r dissapers i dnt knw may b its because it is billboarding/showing me the worng side of the planer can u plz help me with this to
i have checked this by adding $$anonymous$$us to the
input.vertex.x input.vertex.z but no luck so far
many thanks
Try sticking a:
Cull Off
In the pass - that'll tell us if it's only one sided.
it is working when i set the transform of my trees in 3ds max its working nicely thanks alot
and what if i wanted to add shadows in it
Your answer
![](https://koobas.hobune.stream/wayback/20220613112854im_/https://answers.unity.com/themes/thub/images/avi.jpg)