鸟语天空
创建CgInclude文件来存储光照模型
post by:追风剑情 2016-3-5 19:52

一、创建MyCgInclude.cginc文件

#ifndef MY_CG_INCLUDE
#define MY_CG_INCLUDE

fixed4 _MyColor;

//半兰伯特光照模型
inline fixed4 LightingHalfLambert (SurfaceOutput s, fixed3 lightDir, fixed atten)
{
	fixed diff = max (0, dot(s.Normal, lightDir));
	diff = (diff + 0.5)*0.5;
	fixed4 c;
	c.rgb = s.Albedo*_LightColor0.rgb*((diff*_MyColor.rgb)*atten*2);
	c.a = s.Alpha;
	return c;
}

#endif

二、使用MyCgInclude.cginc文件

Shader "Custom/HalfLambertShader" {
	Properties {
		_MainTex ("Base (RGB)", 2D) = "white" {}
		_DesatValue ("Desaturate", Range(0, 1)) = 0.5
		_MyColor ("My Color", Color) = (1,1,1,1)
	}
	SubShader {
		Tags { "RenderType"="Opaque" }
		LOD 200
		
		CGPROGRAM
		#include "MyCgInclude.cginc"
		#pragma surface surf HalfLambert

		sampler2D _MainTex;

		struct Input {
			float2 uv_MainTex;
		};

		void surf (Input IN, inout SurfaceOutput o) {
			half4 c = tex2D (_MainTex, IN.uv_MainTex);
			o.Albedo = c.rgb;
			o.Alpha = c.a;
		}
		ENDCG
	} 
	FallBack "Diffuse"
}

效果

111111.png

评论:
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容