i combined two shaders from a toutrial video to make a shader that cutout a alpha map but it is not working can plz anyone tel me what i did wrong i am realy a noob at shader writing plz help here's the code Shader "Test/transparentCutout" { Properties { _Color("color",color)=(1.0,1.0,1.0,1.0) _MainTex ("Texture Image", 2D) = "white" {} _cutout ("cutout size",Range(0,1))=.5 } Subshader{ Tags{"Queue"=" Transparent"} Pass{ CGProgram #pragma vertex vert #pragma fragment frag uniform float4 _Color; uniform sampler2D _MainTex; uniform float4 _MainTex_ST; uniform float4 _cutout; struct vertexInput { float4 vertexosition; float4 texcoord : TEXCOORD0; }; struct vertexOutput { float4 pos : SV_POSITION; float4 vertpos : TEXCOORD0; float4 tex : TEXCOORD1; }; vertexOutput vert(vertexInput v){ vertexOutput o; o.pos=mul(UNITY_MATRIX_MVP,v.vertex); o.vertpos=v.vertex; o.tex = v.texcoord return o; } float4 frag(vertexOutput i): COLOR{ float4 tex = tex2D (_MainTex,_MainTex_ST.xy*i.tex.xy + _MainTex_ST.zw) float4 alpha= tex.a*_Color.a; if(i.vertpos.y > _cutout){ discard; } return float4(_Color.xyz,alpha) } ENDCG } } thanks in advance
Each line needs a semi-colon after it. float4 tex = tex2D (_MainTex,_MainTex_ST.xy*i.tex.xy + _MainTex_ST.zw) to float4 tex = tex2D (_MainTex,_MainTex_ST.xy*i.tex.xy + _MainTex_ST.zw); return float4(_Color.xyz,alpha) to return float4(_Color.xyz,alpha);
You're trying to set a float value from a float 4. float4 alpha= tex.a*_Color.a; if(i.vertpos.y > _cutout){ discard; } return float4(_Color.xyz,alpha) to float alpha= tex.a*_Color.a; if(i.vertpos.y > _cutout){ discard; } return float4(_Color.xyz,alpha)
Basically there are a ton of issues with your shader. Bad variable types, bad syntax, missing syntax, missing includes... I've added a comment to everything I've changed. Code (csharp): Shader "Test/transparentCutout" { Properties { _Color("color",color)=(1.0,1.0,1.0,1.0) _MainTex ("Texture Image", 2D) = "white" {} _cutout ("cutout size",Range(0,1))=0.5 } Subshader{ Tags{"Queue" = "Transparent"} // Removed space from before Transparent. Pass{ CGPROGRAM // Capitalised this. #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" // Included this file. uniform float4 _Color; uniform sampler2D _MainTex; uniform float4 _MainTex_ST; uniform float _cutout; // Changed this to float rather than float4. struct vertexInput { float4 vertex : POSITION; // float4 vertexposition; means nothing, I think you want this instead. float4 texcoord : TEXCOORD0; }; struct vertexOutput { float4 pos : SV_POSITION; float3 vertpos : TEXCOORD0; // Changed this to float3 rather than float4. float2 tex : TEXCOORD1; // Changed this to float2 rather than float4. }; vertexOutput vert(vertexInput v){ vertexOutput o; o.pos = mul(UNITY_MATRIX_MVP, v.vertex); o.vertpos = v.vertex.xyz; // Added .xyz. o.tex = v.texcoord.xy; // Added semicolon. Added .xy. return o; } float4 frag(vertexOutput i): COLOR{ float4 tex = tex2D(_MainTex, _MainTex_ST.xy * i.tex + _MainTex_ST.zw); // Added semicolon. Removed .xy from i.tex as it's now a float2. float alpha = tex.a * _Color.a; // Made this a float rather than float4. clip(i.vertpos.y - _cutout); // Changed if/discard to clip. return float4(_Color.xyz, alpha); // Added semicolon. } ENDCG } // Added end Pass bracket. } }
thank you so much fr your time but what can i say the shader is still n0t working properly it is cutting out but it dsnt displaying any materiel once again thanks fr making changes into the shader