2017년 10월 19일 목요일

Understanding diffuse transfer function.

Diffuse transfer function

In PRT, transfer function includes much information(visibilityintereflected lighting) and projected to sh coefficients in offline using monte carlo integration. But many game engine uses sh lighting without these pre-computed transfer function. For example, characters usually don’t contain visibility data for each vertex or texture. So we have to do lighting with only surface normal and lighting function. Because we don’t have pre-computed transfer function, Lambert(clamped cosine) function like below image will be used. 

Maybe you might have wondered how this Lambert transfer function could be generated in runtime. Ok, Cosine function could be projected to sh coefficients using monte carlo integration. But transfer function should be different for specific surface normal. How could this transfer function be rotated along surface normal vector? The famous R.Ramanmoorthi’s IrradianceEnvironmentMap paper lacks detail explanation for this process.

Irradiance Convolution

The convenient Irradiance convolution is like this.
Llm is lighting function,
L(θ,ϕ)=l,mLlmYlm(θ,ϕ)
Tlm is transfer function,
T(θ,ϕ)=l,mTlmYlm(θ,ϕ)
Then irradiance E is,E=l,mLlmTlm

Analytic diffuse transfer function

In this paper, You can learn how cosine function is projected to sh coefficients analytically. Note that this function is in local coordinate.A(θi)=cosθi=n=0AnYn,0(θi)
An=2π0π2Yn,0(θi)cosθisinθidθi
An=2π(2n+14π)01Pn(u)P1(u)du
-11Pa(u)Pb(u)=22a+1δa,b
n=1:An=π3
n>1,odd:An=0
n=even:2π2n+14π-1n/2-1(n+2)(n-1)×[n!2n(n!/2)2]

Local? World? coordinate

The analytic cosine function above is in local coordinate. It means that you can use it with surfaces whose normal vector is z axis. So you have to rotate this along surface normal vector.

Rotation of clamped cosine function(Zonal harmonics rotation)

When (θ,ϕ) is direction to which we want to rotate,
Arlm is rotated cosine function along (θ,ϕ),
Aolm is original cosine function along z axis,
Arlm=4π2l+1AolmYlm(θ,ϕ)
When n is 1, A1=π3 and 4π2l+1=2π3Ar1=2π3 and other coefficients match as well.
So in conclusion you just need to use this Arn coefficients to rotate diffuse transfer function. And you can use this resulting coefficient to do dot product with lighting coefficients as R.Ramanmoorthi’s IrradianceEnvironmentMap paper says.

Other BRDF

Most game engine uses same diffuse transfer function like above even the diffuse BRDF of surface is not Lambert, therefore indirect lighting for BRDF other than lambert is not realistic. But with knowledge like this we could do better. The Order 1886 generated skin diffuse transfer function which is projected by monte carlo integration and used it as skin diffuse lighting. If we have other isotropic diffuse BRDF function we could do exactly same thing like this.

댓글 없음:

댓글 쓰기