6.Half Lambert光照Diffuse Shader
来源:互联网 发布:猫王收音机 知乎 编辑:程序博客网 时间:2024/06/05 05:57
简单来说,Lambert定律认为,在平面某点漫反射光的光强与该反射点的法向量和入射光角度的余弦值成正比(即我们之前使用dot函数得到的结果)。Half Lambert最初是由Valve(游戏半条命2使用的引擎即是其开发的)提出来,用于提高物体在一些光线无法照射到的区域的亮度的。简单说来,它提高了漫反射光照的亮度,使得漫反射光线可以看起来照射到一个物体的各个表面。而Half Lambert最初也是被用于游戏半条命的画面渲染,为了防止某个物体的背光面丢失形状并且显得太过平面化。这个技术是完全没有基于任何物理原理的,而仅仅是一种感性的视觉增强
相比之前的Lambert光照shader,只是多加了一行代码
float hLambert = difLight * 0.5 + 0.5;
由代码可以看出,我们定义了一个新的变量hLambert来替换difLight用于计算某点的颜色值。difLight的范围是0.0 - 1.0,而通过hLambert,我们将结果由0.0 - 1.0映射到了0.5 - 1.0,从而达到了增加亮度的目的。下图显示了这一变化:
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"}
0 0
- 6.Half Lambert光照Diffuse Shader
- 5.Lambert光照Diffuse Shader
- Half Lambert光照模型
- Unity shader教程-第五课:自定义光照模型之Half Lambert模型
- shader学习之路(1)- half lambert
- 3.Unity_CG_Shader光照之——漫反射(lambert模型以及Half lambert模型)
- lambert光照
- 一步步学shader系列(2):环境光照diffuse漫反射光照
- Unity Shader-兰伯特光照模型与Diffuse Shader
- Unity Shader-兰伯特光照模型与Diffuse Shader
- 【猫猫的Unity Shader之旅】之Lambert光照
- Shader基于顶点编程的Lambert光照,Phong光照和Blinn-Phong光照
- Shader基于片段编程的Lambert光照,Phong光照和Blinn-Phong光照
- Unity3D 开发之shader教程(浅谈光照之漫反射diffuse)
- Unity Shaders and Effects Cookbook (1-3) 创建 Half Lambert 光照模型
- 【Unity Shaders】学习笔记之为创建Half Lambert光照模型(六)
- Shader学习笔记(三)自定义光照模型,经典光照模型Lambert与HalfLambert
- Unity使用Shader控制物体材质的透明度(Lambert版和非光照版)
- C语言版大数相加
- 优化系列 | DELETE子查询改写优化
- springmvc mybatis集成
- 《设计模式》之Creational模式:简介
- SVN里恢复到某一天的版本操作
- 6.Half Lambert光照Diffuse Shader
- gradle project sync failed.Basic functionality(e.g.editing,debugging) will not work
- [51nod1239]欧拉函数之和
- HIVE的ACID特性
- Android WiFi STA Framework层分析(基于KitKat4.4.4)
- [Python] 使用python的随机验证码。
- 从git中导出项目
- UVA 10934 Dropping water balloons
- EditText实现搜索框常见需求详解(配合软键盘的应用和模拟搜索List结果集)