正交相机下的结果
Shader "Cg discard" { SubShader { Pass { Cull Off // turn off triangle culling, alternatives are: // Cull Back (or nothing): cull only back faces // Cull Front : cull only front faces CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct vertexInput { float4 vertex : POSITION; }; struct vertexOutput { float4 pos : SV_POSITION; float4 posInObjectCoords : TEXCOORD0; }; vertexOutput vert(vertexInput input) { vertexOutput output; output.pos = mul(UNITY_MATRIX_MVP, input.vertex);//本地坐标转到屏幕空间 //output.posInObjectCoords=mul(_Object2World,input.vertex); //本地坐标转化到世界坐标 在世界坐标系进行discard output.posInObjectCoords= output.pos //裁剪空间进行discard return output; } float4 frag(vertexOutput input) : COLOR { if (input.posInObjectCoords.y < 0.0) { discard; // drop the fragment if y coordinate > 0 } return float4(0.0, 1.0, 0.0, 1.0); // green } ENDCG } } }