Wednesday, December 18, 2013

SSGI in Unity

A simple SSGI (Screen Space Global Illumation) effect was a surprisingly quick feature to add, as most of the legwork had already been done by Unity's SSAO (Screen Space Ambient Occlusion) Image Effect.

The aim was to add additional contextual information to the final render, by way of indirect bounce light (or more accurately - color bleeding) from nearby surfaces.

SSGI is OFF, SSAO is OFF.
We lack substantial spatial cues.


The process I used is identical to SSAO, only instead of merely measuring contributions to the occlusion term, I allowed the occluding surfaces to contribute local surface color as well.

Altering the SSAO shader, I stuffed the AO term into the _SSGI tex's .a channel, and the GI term into the .rgb channels, then blended the color bleeding signal with the original image, using a remapped ao signal.

sampler2D _SSGI;

half4 frag( v2f i ) : COLOR
{
half4 c = tex2D (_MainTex, i.uv[0]);
half ao = tex2D (_SSGI, i.uv[1]).a;
ao = pow (ao, _Params.w);
half3 gi = tex2D (_SSGI, i.uv[1]).rgb;
c.rgb = lerp(c.rgb, gi, 1-ao);
return c;
}

What's nice about this hack is all the parameters for AO are separable and compatible with those for GI.

SSGI is ON, SSAO is ON.
Indirect illumination and occlusion provide greater spatial context.

No comments: