GLSL depth of field with bokeh v2.4 (update)

I’m an artist working on 0 A.D. (an open-source real-time strategy set in ancient times). Would it be okay for us to use your shader in the game? Here’s what it looks like with the shader:


Also, any idea what’s the lines on the edges of the fully-focused area? (I’m using manual focus, not focal length, if it matters)

leonnn
change the:
float gain = 2.0; //highlight gain;
to 0.0

Zaggy:

sure, use it for your game.
About the line, hmm I don’t know actually. It looks like there is a problem with values or something. The transition from focused to unfocused area seems to be too hard.
try increasing:
float ndofdist = 2.0; //near dof falloff distance
float fdofdist = 3.0; //far dof falloff distance

this will make the transition smoother

I’ve got both of those values at 10 (I fiddled with all the values a lot). But I did figure something out to remove the lines (though it may not be the ideal solution). If I remove the “if(blur < 0.1)” bit, then it looks fine (though the fully focused area isn’t completely focused anymore).

Could someone tell me how I would go about adding a delay to the change in focus? When using AutoFocus for example, the change in focus is instant, I would like to give the camera a moment to adjust. :confused:

EDIT: The technique that let you adjust the focus with the left mouse button already had “slowfocus”, I will use that :slight_smile:

@ martin.hedin: At the Moment I am not aware of how martinsh has gone about making his Focus work, but you can make you own D.o.F. or change this one so the Focus is set to an Object A that follows another Object B – while Object B immediately put to the Hit-Position of a Ray casted from the Camera into it’s Direction, Object A would be SLOW-PARENTED to that other Object. Now if the Focus changes with the Position of the slow-parented Object, then the Adaption will happen slow and smoothly, maybe realistically too.

EDIT: I guess there is a Way to to this with a mathematical Function instead, but that would sound trickier to me.

The code to set and get focus, already had what I was looking for, under #slow focusing:

def setFocus():  
    Ray = cont.sensors["Ray"]

    pos_vec = Vector(Ray.hitPosition)
    normal_vec = Vector(Ray.hitNormal)

    POP_OUT = 0.01

    focus.alignAxisToVect(-normal_vec.xyz, 2, 1)
    normal_vec.magnitude = POP_OUT

    focus.worldPosition = pos_vec + normal_vec

def getFocus():
    slowfocus = 0.94
    
    if not 'oldx' in own:
        own['oldx'] = 1.0
    if not 'oldy' in own:
        own['oldy'] = 1.0
    if not 'oldz' in own:
        own['oldz'] = 1.0

    #slow focusing
    own['oldx'] = (own['oldx']*slowfocus + focus.worldPosition[0]*(1-slowfocus))
    own['oldy'] = (own['oldy']*slowfocus + focus.worldPosition[1]*(1-slowfocus))
    own['oldz'] = (own['oldz']*slowfocus + focus.worldPosition[2]*(1-slowfocus))

    vecTo = Vector((own['oldx'],own['oldy'],own['oldz'])) - camera.worldPosition

    #z = camera.getDistanceTo(focus)
    z = vecTo.project(camera.getAxisVect((0.0, 0.0, 1.0))).magnitude
    own['focalDepth'] = z

I just changed the setFocus in the game logic to Always with a pulse so it would not refocus constantly, instead of using the left mouse button, and I removed the vertices from the red ball so it does not show. Easy. :eyebrowlift:

Woow, I’ve been looking through all the amazing shaders of martinsh and i have a very important question, How can I use/install all this, is amazing, lens flare, aereal lights DoF, Atmospheric stuff, just awesome. but how to use it? (sorry for such a noobish question I’m kind of new in BGE)

Using this 2dfilter really makes my GPU running hot, but it also happens with other filters. Martinsh’s DLAA filter is running much cooler for example. Is this a general problem with the blender 2dfilter system, or is this DOF code GPU intensive? Could something be changed in this code to make it run cooler?

I think you should start a new thread for this question, to keep this thread about the DOF filter, but I would say:

  1. Download the blend files and look them through, take a look in the Logic Editor and see what scripts are assigned to camera and meshes etc. And also take a look in the Text Editor and look at the python code.

  2. Or try using the example blends as a start and import your geometry, that is good way to start and test things.

Man, those screenshots look absolutely gorgeous! That’s such an impressive look that would actually let you create something very impressive looking while only using a relatively tiny amount of geometry and textures…

How do I set this up? I’ve done everything you have in the .blend and it’s still not working in my scene!

Amazing work. :yes:
Im very interrested in the fringe/color offset part. the look is just what i’ve been looking for. Is there a script just for that, wich i can use in real-time?

go back to post #1 or martinsh’ dev blog

if i recall, you need a particular version of Blender

ws

strange, this not works me unless when I change “key press 1” to “always”…