日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

6.Half Lambert光照Diffuse Shader

發(fā)布時間:2023/12/13 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 6.Half Lambert光照Diffuse Shader 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

簡單來說,Lambert定律認(rèn)為,在平面某點漫反射光的光強與該反射點的法向量和入射光角度的余弦值成正比(即我們之前使用dot函數(shù)得到的結(jié)果)。Half Lambert最初是由Valve(游戲半條命2使用的引擎即是其開發(fā)的)提出來,用于提高物體在一些光線無法照射到的區(qū)域的亮度的。簡單說來,它提高了漫反射光照的亮度,使得漫反射光線可以看起來照射到一個物體的各個表面。而Half Lambert最初也是被用于游戲半條命的畫面渲染,為了防止某個物體的背光面丟失形狀并且顯得太過平面化。這個技術(shù)是完全沒有基于任何物理原理的,而僅僅是一種感性的視覺增強

相比之前的Lambert光照shader,只是多加了一行代碼

float hLambert = difLight * 0.5 + 0.5;

由代碼可以看出,我們定義了一個新的變量hLambert來替換difLight用于計算某點的顏色值。difLight的范圍是0.0 - 1.0,而通過hLambert,我們將結(jié)果由0.0 - 1.0映射到了0.5 - 1.0,從而達(dá)到了增加亮度的目的。下圖顯示了這一變化:

Shader "Study/6_HalfLambertDiffuse" { <span style="white-space:pre"> </span>Properties{ <span style="white-space:pre"> </span>_Color("Main Color", Color) = (1,1,1,1) <span style="white-space:pre"> </span>_MainTex("Base (RGB)", 2D) = "white" {} <span style="white-space:pre"> </span>_EmissiveColor("Emissive Color", Color) = (1,1,1,1) <span style="white-space:pre"> </span>_AmbientColor("Ambient Color", Color) = (1,1,1,1) <span style="white-space:pre"> </span>_MySliderValue("This is a Slider", Range(0,10)) = 2.5 <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>SubShader{ <span style="white-space:pre"> </span>Tags{ "RenderType" = "Opaque" } <span style="white-space:pre"> </span>LOD 200 <span style="white-space:pre"> </span>CGPROGRAM #pragma surface surf Lambert MyLambertDiffuse<span style="white-space:pre"> </span>sampler2D _MainTex; <span style="white-space:pre"> </span>fixed4 _Color; <span style="white-space:pre"> </span>//We need to declare the properties variable type inside of the ? <span style="white-space:pre"> </span>//CGPROGRAM so we can access its value from the properties block. ? <span style="white-space:pre"> </span>float4 _EmissiveColor; <span style="white-space:pre"> </span>float4 _AmbientColor; <span style="white-space:pre"> </span>float _MySliderValue;<span style="white-space:pre"> </span>struct Input <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>float2 uv_MainTex; <span style="white-space:pre"> </span>};<span style="white-space:pre"> </span>void surf(Input IN, inout SurfaceOutput o) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>//We can then use the properties values in our shader ? <span style="white-space:pre"> </span>//float4 c; <span style="white-space:pre"> </span>fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; <span style="white-space:pre"> </span>c = c * pow((_EmissiveColor + _AmbientColor), _MySliderValue); <span style="white-space:pre"> </span>o.Albedo = c.rgb; <span style="white-space:pre"> </span>o.Alpha = c.a; <span style="white-space:pre"> </span>}<span style="white-space:pre"> </span>inline float4 LightingMyLambertDiffuse(SurfaceOutput s, fixed3 lightDir, fixed atten) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>float difLight = max(0, dot(s.Normal, lightDir)); <span style="white-space:pre"> </span>float hLambert = difLight * 0.5 + 0.5; <span style="white-space:pre"> </span>float4 col; <span style="white-space:pre"> </span>col.rgb = s.Albedo * _LightColor0.rgb * (difLight * atten * 2); <span style="white-space:pre"> </span>col.a = s.Alpha; <span style="white-space:pre"> </span>return col; <span style="white-space:pre"> </span>}<span style="white-space:pre"> </span>ENDCG <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>FallBack "Diffuse" }


創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結(jié)

以上是生活随笔為你收集整理的6.Half Lambert光照Diffuse Shader的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。