Light Pre-pass Render

简介

Light Pre-pass 渲染器 [0] 是延迟渲染的一种修改版。 渲染步骤大致如下:

此方法的优点有:

光照方程

常用的就是Phong [1] 与Blinn-Phong [2] 了,先复习一下其原理:

phong

Name Detail Name Detail
N 平面法线 L 光的方向
V 视角方向 R L对N镜像
H L + V    

Phong模型

phong model

Name Detail Name Detail
K Color Att Attenuation
a Ambient s Specular
d diffuse n shininess
IT Intensity l Light

L对N的镜像R的计算:

reflect

Blinn-Phong模型

blinn phong model

渲染器设计

属于灯光的参数:

light
{
	color, 
	shininess/power
}

属于材质的参数:

material 
{
	specular_color, 
	specular_intensity, 

	diffuse_color, 
	diffuse_intensity,

	shininess/power
}

我们需要重建的光照方程,使用Blinn-Phong光照模型:

color = ambient + shadow * attenuation * (
	mat_diff * diff_intensity * light_color * N * L + 
	mat_spec * spec_intensity * ((N * H)^n)^m
)
Name Detail Name Detail
attenuation 控制灯光的衰减 intensity 控制光照的强度
n 灯光的亮度 m 材质的亮度

光照方程中,与灯光相关参数:

我们将其存储到Light Buffer中,用于后续渲染中对光照方程的重建:

light_buffer.rgb = light_color.rgb * N * L * attenuation
light_buffer.a = (N * H)^n * N * L * attenuation
N * L * attenuation

若需要重建高光反射分量,则共需要两个Render Target。

在这里,我们可以转换 N * L * attenuation 到 luminance [3],这两个值非常接近:

luminance = N * L * attenuation 
	= (0.2126 * R + 0.7152 * G + 0.0722 * B)

这样我们就可以重建高光反射分量,并且仅需要一个Render Target:

(N * H)^n = light_buffer.a / luminance
	= ((N * H)^n * N * L * attenuation) / (N * L * attenuation);

附录

[0] Wolfgang Engel. Light Pre-Pass Renderer. Diary of a Graphics Programmer.

[1] Wikipedia. Phong Reflection Model.

[2] Wikipedia. Blinn Phong Shading Model.

[3] Wolfgang Engel. Light Pre-Pass More Blood. Diary of a Graphics Programmer.