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

The Shader is great.
Far Things don’t become too blurry (due to maxblur Limitation), the Noise remains still, the Debuggin’ Visualisation is very well done, and while still lookin’ pretty good it runs very smooth and fast when usin’ only one Sample.
I actually suggest for Ingame Purposes to use only one Sample because it still looks pretty good (with maxlur=1.0).

Hey, you actually gave me an idea for a new feature - allow user to specify maximum blur for near and far focal depth planes, and perhaps even specify the distance :slight_smile:
Also I am still trying to understand the falloff curve and distances of the depth of field, I do not think that is is just linear.

Great as usuall thanks again for share!

Feature Request - can you add a… lets see, how do I put it… In the auto-focus, when you change the focal point from an object 50 units away to an object 10 units away, is there a way to increase the amount of time it takes to fully focus? Make the transition smoother?

I have done much more physically accurate DoF. It uses real lens equations, taking as input “f-stop”, “aperture diameter”, “focal length” and “focal plane” values. Also features adaptive focusing requested by @The_Red_Hand.

Blend is HERE


same as before +
•Up & Down arrow keys - adjusts “focal length” value in mm (zoom in/out) (range: from 6mm to 600mm)
•Left & Right arrow keys - adjusts “f-stop” or relative aperture value (automatically changes aperture diameter in mm)
(range: f/1, f/1.4, f/2, f/2.8, f/4, f/5.6, f/8, … f/256)

Stunning work martinsh!!! Ive been a fan of your work for some time now and so far ya’ve kept to amazing quality work coming along. this may not be the best place to put this request but I was wondering is there any chance you would know if it is possible to combine and modify your dof shader and the color bleed to something that will give off a similar lighting effect that you see on lanterns and other glowing objects in games like trine 2 ( without having to redo the lighting system in blender to give it deferred lighting. also maybe it’s possible to change the color bleending part of that script so that the distance of the color bleed and glow is determined by a float value of a varible that each individual object has in its properties? could the glowing effect my accomplished by placing dof on an individual object, so no matter how near or far away the camera is from that object, the object would still be rendered as a blur.

or maybe instead of using the dof shader, the lighting scattering shader would be more useful. So the light scattering is omni projected to a distanced determined by a float property on that indivdual object. if that would work such a tool would be extremely useful for a game developer like myself.

Hello Tony, thank you!
Regarding your request - well it is not connected to depth of field at all :). But I have a working prototype of it already. I have to bring it up from my archives and get it working in Blender 2.6.
It is a part of bigger project including a full outdoors lighting and weather system which includes air turbidity along with fogging. So for each light in the scene there is also calculated a light scattering term for it. More turbid the atmosphere - more scattered the lighting around the light source. So just hang on, I will publish it soon.

Sweet nectar bro, that sounds awesome, lookin forward to learning how its done. such a feature will really improve the visual quality of many of our games in blender and your work is always amazing, i wonder if you ever considered getting your work implemented into a blender build?, so people can use your shanders from a menu.

Here you go Tony - for Blender 2.6

It needs some finishing touches though, but I will make a separate forum thread about this sometime soon.

Words cannot describe how awesome that looks. It’s just fantastic.


Lightscattering around a Lamp – nah, did I think, just make a Sprite around it…

But ~this~ is really incredible! I can imagine the (almost literal) “Atmosphere” that can be built up with this Effect!
Thank you, martinsh, and thank you, TonyPowell, for inspirin’ martinsh to share this so soon! : D

A Hint! (An important one?)
In the .blend, the Shader is called by an Always Actuator with True-Level-Triggering on. I just deactivated that and the Shader works, from what I can tell, exactly as good and correct.
(No Pulse, less Logic ingame – that is always a Benefit.)

Hmm, are there any docs on how shaders are used within Blender, I can mess around with the parameters in these, but it would be interesting to know how to extend them further.

Bro you are the man hahahahahaha cant believe you did this and so fast too, it looks incredible, soo awesome, i cant wait to play around with this and toss this into a game, hahahahahahaha. in the finishing touches will other objects block some of the light being emitted from the lamps, like if a play walks in front of the lamp, will we see a shadow of the player in the mist kinda of like in the old light scattering shader you made were the mountains block the sun’s rays and cast a shadow?

Dude this shader just made my day hahahahahahaha Thanks so much for this feature bro!!!


um, i found some issues with this shader, its messing the UV maps.
Its a nice one, but i cant find a solution yet.

I also noticed that. The Shader replaces the initial Material and since there is no Normalmap defined in that new Material, I loose my Normalmaps when usin’ that Shader.
So: Is it possible to change it into a 2D-Filter somehow?

Hello guys, thanks.
The shader is using 1 texture channel and has UV multiplied by 2, thats what is messing it up.
The way the shader works - it has to be applied on every object in the scene. Having it as overlay 2D filter would fix this issue. But right now it is not quite possible with in BGE.
I will make a shader version that will be easier to integrate on your own.

Simply amazing, thanks martinsh! :slight_smile:

Excuse me, martinsh, where can we worship you ?!?

No, but seriously, tremendous work and skill.


Hey hey Martinsh!! just checkin the thread again, this shader looks awesome, any word on the improvements on it for easier implementation, im thinkin this would be great for like laser blast or beams. also is it possible to tie this shader with a texture. so that its the texture that glows and emits light scattering, kinda like a futuristic armor that has some glowing lights emitting from its texture. also is it possible to have the light scattering produce a shadow in the mist when the light is blocked by an object. I never really looked into making shaders so i have no idea if this is complex to pull off, but if theres anyone here that make do it its def you bro!