Having some issues with mist + python

I am trying to change the color of the mist using python somehow. I have scoured the api’s and google and think that the following python functions should do the job.


But it doesn’t. The mist doesn’t change at all. I’m a little bit lost with this. I’m working in GLSL and the couple of examples of setting mist color I found on BA, only worked in multitexture mode. I’m currently looking into using a GLSL shader to handle the mist, but I was wondering if anyone was having luck with the functions above, using the bge api.

Any tips?

Yeah, thats really weird. I tried to figure something out but can’t do it. Probably because GLSL takes its values from somewhere else. Maybe the World settings, Horizon color is mist color. But to get there you must use bpy and you can do that only inside Blender. So when you export your game this wont work, but that means that it must be somewhere else because the exported game knows the color.

I think they really are broken, but I don’t recall much in the way of people trying to use them in recent years so the devs. may have not been aware of it.

I would also like to add that bge.render.setAmbientColor(rgb) is also broken. It seems like the only world rendering function that works right now is bge.render.setBackgroundColor(rgba)

I think I recall something about some of these functions working if there’s no world specified for the scene? In any case, it should be fixed.

With no world you have no physics as well. So if the functions worked in that case then you might get it working, but then you can’t really make a game, so the functions being fixed are a must.

They are not broken. I use them.
Here’s the secret:
You can’t start mist from the logic panel, you have to turn the mist on from a script.
If you do that, then everything else works.

If you don’t, then (as you’ve noticed) nothing does a thing.

Torakunsama showed me this and provided me with the following blend:

Odd isn’t it? I should probably bug-report it some time.

Moved from “Team Projects” to “Game Engine Support and Discussion”

Ok, thanks for the tips everyone, seems like its not only me that is having issues with this. I’ve tried removing the world from the scene, but still no luck at all.

sdfgeoff, thanks for the file, but as soon as you switch to GLSL mode, the mist does not work anymore. I think I found that blend file when I was searching for a solution.

Time for some investigation. I’ve had a look through the source code for the Rasterizer and it looks like all the python functions are bound correctly to a pyObject in the C source. These functions then seem to call SetFogColor on the OpenGLRasterizer which runs some gl functions that seem to deal with fog. Everything looks to be linked up, so I’m thinking that this problem lies somewhere in the open_gl calls, which is where I start to feel dizzy, trying to get to grips with open_gl programming. I will try and continue to find the problem, but I have a feeling that the issue is over my head.

There has been a bugin the bge tracker since 2011 about mist, but it still hasn’t been assigned to anyone yet. I wish the tracker had some sort of ‘upvote’ system, so users could vote up the bugs they want fixed first.

What about working on porting over volumetrics? I would love to see a voxel rendering patch,
have you seen this?

What is the mist for?
you may be able to fake it,
also, is there such a thing as a shader fog?

I really don’t think its as simple as ‘porting over’ to implement voxels. Atomontage looks great, I’ve been following the development of that for some time now, but I still haven’t really seen it used in games yet. Seems to be more aligned to visualization and things at the moment, and it would take a lot of time and effort for someone to implement in the bge. Plus, fixing the python bindings to the api should definitely not require a whole new rendering engine to be implemented. You don’t buy a lambo when your skoda breaks down.

What is the mist for?

well…its for mist. I’ve got a day/night cycle working nicely, it just looks silly when the mist does not change color with the skybox.

you may be able to fake it,
also, is there such a thing as a shader fog?

Had a quick look into a GLSL shader to handle the mist but I would prefer to use the bge api to do this, especially since the python functions seems to be there.

Thank you for your efforts sir :slight_smile: