# Fog¶

class Fog

Bases: PandaNode

Specifies how atmospheric fog effects are applied to geometry. The Fog object is now a PandaNode, which means it can be used similarly to a Light to define effects relative to a particular coordinate system within the scene graph.

In exponential mode, the fog effects are always camera-relative, and it does not matter where the Fog node is parented. However, in linear mode, the onset and opaque distances are defined as offsets along the local forward axis (e.g. the Y axis). This allows the fog effect to be localized to a particular region in space, rather than always camera- relative. If the fog object is not parented to any node, it is used to generate traditonal camera-relative fog, as if it were parented to the camera.

Inheritance diagram

enum Mode
enumerator M_linear = 0

f = (end - z) / (end - start)

enumerator M_exponential = 1

f = e^(-density * z)

enumerator M_exponential_squared = 2

f = e^((-density * z)^2)

explicit Fog(std::string const &name)
static TypeHandle get_class_type(void)
LColor const &get_color(void) const

Returns the color of the fog.

PN_stdfloat get_exp_density(void) const

Returns the density of the fog for exponential calculations. This is only used if the mode is not M_linear.

LPoint3 const &get_linear_onset_point(void) const

Returns the point in space at which the fog begins. This is only used if the mode is M_linear.

LPoint3 const &get_linear_opaque_point(void) const

Returns the point in space at which the fog completely obscures geometry. This is only used if the mode is M_linear.

Mode get_mode(void) const
void set_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b)
void set_color(LColor const &color)

Sets the color of the fog.

Sets the color of the fog. The alpha component is not used.

void set_exp_density(PN_stdfloat exp_density)

Sets the density of the fog for exponential calculations. This is only used if the mode is not M_linear.

If the mode is currently set to M_linear, this function implicitly sets it to M_exponential.

void set_linear_fallback(PN_stdfloat angle, PN_stdfloat onset, PN_stdfloat opaque)

Fog effects are traditionally defined in camera-relative space, but the Panda Fog node has a special mode in which it can define a linear fog effect in an arbitrary coordinate space.

This is done by specifying 3-d onset and opaque points, and parenting the Fog object somewhere within the scene graph. In this mode, the fog will be rendered as if it extended along the vector from the onset point to the opaque point, in 3-d space.

However, the underlying fog effect supported by hardware is generally only one-dimensional, and must be rendered based on linear distance from the camera plane. Thus, this in-the-world effect is most effective when the fog vector from onset point to opaque point is most nearly parallel to the camera’s eye vector.

As the angle between the fog vector and the eye vector increases, the accuracy of the effect diminishes, up to a complete breakdown of the effect at a 90 degree angle.

This function exists to define the workaround to this problem. The linear fallback parameters given here specify how the fog should be rendered when the parameters are exceeded in this way.

The angle parameter is the minimum angle, in degrees, of the fog vector to the eye vector, at which the fallback effect should be employed. The onset and opaque parameters specify the camera-relative onset and opaque distances to pass to the rendering hardware when employing the fallback effect. This supercedes the 3-d onset point and opaque points.

void set_linear_onset_point(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
void set_linear_onset_point(LPoint3 const &linear_onset_point)

Specifies the point in space at which the fog begins. This is only used if the mode is M_linear.

void set_linear_opaque_point(LPoint3 const &linear_opaque_point)
void set_linear_opaque_point(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)

Specifies the point in space at which the fog completely obscures geometry. This is only used if the mode is M_linear.

void set_linear_range(PN_stdfloat onset, PN_stdfloat opaque)

Specifies the effects of the fog in linear distance units. This is only used if the mode is M_linear.

This specifies a fog that begins at distance onset units from the origin, and becomes totally opaque at distance opaque units from the origin, along the forward axis (usually Y).

This function also implicitly sets the mode the M_linear, if it is not already set.

void set_mode(Fog::Mode mode)

Specifies the computation that is used to determine the fog effect. If this is M_linear, then the fog will range from linearly from the onset point to the opaque point (or for the distances specified in set_linear_range()), and the fog object should be parented into the scene graph, or to the camera.

If this is anything else, the onset point and opaque point are not used, and the fog effect is based on the value specified to set_exp_density(), and it doesn’t matter to which node the fog object is parented, or if it is parented anywhere at all.