Game beauty Fog/Mist, Shaders, LOD

Im currently deep into my game project at the moment.

Ive just finished setting up a dynamic lighting, dynamic loading system & Level of Detail on distant objects for Poly count and animation optimising.

anyways at the moment im coding a Day Night Cycle and can change the lighting positions & settings, the skybox color & mesh. But im getting a little annoyed at animating mist.

Yeh you guessed it GLSL because we are in the year 2013. I know the commands are broken for changing anything to do with it. But one thing ive noticed on these forums that people have acknowledged the problem, but nobody has presented any viable alternatives or solutions.

The Yo Frankie method of using Nodes on every single material seems to me a bit excessive just for fog or distant haze. Im not even sure you can even adjust the color in realtime. (this is a must)

  1. Are there any GLSL Vert/Frag 2D filters that can utilize the Z depth of the scene or maybe a Ray sensor attached to the camera. Can anyone offer any solutions?

  2. How viable would it be, and what advantages are there to completely text coding materials in GLSL other than using nodes & material editor.



Here is what im currently working with.


  1. 2D (screen) filters can access the depth texture, so you should be able to get the Z depth of the scene and fade objects out easily that way.

  2. Text shaders gives you more control, while nodes are easier to set up and visualize. Obviously, you can’t do everything with nodes, but you can do a surprising amount with them. Text shaders also overwrite the material setup, so you’ll have to set up everything from scratch (including shadows), whereas node materials can be built on top of other materials.

  1. Solar you have given me an idea to try, im going to intergrate Object Color and alpha into the LOD module and basically use an action to fade in/out either the color or alpha according to distance from the camera. : E2a Doesn’t work

As for Terrain and Planes/sky im still trying a few things.

  1. Thanks, thats just what im looking for. I don’t mind extra work or code for nicer results as you can see.

This stage is definately the most intensive, but affects how the rest of the game will function.

For indoors im using Zones for different rooms and once triggered lights & objects are replaced according to location.

i had some issues with libload and lighting but basically made a script that allows them to be swapped easily.

for the levels themselves trees, grass, rocks are linked into the level, the level is libloaded into a master blend along with The player, HUD & Weapon.


I’m getting closer, at the bottom of the blender wiki page linked below does it the Yo Frankie way as ive decided to choke up and use it for every object. With linking datablocks from scenes its not so bad.

last thing i need to do is find a way of manipulating elements of the Node group so i can adjust distance and color Realtime.

if i find a way i’ll let you know.

Edit: B2.65.8 Word of warning dont link materials and shader nodes too much from file to file, my tree asset and entire level blend has become currupted. I lost a few hours work.


Ok i have a solution, it is however crude.

Basically within the Nodes the fog image comes from the Swap material which uses Video Texture to change it.

So not only can you use colors, you can also use gradients and images. You can do this an unlimited amount of times with as many images as you like.

Ive posted an example blend and image at the bottom of the post if anyone stumbles accross this.

# Imports and Naming

import bge
from bge import texture
from bge import logic
from bge import events

Cont = logic.getCurrentController()
Scene = logic.getCurrentScene()
Obj = Cont.owner

# Keyboard Events
keyboard =
kbSpace = events.SPACEKEY

# Set Initial State

if not "State" in Obj:
     Obj["State"] = "Blue"

# Correct State and Space Key pressed
if keyboard[kbSpace] and Obj["State"] == "Blue":

     # Change State
     Obj["State"] = "Orange"
     # Setup for Texture Swap
     matID = texture.materialID(Obj, "MA" + Obj["Material"])
     object_texture = texture.Texture(Obj, matID)
     url = logic.expandPath("//MistOrange.jpg")
     new_source = texture.ImageFFmpeg(url)
     # Swap The texture   
     Obj["Texture"] = object_texture
     Obj["Texture"].source = new_source


MistColorChanger.blend (658 KB)