Spherical Harmonic Lighting - GI

本文深入探讨了球谐光照(Spherical Harmonic Lighting)技术在全局光照(Global Illumination)中的应用,这是一种压缩方法,用于处理球面上的低频数据,如样本点光照数据。通过将六面纹理映射到球体上构建样本点,并使用统计方法计算平均权重值来生成SH系数,进而实现更真实的光照效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

sh_screen_shot

This sample shows how to apply Spherical Harmonic diffuse lighting as Global Illusion (GI). GI could give some more realistic effect to improve the global lighting effect than the traditional ambient lighting that will break whole the scene color contrast. If you check some more advanced rendering engine, you will find that the artist will always use shaders to implement more cool effect instead of following the old way of direct lighting methods. For example, some one could like to use a sky light sphere to lit the objects considering the vertex normal. 

Spherical Harmonic is a compress method, that could be used to compress some low short wave data among a sphere. Here, SH was used to compress the sample point lighting data over a sphere. I used a cube (6 textures) map mapping to sphere to build those sample points. The result of the SH compressing process is a group of coefficients. (the number of the coefficients based on the order that you choose)

 

Build SH coefficients

The SH data compress process is the process to find the SH coefficients. There are two ways to achieve that : 1) Calculate the value by integral mathematical function; 2) use statistical method – calculate the sum average weight value with a lots of random sampling data, that just Gore Integral does.

c_i c

As you see from the above function, the left one is the mathematical integral version one, and the right one is the sum average weight value calculation one. N means the number of the sample point, and “4PI” means the area over a unit sphere (also the possibility that this point will be sampled, equal the inverse of the area). Maybe you have already know that all the sample point have the same weight, but of course you could increase some special sample weight to make them become more contribute to the whole sampling. For more details about the concept, you could refer to spherical-harmonic-lighting.pdf.

 

Average sum weight calculation

Just take 3 sample as an example, the sample will like this (sample_value, weight) :

(V_0, W_0), (V_1, W_1), (V_2, W_2). And the Average sum weight will be calculated like this:
Result = ( V_0 * W_0 + V_1 * W_1 + V_2 * W_2 ) / (W_0 + W_1 + W_2)

 

Restore the RGB from SH coefficients

Restore the RGB from the SH coefficients given by a normal is very easy, the code is as following:

const Colour sharm[9];
Colour LightNormal ( Vector &dirn )
{
    Colour colour = sharm[0];
    colour += sharm[1] * dirn.x;
    colour += sharm[2] * dirn.y;
    colour += sharm[3] * dirn.z;
    colour += sharm[4] * (dirn.x * dirn.z);
    colour += sharm[5] * (dirn.z * dirn.y);
    colour += sharm[6] * (dirn.y * dirn.x);
    colour += sharm[7] * (3.0f * dirn.z * dirn.z - 1.0f);
    colour += sharm[8] * (dirn.x * dirn.x - dirn.y * dirn.y);
    return colour;
}

As you see, the above could be achieved with shader, that will work with the normal mapping. 

The full source code could found here.

转载于:https://www.cnblogs.com/open-coder/archive/2012/09/03/2669772.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值