国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 編程設(shè)計(jì) > 正文

Unity3D中shader 輪廓描邊效果實(shí)現(xiàn)代碼

2020-02-02 19:00:49
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

Unity3D中shader 輪廓描邊效果

想利用Unity3D中shader這個(gè)功能實(shí)現(xiàn)描邊輪廓邊框效果該怎么做呢,相信有很多搞開(kāi)發(fā)的人想知道,為此下面就給大家介紹下方法。

  Shade實(shí)現(xiàn)描邊效果,如下圖中的3D球效果圖

          Shade代碼如下:

Shader "Outlined/Silhouetted Diffuse" {  Properties {  _Color ("Main Color", Color) = (1,1,1,1)  _OutlineColor ("Outline Color", Color) = (0,0,0,1) //改變這個(gè)能改變輪廓邊的顏色  _Outline ("Outline width", Range (0.0, 0.03)) = 0.008 //改變這個(gè)能改變輪廓邊的粗細(xì)  _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 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; } 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 SrcAlpha 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"  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  }  }  }    SubShader {  Tags { "Queue" = "Transparent" }   Pass {  Name "OUTLINE"  Tags { "LightMode" = "Always" }  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 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" } 

  以上就是Unity3D中利用shader這個(gè)功能實(shí)現(xiàn)描邊輪廓邊框效果的方法,不會(huì)的話就直接那這串代碼去嘗試吧。

       感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 罗定市| 海安县| 夹江县| 五台县| 石渠县| 哈尔滨市| 吉首市| 舞钢市| 克山县| 会宁县| 镇远县| 遂平县| 贵州省| 叶城县| 崇文区| 乐东| 玉树县| 景洪市| 神农架林区| 临猗县| 九龙城区| 临洮县| 惠州市| 滁州市| 高邮市| 金昌市| 民勤县| 清水河县| 湟中县| 尚义县| 永济市| 四平市| 玉林市| 宣威市| 策勒县| 彰化市| 鸡东县| 浏阳市| 祁东县| 仁化县| 涞水县|