Fog reparenting

Hi again!

I’m trying to implement fog as the manual:

		self.fog = Fog("atmosphere")

The manual said, if the fog affects the entire world, then it should be reparented to render. However, fog instance doesn’t have a reparentTo member function…

Looking at the online documentation, the fog class intro said if the fog is not parented to anything, it affacts the camera everywhere…

But I still don’t see fog. Any insights? :slight_smile:

The manual is a little inaccurate with respect to fog. Our apologies.

First, Fog is a type of node, i.e. it derives from PandaNode; it is not a NodePath. If you want to parent a Fog object into the scene graph, the easiest way is to wrap a NodePath around it and use the reparentTo() method of the NodePath, like this:

np = NodePath(self.fog)

A full explanation of the distinction between a PandaNode, which is the basic atom of the scene graph, and a NodePath, which is a wrapper around a node and provides a high-level API for fundamental scene graph operations, should probably be in one of the first chapters of the manual.

In any case, reparenting the Fog into the scene graph has absolutely nothing to do with what part of the scene it applies to. In fact, if you are calling setExpDensity(), which puts the fog in exponential mode (as opposed to its default, linear mode), then the node that the Fog object is parented to has no effect whatsoever, and you probably shouldn’t bother trying to parent it into the graph. (The node that the Fog is parented to only affects the fog when it is linear mode, and then its effect is to change the origin and direction of the fog.)

The way that that you actually enable the Fog is via the NodePath.setFog() method. If you want to fog the whole world, do this:


To turn off the fog again:


Note that fog does not affect the clear color of the window, so unless you have a completely interior scene you may also want to change your window’s background color to match the color of your fog:

base.setBackgroundColor(1, 1, 0)


You can also use:



Thanks for this drwr. I have tried to improve the manual page on Fog based on the previous page, this thread, the API and some small experiments. One thing I can’t figure out is how to actually use linear fog with setLinearFallback and actually make it look good? Maybe you can give us some tips or an example?

See my examples and doc here:

Good work, thanks. A few clarifications:

The Fog and FogAttrib classes actually work together to implement Fog. It is similar to PointLight and LightAttrib, or Texture and TextureAttrib, or any of a whole family of FooAttrib classes. In general, attributes are applied to nodes in Panda using a RenderAttrib class. But the RenderAttrib is a very low-level mechanism; you don’t usually have to use the RenderAttrib class directly, because there are high-level NodePath methods that do this for you. For instance, in this case, the nodePath.setFog() call actually creates a FogAttrib on the node in question. You can see this when you do

We really need a manual page, or a series of pages, that goes into detail about this whole scene graph attribute mechanism. As it is, we have only a page that very briefly mentions it and then says nothing more. In the meantime, I recommend not even mentioning FogAttrib on the fog manual page (since it distracts from the main point), or at most mentioning it as a low-level mechanism that you don’t need to use directly.

The setLinearFallback() will always look bad when applied to an object out in the open that you can approach from any angle. It’s really designed for something that is in a very specific environment that constrains your approach angle, for instance, an object deep within a dark cave.

By the way, I’m pretty sure you can’t have multiple Fog nodes in effect over the whole scene at once. You can put apply different Fog effects to different nodes in the scene, but any one node can only have one kind of Fog at a time. This is just a limitation imposed by the hardware.