레이블이 UE4인 게시물을 표시합니다. 모든 게시물 표시
레이블이 UE4인 게시물을 표시합니다. 모든 게시물 표시

2016년 3월 27일 일요일

Incorrect naming in UE4 skylight source code.

Recently, I am reading UE4 skylight code. and found that they call projected SH coefficients as "IrradianceEnvironmentMap".

Actually, this naming is wrong.
They make this Irradiance SH Function by producting cosine lobe in the end. But until then it is projected "Radiance SH" not "Irradiance SH".

Let's recall basic rendering process using spherical harmonics.

1. Project SH coefficients from radiance cube map.
2. Convert Radiance SH to Irradiance SH by dot product with cosine lobe
(Ravi Ramamoorthi's paper)
3. Evaluate Irradiance env map with normal vector

Let's see two different shader code for SH shading.

Below code is hlsl from MJP in gamedev.net
This is easy to understand.
There is radiance SH, cosine lobe.



And below is code from Peter-Pike Sloan
This code seems to be just a sh evaluation code.
The secret is coefficient for cosine lobe is already producted to radiance SH(and it becomes Irradiance finally!)


Later code may be a lot faster(because use fewer shader instructions).

UE4 call value after 1 as IrradianceEnvironmentMap(it becomes irradiance in the end, but not at first).

Although final rendering is OK, But Incorrect naming confuse stupid reader like me.


2016년 1월 25일 월요일

UE4 Rendering thread problem related to Editor

UE4 has multi-thread rendering architecture which is similar to UE3(almost same..).
Game thread datas(PrimitiveComponent..) and Rendering thread datas(SceneProxy..) are main components of it.

Game thread enqueue asynchronous rendering command continously to rendering thread. Applying changed property in game thread to rendering thread is one of them.

Usually there is no bad thing here. Until Editor and UpdateRendertargetCapture are used together.

case :
1. Component property is changed by editor click.(from Window Msg Pump)
2. There is 2dSceneCaptureActor in the scene.
3. GarbageCollection is performed.

problem :
1. some object could be garbage collected.
2. Scene could be rendered before change of property is applied to render thread.
3. Garbaged collected object could be referenced in rendering thread.

I resolved this sitation by FlushRenderingCommand. But still, We could say this is flaw of UE4 multi-threading or update capture architecture.