博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Unity3D Shader 半兰伯特光照模型
阅读量:4684 次
发布时间:2019-06-09

本文共 2043 字,大约阅读时间需要 6 分钟。

//效果预览

 

 

//Shader代码

Shader "Unlit/HalfLambert"{    Properties    {        _MainTex ("Texture", 2D) = "white" {}        _Diffuse ("Diffuse Color", Color) = (0,0,0,0)    }    SubShader    {        Tags { "RenderType"="Opaque" }        LOD 100        Pass        {            CGPROGRAM            #pragma vertex vert            #pragma fragment frag            // make fog work            #pragma multi_compile_fog                        #include "UnityCG.cginc"            #include "Lighting.cginc"            struct a2v              {                  float4 vertex : POSITION;                  float3 normal : NORMAL;                  float4 texcoord : TEXCOORD0;              };              struct v2f            {                float2 uv : TEXCOORD0;                UNITY_FOG_COORDS(1)                float4 vertex : SV_POSITION;                fixed3 worldNormal:TEXCOORD1;            };            sampler2D _MainTex;            float4 _MainTex_ST;            fixed4 _Diffuse;                        v2f vert (a2v v)            {                v2f o;                o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);                o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);                o.worldNormal = mul((float3x3)unity_ObjectToWorld,v.normal);                UNITY_TRANSFER_FOG(o,o.vertex);                return o;            }                        fixed4 frag (v2f i) : SV_Target            {                fixed3 worldLightDir = normalize(_WorldSpaceLightPos0.xyz);                fixed3 worldNormal = normalize(i.worldNormal);                fixed3 halLambert = 0.5+0.5*dot(worldLightDir,worldNormal);                fixed3 dif = (UNITY_LIGHTMODEL_AMBIENT+halLambert*_LightColor0)*_Diffuse;                // sample the texture                fixed4 col = tex2D(_MainTex, i.uv);                // apply fog                UNITY_APPLY_FOG(i.fogCoord, col);                return fixed4(dif * col.rgb, col.a);                 return col;            }            ENDCG        }    }}

 

转载于:https://www.cnblogs.com/mrblue/p/7733027.html

你可能感兴趣的文章
c#Socket通信
查看>>
第七周翻译
查看>>
HTTPS协议的实现原理
查看>>
MvvmLight的Message使用
查看>>
0404 构建之法第四章理解
查看>>
Hunters
查看>>
2018二月实现计划成果及其三月规划
查看>>
封装springmvc处理ajax请求结果
查看>>
jQuery+ localStorage 实现一个简易的计时器
查看>>
tyvj P2018 「Nescafé26」小猫爬山 解题报告
查看>>
类名.class和getClass()区别
查看>>
开发脚本自动部署及监控
查看>>
JavaScript--语句
查看>>
抽象数据类型(ADT)和面向对象编程(OOP)3.2规约
查看>>
(五)数据库服务学习入门
查看>>
12/17面试题
查看>>
css 继承和层叠
查看>>
【转载】正则表达式全部符号解释
查看>>
javascript实现图片轮播3D效果
查看>>
ssl初一组周六模拟赛【2018.3.17】
查看>>