unityShader之裁剪效果

xiaoxiao2021-02-28  19

本文转载自http://blog.csdn.net/yiwei151/article/details/78622365。。效果:

Shader代码:

// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' Shader "Custom/CaiQie" { Properties{ _Color("Color",Color)=(1,1,1,1) _P("p",Range(-0.5,0.51))=0 } SubShader{ Pass{ Cull OFF CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" float4 _Color; float _P; struct a2v{ float4 vertex:POSITION; float4 texcoord:TEXCOORD0; }; struct v2f{ float4 pos:POSITION; float4 uv:TEXCOORD0; }; v2f vert(a2v v){ v2f o; o.uv = v.vertex; o.pos=UnityObjectToClipPos(v.vertex); return o; } fixed4 frag(v2f i):COLOR{ if(i.uv.y<_P){ discard; } return _Color; } ENDCG } } }

新建一个材质球,选择此shader,修改P值即可看到效果,当然,根据不同的模型,跟适当修改shader中P的取值范围!!!!

<link rel="stylesheet" href="http://csdnimg.cn/release/phoenix/production/markdown_views-993eb3f29c.css" /> </div>
转载请注明原文地址: https://www.6miu.com/read-1950161.html

最新回复(0)