Sunday, 2 March 2014

Post Processing

Post Processing

This week I was working on post processing shaders.

HDR/Bloom

The first one I worked on was bloom. We talked about bloom at an earlier time but lets recap it. Bloom is a glow effect overlay that is put on an image in order to reproduce the view of real world cameras. It is a computer graphics technique that is used in video games, tech demos as well as animated movies. Bloom is the process of “extending” the light from the borders of “bright” areas of an image. This makes the light brighter and more of a real world effect instead of seeming unsettling.

The theory of bloom is simple, in real life a lens can never focus perfectly. Even the most expensive lenses will distort the light somewhat. Normally we do not see this, but if the light is very bright, like the sun for instance, the light will go out of its natural place and extend its reach to other portions of the image. This effect is barely noticeable when there are two bright places next to each other, but when there is a bright and a dark place next to each other we see this effect.

In HDR we can reproduce this effect by altering the image with a Gaussian blur kernel. The distortion (or bleeding) from this kernel is effected by the brightness of the light in our scene. Since this is a post processing effect, it is done after the scene is initially rendered and there are two different ways to do this. The first way is the simplest: You start by rendering the scene to a FBO. The next step is to highlight your bright areas using tone mapping and save this as a second texture. You then apply Gaussian blur to this new texture. Finally you add together your original image and the blurred image for an image with bloom. The second way to do this is to add in an extra step. Before you do the highlights on your next texture you shrink it down and stretch it out to get a pixilated version of your original image. The more you shrink then stretch the image the more distorted your bleed effect will be. The second method is how we implemented it during my class.


Black and White

Another post processing technique I did was to make my image completely greyscale. This is very simple to do using  the following code:

float relativeLuminance(in vec3 rgb)
{
       return (0.2126*rgb.r + 0.7152 * rgb.g + 0.0722*rgb.b);
}
That alone allowed for only a basic greyscale image, I wanted to add in a cell shading effect therefore I used the following to create a cartoony, greyscale image.

float celShading(in vec3 pos, in vec3 norm)
{
       vec3 N = normalize(norm);

       vec3 L = normalize(lightPos - pos);

       float Lambert = max(0.0, dot(N, L));

       Lambert = texture(qMapTex, vec2(Lambert, 0.0)).r;

       return Lambert;
}


This gives the scene a similar effect as the following:





No comments:

Post a Comment