Unity3D描边效果.docx

上传人:牧羊曲112 文档编号:3168033 上传时间:2023-03-11 格式:DOCX 页数:7 大小:37.45KB
返回 下载 相关 举报
Unity3D描边效果.docx_第1页
第1页 / 共7页
Unity3D描边效果.docx_第2页
第2页 / 共7页
Unity3D描边效果.docx_第3页
第3页 / 共7页
Unity3D描边效果.docx_第4页
第4页 / 共7页
Unity3D描边效果.docx_第5页
第5页 / 共7页
亲,该文档总共7页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《Unity3D描边效果.docx》由会员分享,可在线阅读,更多相关《Unity3D描边效果.docx(7页珍藏版)》请在三一办公上搜索。

1、Unity3D描边效果Unity3D描边效果 Unity开发中,描边效果,使用Shader就可以轻松实现。这里先给出 效果图 但是我并不熟悉shader这一块,这里直接给出 shader 的代码: Shader Outlined/Silhouetted Diffuse Properties _Color (Main Color, Color) = (1,1,1,1) _OutlineColor (Outline Color, Color) = (0,0,0,1) /改变这个能改变轮廓边的颜色 _Outline (Outline width, Range (0.0, 0.03) = 0.008

2、/改变这个能改变轮廓边的粗细 _MainTex (Base (RGB), 2D) = white CGINCLUDE #include UnityCG.cginc struct appdata float4 vertex : POSITION; float3 normal : NORMAL; ; struct v2f float4 pos : POSITION; float4 color : COLOR; ; uniform float _Outline; uniform float4 _OutlineColor; v2f vert(appdata v) / just make a copy

3、of incoming vertex data but scaled according to normal direction v2f o; o.pos = mul(UNITY_MATRIX_MVP, v.vertex); float3 norm = mul (float3x3)UNITY_MATRIX_IT_MV, v.normal); float2 offset = TransformViewToProjection(norm.xy); o.pos.xy += offset * o.pos.z * _Outline; o.color = _OutlineColor; return o;

4、ENDCG SubShader Tags Queue = Transparent / note that a vertex shader is specified here but its using the one above Pass Name OUTLINE Tags LightMode = Always Cull Off ZWrite Off ZTest Always ColorMask RGB / alpha not used / you can choose what kind of blending mode you want for the outline Blend SrcA

5、lpha OneMinusSrcAlpha / Normal /Blend One One / Additive /Blend One OneMinusDstColor / Soft Additive /Blend DstColor Zero / Multiplicative /Blend DstColor SrcColor / 2x Multiplicative CGPROGRAM #pragma vertex vert #pragma fragment frag half4 frag(v2f i) :COLOR return i.color; ENDCG Pass Name BASE ZW

6、rite On ZTest LEqual Blend SrcAlpha OneMinusSrcAlpha Material Diffuse _Color Ambient _Color Lighting On SetTexture _MainTex ConstantColor _Color Combine texture * constant SetTexture _MainTex Combine previous * primary DOUBLE SubShader Tags Queue = Transparent Pass Name OUTLINE Tags LightMode = Alwa

7、ys Cull Front ZWrite Off ZTest Always ColorMask RGB / you can choose what kind of blending mode you want for the outline Blend SrcAlpha OneMinusSrcAlpha / Normal /Blend One One / Additive /Blend One OneMinusDstColor / Soft Additive /Blend DstColor Zero / Multiplicative /Blend DstColor SrcColor / 2x

8、Multiplicative CGPROGRAM #pragma vertex vert #pragma exclude_renderers gles xbox360 ps3 ENDCG SetTexture _MainTex combine primary Pass Name BASE ZWrite On ZTest LEqual Blend SrcAlpha OneMinusSrcAlpha Material Diffuse _Color Ambient _Color Lighting On SetTexture _MainTex ConstantColor _Color Combine texture * constant SetTexture _MainTex Combine previous * primary DOUBLE Fallback Diffuse 如果你看不懂,直接拿去在实例中测试一下就明白了。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号