最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Unity Shader實(shí)現(xiàn)素描風(fēng)格的渲染

 更新時(shí)間:2020年04月29日 10:28:09   作者:vvc223c  
這篇文章主要為大家詳細(xì)介紹了Unity Shader實(shí)現(xiàn)素描風(fēng)格的渲染,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Unity Shader實(shí)現(xiàn)素描風(fēng)格的具體代碼,供大家參考,具體內(nèi)容如下

原理

使用6張素描紋理進(jìn)行渲染,在渲染階段,在頂點(diǎn)著色階段計(jì)算逐頂點(diǎn)的光照,根據(jù)光照結(jié)果決定6張紋理的混合權(quán)重,并傳遞給片元著色器。在片元著色器中根據(jù)這些權(quán)重來混合6張紋理的采樣結(jié)果

Shader實(shí)現(xiàn)

Shader "Hatching" 
{
 Properties {
 _Color ("Color Tint", Color) = (1, 1, 1, 1)//顏色
 _TileFactor ("Tile Factor", Float) = 1//紋理的平鋪系數(shù),數(shù)值越大素描線條越密
 _Outline ("Outline", Range(0, 1)) = 0.1
 _Hatch0 ("Hatch 0", 2D) = "white" {}
 _Hatch1 ("Hatch 1", 2D) = "white" {}
 _Hatch2 ("Hatch 2", 2D) = "white" {}
 _Hatch3 ("Hatch 3", 2D) = "white" {}
 _Hatch4 ("Hatch 4", 2D) = "white" {}
 _Hatch5 ("Hatch 5", 2D) = "white" {}//對(duì)應(yīng)的6張素描紋理
 }
 
 SubShader {
 Tags { "RenderType"="Opaque" "Queue"="Geometry"}
 
 
 Pass {
 Tags { "LightMode"="ForwardBase" }
 
 CGPROGRAM
 
 #pragma vertex vert
 #pragma fragment frag 
 
 #pragma multi_compile_fwdbase
 
 #include "UnityCG.cginc"
 #include "Lighting.cginc"
 #include "AutoLight.cginc"
 #include "UnityShaderVariables.cginc"
 
 fixed4 _Color;
 float _TileFactor;
 sampler2D _Hatch0;
 sampler2D _Hatch1;
 sampler2D _Hatch2;
 sampler2D _Hatch3;
 sampler2D _Hatch4;
 sampler2D _Hatch5;
 
 struct a2v {
 float4 vertex : POSITION;
 float4 tangent : TANGENT; 
 float3 normal : NORMAL; 
 float2 texcoord : TEXCOORD0; 
 };
 
 struct v2f {
 float4 pos : SV_POSITION;
 float2 uv : TEXCOORD0;
 fixed3 hatchWeights0 : TEXCOORD1;//
 fixed3 hatchWeights1 : TEXCOORD2;// 6個(gè)混合權(quán)重,存在兩個(gè)fixed3變量中
 float3 worldPos : TEXCOORD3;
 SHADOW_COORDS(4)
 };
 
 v2f vert(a2v v) {
 v2f o;
 
 o.pos = UnityObjectToClipPos(v.vertex);
 
 o.uv = v.texcoord.xy * _TileFactor;
 
 fixed3 worldLightDir = normalize(WorldSpaceLightDir(v.vertex));
 fixed3 worldNormal = UnityObjectToWorldNormal(v.normal);
 fixed diff = max(0, dot(worldLightDir, worldNormal));//漫反射系數(shù)
 
 o.hatchWeights0 = fixed3(0, 0, 0);
 o.hatchWeights1 = fixed3(0, 0, 0);
 
 float hatchFactor = diff * 7.0;//把diff縮放到[0,7]范圍
 
 //純白
 if (hatchFactor > 6.0) 
 {
 
 } else if (hatchFactor > 5.0) {
  o.hatchWeights0.x = hatchFactor - 5.0;
 } else if (hatchFactor > 4.0) {
  o.hatchWeights0.x = hatchFactor - 4.0;
  o.hatchWeights0.y = 1.0 - o.hatchWeights0.x;
 } else if (hatchFactor > 3.0) {
  o.hatchWeights0.y = hatchFactor - 3.0;
  o.hatchWeights0.z = 1.0 - o.hatchWeights0.y;
 } else if (hatchFactor > 2.0) {
  o.hatchWeights0.z = hatchFactor - 2.0;
  o.hatchWeights1.x = 1.0 - o.hatchWeights0.z;
 } else if (hatchFactor > 1.0) {
  o.hatchWeights1.x = hatchFactor - 1.0;
  o.hatchWeights1.y = 1.0 - o.hatchWeights1.x;
 } else {
  o.hatchWeights1.y = hatchFactor;
  o.hatchWeights1.z = 1.0 - o.hatchWeights1.y;
 }
 
 o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
 
 TRANSFER_SHADOW(o);
 
 return o; 
 }
 
 fixed4 frag(v2f i) : SV_Target 
 { //根據(jù)相應(yīng)的權(quán)重進(jìn)行采樣
 fixed4 hatchTex0 = tex2D(_Hatch0, i.uv) * i.hatchWeights0.x;
 fixed4 hatchTex1 = tex2D(_Hatch1, i.uv) * i.hatchWeights0.y;
 fixed4 hatchTex2 = tex2D(_Hatch2, i.uv) * i.hatchWeights0.z;
 fixed4 hatchTex3 = tex2D(_Hatch3, i.uv) * i.hatchWeights1.x;
 fixed4 hatchTex4 = tex2D(_Hatch4, i.uv) * i.hatchWeights1.y;
 fixed4 hatchTex5 = tex2D(_Hatch5, i.uv) * i.hatchWeights1.z;
 fixed4 whiteColor = fixed4(1, 1, 1, 1) * (1 - i.hatchWeights0.x - i.hatchWeights0.y - i.hatchWeights0.z - 
  i.hatchWeights1.x - i.hatchWeights1.y - i.hatchWeights1.z);
 
 fixed4 hatchColor = hatchTex0 + hatchTex1 + hatchTex2 + hatchTex3 + hatchTex4 + hatchTex5 + whiteColor;
 
 UNITY_LIGHT_ATTENUATION(atten, i, i.worldPos);
  
 return fixed4(hatchColor.rgb * _Color.rgb * atten, 1.0);
 }
 
 ENDCG
 }
 }
 FallBack "Diffuse"
}

效果如下:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • .NET中的async和await關(guān)鍵字使用及Task異步調(diào)用實(shí)例

    .NET中的async和await關(guān)鍵字使用及Task異步調(diào)用實(shí)例

    這篇文章主要介紹了.NET中的async和await關(guān)鍵字使用及Task異步調(diào)用實(shí)例,本文還包含了取消執(zhí)行和顯示進(jìn)度的例子,需要的朋友可以參考下
    2014-07-07
  • c# 委托詳解

    c# 委托詳解

    本文將通過實(shí)例解析對(duì)c# 委托進(jìn)行詳細(xì)介紹,具有很好的參考價(jià)值,下面跟著小編一起來看下吧
    2017-02-02
  • C# 多線程更新界面的錯(cuò)誤的解決方法

    C# 多線程更新界面的錯(cuò)誤的解決方法

    這篇文章主要介紹了C# 多線程更新界面的錯(cuò)誤方法,由于一個(gè)線程的程序,如果調(diào)用一個(gè)功能是阻塞的,那么就會(huì)影響到界面的更新,導(dǎo)致使用人員操作不便。所以往往會(huì)引入雙線程的工作的方式,主線程負(fù)責(zé)更新界面和調(diào)度,而次線程負(fù)責(zé)做一些阻塞的工作,便有了下面春雨里方法
    2021-10-10
  • C#使用迭代器實(shí)現(xiàn)文字動(dòng)態(tài)效果的示例代碼

    C#使用迭代器實(shí)現(xiàn)文字動(dòng)態(tài)效果的示例代碼

    這篇文章主要為大家詳細(xì)介紹了C#如何通過使用迭代器實(shí)現(xiàn)文字動(dòng)態(tài)效果,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-02-02
  • sqlserver備份還原數(shù)據(jù)庫(kù)功能封裝分享

    sqlserver備份還原數(shù)據(jù)庫(kù)功能封裝分享

    這篇文章主要介紹了sqlserver備份還原數(shù)據(jù)庫(kù)功能封裝示例,需要的朋友可以參考下
    2014-03-03
  • C#使用ADO.Net部件來訪問Access數(shù)據(jù)庫(kù)的方法

    C#使用ADO.Net部件來訪問Access數(shù)據(jù)庫(kù)的方法

    數(shù)據(jù)庫(kù)的訪問是所有編程語(yǔ)言中最重要的部分,C#提供了ADO.Net部件用于對(duì)數(shù)據(jù)庫(kù)進(jìn)行訪問。本文從最簡(jiǎn)單易用的微軟Access數(shù)據(jù)庫(kù)入手討論在C#中對(duì)數(shù)據(jù)庫(kù)的訪問。
    2015-09-09
  • c#數(shù)據(jù)綁定之linq使用示例

    c#數(shù)據(jù)綁定之linq使用示例

    本實(shí)例以MS AdventureWorks2008Entities數(shù)據(jù)庫(kù)為基礎(chǔ),演示了LINQ TO ENTITY、LINQ TO ENTITYSQL和LINQ TO ENTITYCLIENT。
    2014-04-04
  • C#上位機(jī)與三菱PLC通訊的實(shí)現(xiàn)步驟(圖文)

    C#上位機(jī)與三菱PLC通訊的實(shí)現(xiàn)步驟(圖文)

    這篇文章主要介紹了C#上位機(jī)與三菱PLC通訊的實(shí)現(xiàn)步驟(圖文),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-02-02
  • UGUI實(shí)現(xiàn)4位驗(yàn)證碼輸入

    UGUI實(shí)現(xiàn)4位驗(yàn)證碼輸入

    這篇文章主要為大家詳細(xì)介紹了UGUI實(shí)現(xiàn)4位驗(yàn)證碼輸入,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-12-12
  • C#讀取中文文件出現(xiàn)亂碼的解決方法

    C#讀取中文文件出現(xiàn)亂碼的解決方法

    這篇文章主要介紹了C#讀取中文文件出現(xiàn)亂碼的解決方法,涉及C#中文編碼的操作技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-05-05

最新評(píng)論

霍邱县| 锡林浩特市| 盘山县| 卢龙县| 家居| 盈江县| 宜良县| 广灵县| 民勤县| 霍州市| 青岛市| 台南县| 濮阳市| 建阳市| 河池市| 北碚区| 宁晋县| 陵川县| 屯昌县| 区。| 新晃| 鹤岗市| 台前县| 罗田县| 栖霞市| 张北县| 阿勒泰市| 香格里拉县| 巴彦淖尔市| 称多县| 田东县| 溧水县| 黄大仙区| 巫溪县| 定襄县| 始兴县| 东乌珠穆沁旗| 宾阳县| 洛宁县| 开远市| 金乡县|