光源类型
光源分为:平行光,点光源,聚光灯,面光源
光源属性有五个:位置,方向,颜色,强度,衰减
前向渲染中,Base部分计算环境光和自法光,Base只会处理一个逐像素的平行光,如果有多个平行光,其他的按逐顶点处理或者在Additional中按逐像素处理。
Shader "Unity Shaders Book/Chapter 9/Forward Rendering" {
Properties {
_Diffuse ("Diffuse", Color) = (1, 1, 1, 1)
_Specular ("Specular", Color) = (1, 1, 1, 1)
_Gloss ("Gloss", Range(8.0, 256)) = 20
}
SubShader {
Tags {
"RenderType"="Opaque" }
Pass {
// Pass for ambient light & first pixel light (directional light)
Tags {
"LightMode"="ForwardBase" }
CGPROGRAM
// Apparently need to add this declaration
#pragma multi_compile_fwdbase
#pragma vertex vert
#pragma fragment frag
#include "Lighting.cginc"
fixed4 _Diffuse;
fixed4 _Specular;
float _Gloss;
struct a2v {
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct v2f {
float4 pos : SV_POSITION;
float3 worldNormal : TEXCOORD0;
float3 worldPos : TEXCOORD1;
};
v2f vert(a2v v) {
v2f o