Thursday, March 29, 2012

Revisiting Lens Effect / Bokeh - Details

just finished doing another test with this technique, and even test it on my old card... and it rocks, can't wait to inject it to the engine (its still a render monkey tester).
anyway, someone asked for some details about this technique, so here is the post that i hope will clear few things.

let me start with example with steps:
* we have image A
* we want new image B (blurred)
* so we apply blur filter on A and get B
the tricky part is the blur filter.

if we want to apply simple blur, lets say we take 4 samples, so we will sample four locations around our current pixel and do some average to get our new pixel, this is the basic of blurring. in this example we say the kernel/radius size is 1, because we sample at distance of one pixel from our current pixel.

if we want to control the radius and make it more then 1 pixel, we could manually change our samples locations, but a better way would be to set our samples as directions/vectors from our current pixel to the sample location we would like to sample, so we could scale it and sample at larger distance from our current pixel.

some numbers to show what i mean:
if we have an image with 3x3 pixels, and we are at pixel (1,1), our absolute samples locations will be:
(0,0), (2,0) - top
(0,2), (2,2) - bottom
but when we convert these to directions, we get:
(-1,-1), (1,-1) - top
(-1,1), (1,1) - bottom

NOTE: these directions are simply added to our current pixel location to get the right sample location.
the directions format is better since it allows as to scale them and sample at larger distance and its keeps the code more generic.
keep in mind that these directions will be good for radius 1 or 2, larger values results in artifacts dues to not enough samples around our pixel.
to use large values, you want more samples, but more samples means more gpu power, so you want to find nice balance between quality and speed.

anyway, how could we get shape like blurs? like circles, squares, pentagon etc..
the same idea we did in the simple case, we create a set of directions that creates or match the shape we want and apply it, we need to use more samples so our shape will maintain its shape.

one thing you should know is that when you sample and gather pixels almost all the time you will apply some kind of weight on them so each pixel will have its contribution (you may not want that every pixel will have the same contribution...).

here is a new video with better quality that shows this technique in action.
the test uses 2 inputs to emulate simple depth of field effect:
* first input is color image of a really nice car :)
* second is CoC image that represent the circle of confusion which in turn will change our radius when we blur (created in photoshop to apply dof on specific areas in the image)


Wednesday, March 28, 2012

Revisiting Lens Effect / Bokeh

Hi all
this time i'm revisiting lens effect called bokeh.
last week a friend of mine asked me about my film dof effect, and he asked if i'm supporting bokeh effect, i told him that i used to do it with FFT and with dx11 i can do it better.
as i don't have dx11 card (i'v old geforce 240 gt with dx10.1) i can't do the effect like crytek and unreal samaritan demo.
so is there another technique to do it without dx11? well yes...
what we can do is to create a huge vertex buffer that contain quads, one quad per pixel, and inside the vertex shader we can place and size them as needed.
this technique will work on dx9 hw and should be done on half or quarter size render target because the hugh amount of vertices it required, this technique add as new feature to unreal engine.
i don't really like the idea of having huge VB per pixel, so can we do better?
i did simple test in render monkey and create a "pentagon filter" inside the pixel shader, i control the size via simple circle of confusion value just to test and see if its working.
the filter uses 30 samples per pixel and its very fast, not that i had the chance to test the VB technique, but its faster than crytek method which is very fill rate heavy.
anyway, here is a short movie that show this simple test i did, enjoy :)


Monday, March 5, 2012

The First Scene

Hi all

finally i got to the point that i can share some info about the first scene i'v been working on.
the scene is an abandon parking place which i designed all by myself.
here are few screenshots from the scene:

the scene is far from being complete, i need to add more models, fix textures for pipes/flares etc... but i wanted to share it and not keeping it in the dark as last time...
for now i'm working on new props to fill the scene with so it won't look too clean/empty.

some rendering highlights used (for these who interested):
1. hdr
2. film tone mapping
3. film depth of field
4. gamma & color correction
5. screen space AA
6. sun shafts
7. dynamic shadows (from all lights)
8. real time GI (color & ambient occlusion)
9. light flares

i would be glad to hear what do you think...
cya until next time