1、在片元着色器处理漫反射
// Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject'Shader "Custom/specularfragement"
{properties{_sp("Specular",color) = (1,1,1,1)_shiness("Shiness",range(1,64)) = 8}SubShader{pass {tags{"LightMode" = "ForwardBase"}//光照模型CGPROGRAM#pragma vertex vert#pragma fragment frag#include "unitycg.cginc"#include "lighting.cginc"float4 _sp;fixed _shiness;struct v2f{float4 pos:POSITION;float3 normal:NORMAL;float4 vertex:COLOR;};v2f vert(appdata_base v) {v2f o;o.pos = UnityObjectToClipPos(v.vertex);o.normal = v.normal;o.vertex = v.vertex;return o;}fixed4 frag(v2f IN) :COLOR{float3 N = UnityObjectToWorldNormal(IN.normal);float3 L = normalize(WorldSpaceLightDir(IN.vertex));//加入环境光fixed4 col = UNITY_LIGHTMODEL_AMBIENT;//Diffuse Colorfloat diffuseScale = saturate(dot(N, L));col += diffuseScale * _LightColor0;return col;}ENDCG}}
}
在片元处理的漫反射相较于顶点中处理的漫反射在明暗交接处更加清晰