-接上篇-修改逐顶点的漫反射高光为逐像素类型
首先:法线与顶点在世界空间下的矩阵与位置保留在顶点中计算
其次:环境光+漫反射+高光光照计算移动到frag片元函数中

Shader "Davia/08_Specular Fragment"{
Properties{
_DiffuseColor("Diffuse Color",color) = (1,1,1,1)
_SpecularColor("Specular Color",color) = (1,1,1,1)
_SpecularPow("Specular Pow",Range(1,20)) = 1.0
}
SubShader
{
Pass
{
Tags{"Lightmode" = "ForwardBase"}
CGPROGRAM
#include"Lighting.cginc"
#pragma vertex vert
#pragma fragment frag
fixed4 _DiffuseColor;
fixed4 _SpecularColor;
fixed _SpecularPow;
//application to vertex
struct a2v{
float4 vertex:POSITION;
fixed3 normal:NORMAL;
};
//vertex to fragment
struct v2f{
float4 position:SV_POSITION;
float3 worldnormal:TEXCOORD0;
float3 worldvertex:TEXCOORD1;
};
//将计算过程放在顶点中:逐顶点光照
v2f vert(a2v v) {
v2f f;
//

这篇博客详细介绍了如何在Unity中将逐顶点的漫反射高光转换为逐像素光照,重点讲解了BlinnPhong光照模型的实现过程,包括法线和顶点位置的计算,以及环境光、漫反射和高光的片段函数计算。文章还对比了Phong和BlinnPhong光照模型的区别,并提供了Unity内置Lighting.cginc文件的相关信息。
最低0.47元/天 解锁文章
1269

被折叠的 条评论
为什么被折叠?



