Saturday, 29 March 2014

Depth

Depth of Field

Depth of field is defined as the space in which we can see objects clearly; objects outside this depth appear blurry to our eyes, whether they are closer or further. Depth of field is fundamental to have for photo-realistic rendering.



To do depth of field you need to have alpha information to work with. To do depth of field you need to have alpha information to work with.

The first step is to pre-blur the image through downsizing. After this you use a kernel as well as the depth information to approximate where your circle of confusion is. After this you blend between the original and pre blurred image in this region.

This means that we need the blurriness as well as the depth of each pixel. To get this we pass three different types of information from the camera to the shader: the Focal Plane, the Near Plane and the Far Plane. The camera stores depth information between -1 and 1. To blur we need an absolute value instead of this relative value; to get this we merely half the value and add 0.5. This allows us to pass through blurriness and depth through the same channel. Even though we are doing this we can still do alpha blending in two passes. First you render the rgb with blending enabled for the first pass, after that you use the output of the your computation of depth blur to render to your destination.

Then now you blur you back image. You then blur blend between the original image and the blurred image based on the depth to find how blurry the image is supposed to be.


Most blurring techniques cause leaking of sharp objects into the background. To fix this we use the depth buffer to compare samples and remove ones that contribute to this “leaking”.

Portals

Lately I have been working on a portal system, trying to replicate the one in portal. There are three cameras in total, the main view camera and a camera attached to each portal.

There is a three pass system. For the first pass I start off by drawing the scene. I then create a texture out of the FBO from the first portals view.

The second pass is much like the same but bound the texture from the first pass to the second portals mesh before drawing the scene. Then I create a FBO texture from the second portals view.

During my third pass I have both of the textures bound the opposite portals, the first portals view is bound to the second and the seconds view to the first. I then render my scene to an FBO.

The fourth pass is to create a full screen quad and put the view FBO on top so that it can be post processed.
For the future I plane to add in the glow and ripple effects in. Both of these would create two more passes for the program.

For glow I plan to make two different border textures which I will blend between in order to get the glow to move. Then I will overlay this created texture on top of the texture created for the portals. This will require me to send in two additional textures and the a time variable that is between 0-1 to use for blending.
For my ripple effect I plan to do something similar with normal maps.

Teleportation is set up as a basic box collision check that is checked on both portals. Going through the portals is set up as teleportation for now as I am unsure how to do the gradual teleportation.
While this is not done yet I plan to work on it while I do other things and will post about my progress in the future.

Game Jam


A few weeks ago I took part in a game jam again. The theme of the game jam was interference and interactivity. There I had the chance to work with the Leap Motion. I worked with two others to create the game Ballin’. The basis of the game is to escort a marble through a maze and around pitfalls while not being able to see all but you near surroundings. The catch is that the maze is controlled by the Leap Motion. To play you would hover your hand over the Leap Motion and the board would mimic the movements of your hand. While it is not yet finished, we have actually acquired a Leap Motion of our own and plan to make and perhaps release the game on our own time. 

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: