【Realtime Rendering 6】
1、Lighting computations occur in two phases:
1)light phase.
used to compute the light’s direction vector l and irradiance contribution E^L.
2)material phaes.
In the material phase, the BRDF parameters and surface normal.
The result of the BRDF evaluation is multiplied by a cosine factor and by to produce the outgoing radiance EL.
Both phases are repeated for each light source and the results are summed to produce the total outgoing radiance for the fragment.
每个 surface对每个 light source 依次执行上面两个 phase,所有 light source 的计算结果结果最终汇总到一起。
2、 每一个material需要配合各种 light source组合,导致shader非常多。
Valve抯 Half-Life 2 has 1920 pixel shader combinations.
Light Type 组合会导致Shader爆炸。
3、让每个material处理所有的 light 会导致效率非常低。
A long hallway, which is lit by twenty spaced light sources. if dynamic branches are not employed, then all twenty light sources need to be computed for every pixel.
loop优化方式是:
loop over light sources dynamically in the pixel shader. Unfortunately, dynamic branches in the pixel shader perform poorly on many GPUs.
ubershader、supershader 优化方式:
write a single large shader that is compiled multiple times, using language features or code preprocessors to create a different specialized version of the shader each time.
只写一个通用Shader,通过mactro为每一种 light source组合生成相应shader。
4、一种常用策略。
5、Multipass Lighting.
The idea is to process every light in a separate rendering pass. using the hardware's additive blending capabilities to sum the results in the frame buffe
每个shader的每个 pass 渲染一种 light source type。从而shader与light source type 组合数解耦。
此法可以解决Shader爆炸的问题。
但是此种渲染效率并不高。 This is an O(mn) process.
6、Deferred Shading.
to perform all visibility testing before performing any lighting computations. If the fragment is completely covered by some later fragment, all the time spent computing its shade is wasted.
用于优化因深度问题而导致的无效渲染的问题。
A rough front-to-back sort of objects can help minimize this problem, but deferred shading completely resolves it.
从前向后渲染中以缓解无用渲染问题,但延迟渲染可以完全解决它。
Be done with a Z-buffer by performing a rendering pass that stores away the attributes of the closest visible surface. Values saved include the z-depth, normal, texture coordinates, and material parameters.
These values are saved to multiple render targets accessed by the pixel shader program. The stored buffers are commonly called G-buffers,short for “geometric buffers
第一个Pass渲染所有信息到 G-Buffer,包括 z-depth,normal,texture coordinate, material parameter。第一个pass从G-buffer中读取数据,进行渲染。
Fragment shading is done only once per pixel (per shading program) and so has a predictable upper bound on rendering cost. Geometric transformation is done only once, in the initial pass, and any computations needed for lighting are done only once.
Fifty or more dynamic lights in a scene can easily be handled by deferred shading;
延迟渲染中以轻松处理50个以上的灯光。
7、Early Z pass。
分两步:
1)performing an initial pass and establishing the Z-buffer.
2)scene is rendered normally with full shading.
8、Deferred Shading Zioma变种。
local light sources are rendered to and stored in buffer. Depth peeling can be used to handle storing the information for overlapping light sources. The scene’s geometry is then rendered, using these stored light representations during shading.
此法有两个好处:
1)surface materials are not limited by what is stored in the G-buffer
2)storing light source descriptions can take considerably less space than storing a full material description.