Hi :yes:
Recently I have made cycle/night day in my game and I wanna add some mist in color of the currently sun is shining on horizon. Color must be change in real time.
Try to keyframe the different colours (right-click on the colour button). I already tried something similiar a couple of months ago (It didn’t work…:().
Theres almost no way to get it to work these days. All the old tricks no longer work.
It may be possible with a custom 2d shader, but after I tried some code with the depth texture I found that it doesnt include transparent objects which could cause ugly results.
I did have some limited success though so I may try to clean up the code and see if I can get something useable.
@Smoking_mirror Thanks for interest in this case Its very important for my project, would be great if something could work.
@ Half way to success, its need a depth. But maybe…
But it is really basic and I don’t know if it is a good way to proceed. Furthermore there are errors in the fragment shader while assigning new color value to gl_Fog.color…
FurtherFurthermore, it’s just a part of the problem. Ambient lighting needs also to be modified. But maybe that’s a beginning of answer?
If you need start/end value for the fog, you have to use gl_Fog.start and gl_Fog.end in the equation… Or a python code maybe…
EDIT: For the beginning distance of the fog, you can replace:
There are fixes by HG1 that bring the the possibility of changing world settings in-game when GLSL mode is on.
Unfortunately, they have been stuck in the review tracker and I don’t think any current BGE dev. has had time to look at them more closely, hence one of the reasons why so many in this forum are looking to move on to another engine.
@Raco: It’s a good thing to update only objects in the frustum. But what is wrong with my initial shader is that this shader is applied to ALL objects (in the frustum or in the scene) and each object in a real game has its own properties (specular, shininess, textures etc…) and the initial shader didn’t take into account those parameters. I forgot transparency too. And when you apply shader to an object, shader replaces object’s material. So you have to write a “complete” shader to take into account specular, transparency, shininess, textures of each object in the frustum or in the scene… (EDIT: and if you run the complete shader each frame, it will slow down your computer… You can execute the script more than one time per minute… That was just an example)
I’ll post an example to illustrate what I’m trying to mean:
Tonight I had a few minutes to hack together something of a 2d mist shader. It’s far from perfect, you’ll notice that if you have anything which is transparent (not clip alpha though) in front of the mist, it will be fully affected.
You’ll need to add these properties to the game object with the 2d filter actuator.
near
far
r
g
b
Far and Near are your controls. A higher far setting (about 5.0) will thin the mist towards the horizon. A lower near value (-2.0) will cause the mist to start nearer the camera. If near and far values are close together (-0.2,0.2) you’ll get quite thick mist. Far apart values will give thin mist (-12.0,12.0).
You can set the color with the r,g and b values.
Play around with the settings and see what gives you the best results. I’m not glsl expert so I can’t tell you if this is an optimal solution, but it seems to work OK on my computer.
Hi! That’s a very cool solution! I didn’t know bgl_DepthTexture (I didn’t know gl_Fog yesterday too :)). I mistaked mist for fog. 2D filter seems to be the right thing to work with. Thanks for sharing!
Yeahh I agree thats nice. But…
Smoking mirror script is not working for me (no error). For example in sdfgeoff works fine.
I set up all settings, properties fine on 100%. Even I tried to modify/split first script with second but the effect was one color screen (also no error)
I have ATI card and weak knowledge at glsl.
in this moment am still trying to alive Smoking mirror’s script on my computer.
will let you know how I find something…
Now all the standard mist equations are working fine!
Here’s a blend. W to increase mist distance, Q to change it’s redness. This time distances are in blender units and both near and far can be adjusted in a sensible way.
However, you also need to specify the camera clipping distances to the script.
Many thanks to Martinish for his DOF filter. You can’t see any of it left in the shader here, but it all started with his DOF filter, and I stripped out the blur, stripped out the vinegetting, stripped out this, stripped out that, tweaked what was left, and now it works!
Plans:
Add in exponential decay fog. (Now done, not uploaded yet)
Make it into a mist sphere not a mist plane. (Can of worms. Useful Link?)
Long term plan:
Actually, this fits in really well with something I’m working on currently (A base ‘wrapper’ for any future game I make), so I’ll try to expand this mist script to have the following features:
Controllable Color (Done)
Controllable density type (Linear, Quadratic, Exponential)
Controllable Density/Depth (Done for linear and exponential case)
Controllable clipping (Plane Done, Sphere = current WIP)
That’s awesome. I got a lot of hints from looking at Martinsh’s code too. Even though it does something completely different to what I want, just having some signposts to follow is so useful.
My own code is so often just a hack, like in this case, reduce the brightness, increase the contrast and then map to a useable color value.
There’s lots of cool stuff you could do with this base though; heat shimmer in the distance, fast DOF, noisy mist, textured fog…
Cool.
You can’t do so with the current available textures in 2d filters, yet you can set up 2 render to texture cameras, the first renders the scene normally, and the other renders your desired “mist-proof” object as a mask for when you apply a fragment shader on your first render to texture, setting the pixel shader coords to window borders.
Sorry for my terrible explanation, the process has to be that “hacky” when you’re working with the bge.