2016년 8월 4일 목요일

My strange global illumination solution.

Global illumination is spationaly/directinaly low frequency signal.
Lightmap is sptaionaly high frequency but cannot store high frequency directional data due to memory issue.
Specular IBL is also important part of Global illumination. most game engine uses pre-filtered cubemap for specular GI. This has high frequency directional data, but spatial frequency is very low(1 ~ 300 cubemap in the level in UE4).

So I thought that if specular IBL is low spatial freqency data, what if we use high frequency diffuse GI and forgive high frequency spatial diffuse GI?

Below are result of that thought. There is only 1 probe which can be updated in realtime(no lightmap) and hbao+.


Diffuse indirect lighting might be incorrect spatially. but matches with specular IBL.
and with very low memory(no lightmap) and can be easily interpolated(time of day).

probe can be interpolated using volume texture(3d clipmap in large world), or blended in tiled culling using compute shader. I tried both and chose tiled culling with CS.

2016년 4월 15일 금요일

Fourier Opacity Map volumetric shadow.

I implemented volumetric shadow of particle system in UE3.
There were several options for this effect. The most feasible 3 were like below.

1. per pixel deep shadow map(need CS, UE3 didnt have CS back then)
2. FOM
3. Simple thickness map

I tried #2 first. the result was quite good with some resource. But finally I chose simple thickness map technique because of the severe ringing effect of some particles with high opacity! ringing effect is seen in spherical harmonics too. because frouier and SH use wave like basis functions.

Today, I found that UE4 is using FOM for volumetric self shadow. and document is warning about ringing effect.

why did they choose FOM? maybe they must have found solution for ringing effect.
I will look into source code later.

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.

2016년 1월 8일 금요일

Improving outline postprocess using stencil operation.

There is excellent tutorial for Outline postprocess.

http://www.tomlooman.com/ue4-outline-post-process/

His technique support pretty outline using custom depth(simliar technique is already being used by editor selected object), and also provide nice multi color feature too.

But what if your game designer want to specify occluders who cause occludee outlined?

Here is my solution.

1. occludee writes team color ID to stencil.
2. occluder increment stencil by 1(to do this, we need to slightly modify custom depth path, PrimitiveComponent has occluder/occludee flag and it is rendered seperately in custom depth path)
3. In PostProcess, only increment stencil pixel is considered as "outlined"

This is very useful when there are too much outline in screen, and we want to use only needed.


Got full time graphics programmer job.

Recently, I came back to game industry. and am now full time graphics programmer.
People might say that why would we need graphics programmer if we use engine like UE4. but even UE4 doesn't have all the features we want. so there are tons of things to be touched by graphics programmer.

Fortunately, UE4 is a lot easier than UE4 to modify or extend.

Here is what I am doing now.

1. understand inside of renderer, and guide artist team to use engine correctly(ex: PBR input)
2. adding missing features(ex : lighting channel in UE3 or Hair rendering and etc..)
3. make tools for faster artistic iteration and faster tweak.

I am thinking if there are more things to be done. and these are very interesing so far.

I will post some tips later.