一些必需的声明
- 需要声明LightMode
- 定义宏#pragma multi_compile_fwdbase
- 包含库函数"AutoLight.cginc"
- 需要ShadowCaster,写Fallback "Diffuse"可以自动补全
- 阴影一般作用于漫反射 (直接漫反射和简介漫反射)
-
half diff_term = min(shadow,max(0.0,dot(normal_dir, light_dir)));
half3 diffuse_color = diff_term * _LightColor0.xyz * base_color.xyz;
踩坑点
struct v2f
{
float4 pos : SV_POSITION; //必须写成pos,不然会报错
SHADOW_COORDS(2)
};
v2f结构体的顶点坐标需要写成pos,写成vertex或者其他名字会报错
只计算阴影(DirectLight)
Tags{"LightMode"="Forwardbase"}
#pragma multi_compile_fwdbase
#include "AutoLight.cginc"
// in v2f struct;
SHADOW_COORDS(2)
// in vert sahder
TRANSFER_SHADOW(o);
//in frag shader;
half shadow = SHADOW_ATTENUATION(i);
Fallback "Diffuse"
?计算阴影和灯光衰减(pointLight)
Tags{"LightMode"="Forwardbase"}
#pragma multi_compile_fwdbase
#include "AutoLight.cginc"
// in v2f struct;
LIGHTING_COORDS(3,4)
// in vert sahder
TRANSFER_VERTEX_TO_FRAGMENT(o);
//in frag shader;
half atten = LIGHT_ATTENUATION(i); //
Fallback "Diffuse"
|