Directional fog

Hello, folks. Panda is great, but it lacks good documentation.

I want to make a fog that is dependent not only on the distance but also on angle. I. e. i want the horizon to be covered with fog, but not objects far above my head. Is it possible?

first off. pandas’s documentation is by far better and more complete than any other engine i saw before cough

to your question. pretty much everything is possible. thought i wouldnt know any building function to do so. so you most likely will need to write a simple shader for it.

if you want to avoid writing shaders you could manually set the color-scale of your object every frame using a task and some basic math. this will most likely be slower than shaders if you have many objects. and it wont work on huuuuuuuge objects reaching from the horizon up to far above your head. but it might be a valid alternative in many cases.


Thomas is absoutely right. The fixed-function graphics pipeline in your graphics card can only make distance-based fog, so if you want something else, you either have to fake it with some trick like Thomas suggests, or write a shader to do it.


Sorry for stupid question, but do shaders work on non-shader-supporting cards (GL 2.x)? I mean, does Panda fallback to a software emulation of shaders?

Software emulation of shaders? Sounds mucky. No, Panda won’t do anything like that, although it’s theoretically possible that your graphics driver might. (NVidia does provide a special graphics driver you can install that will do just that, or at least they used to.)

I can’t think any reason you’d want this behavior, though, except for developing code for shader-capable hardware that you don’t have. This is the only reason NVidia provided this driver, after all. But you wouldn’t want to run in this mode, it would be far too slow for most real-time purposes.


Then what do Real Men do when they want to write code that works both on shader and non-shader aware cards, still utilizing the most from them? Do I need separate cases for both types of cards?

Dunno if I belong to the “Real Men”, but I’d not worry so much if you aim at most gamers, even most old video cards have support for shaders. Really, it’s hard to buy a new computer with a card that doesn’t support shaders.
But if you want to stay compatible with prehistoric GPU’s as well (and people without GPU), I’d make separate cases: if shaders are supported (which you can check through, otherwise use less-fancy non-directional fog, or sometimes you can fake effects with texture projection or combine modes.
(For example, things like normal mapping can be done without shaders, by utilizing combine modes only, which is also implemented through NodePath.setNormalMap)

In this particular case, you might be able to do this stuff by setting the fog thickness based on the angle with which one looks upward - if one looks up, the fog thickness gets set less than if one looks forward.

Actually, that’s not really true. In fact, it’s quite easy to do this, if you buy one of the sub-$500 PC’s that are increasingly common, and it turns out that vast numbers of people have been doing this recently.

It is true that hardcore gamers, or anyone who understands about graphics hardware and cares about graphics quality, will avoid buying a machine with one of these integrated graphics cards, or will upgrade the graphics card separately. But if you’re writing a game for the masses, you have to be prepared to write a game for someone with one of these limited cards. These modern integrated graphics cards perform very similarly to the “prehistoric” cards of five years ago or more, and they rarely have good support for shaders. (Increasingly, though, they do have some shader support, especially with the increasing penetration of Vista.)