【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.
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、一种常用策略。
原文地址:https://www.cnblogs.com/tekkaman/p/9190234.html