Panda3D
|
Specifies how atmospheric fog effects are applied to geometry. More...
#include "fog.h"
Public Types | |
enum | Mode { M_linear, M_exponential, M_exponential_squared } |
Public Member Functions | |
Fog (const string &name) | |
void | adjust_to_camera (const TransformState *camera_transform) |
This function is intended to be called by the cull traverser to compute the appropriate camera-relative onset and opaque distances, based on the fog node's position within the scene graph (if linear fog is in effect). | |
virtual TypeHandle | force_init_type () |
const LColor & | get_color () const |
Returns the color of the fog. | |
PN_stdfloat | get_exp_density () const |
Returns the density of the fog for exponential calculations. | |
const LPoint3 & | get_linear_onset_point () const |
Returns the point in space at which the fog begins. | |
const LPoint3 & | get_linear_opaque_point () const |
Returns the point in space at which the fog completely obscures geometry. | |
void | get_linear_range (PN_stdfloat &onset, PN_stdfloat &opaque) |
Retrieves the current onset and offset ranges. | |
Mode | get_mode () const |
virtual TypeHandle | get_type () const |
virtual PandaNode * | make_copy () const |
Returns a newly-allocated Node that is a shallow copy of this one. | |
void | output (ostream &out) const |
Outputs the Namable. | |
void | set_color (PN_stdfloat r, PN_stdfloat g, PN_stdfloat b) |
Sets the color of the fog. | |
void | set_color (const LColor &color) |
Sets the color of the fog. | |
void | set_exp_density (PN_stdfloat exp_density) |
Sets the density of the fog for exponential calculations. | |
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. | |
void | set_linear_onset_point (PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) |
Specifies the point in space at which the fog begins. | |
void | set_linear_onset_point (const LPoint3 &linear_onset_point) |
Specifies the point in space at which the fog begins. | |
void | set_linear_opaque_point (const LPoint3 &linear_opaque_point) |
Specifies the point in space at which the fog completely obscures geometry. | |
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. | |
void | set_linear_range (PN_stdfloat onset, PN_stdfloat opaque) |
Specifies the effects of the fog in linear distance units. | |
void | set_mode (Mode mode) |
Specifies the computation that is used to determine the fog effect. | |
virtual void | write_datagram (BamWriter *manager, Datagram &dg) |
Writes the contents of this object to the datagram for shipping out to a Bam file. | |
virtual void | xform (const LMatrix4 &mat) |
Transforms the contents of this node by the indicated matrix, if it means anything to do so. | |
Static Public Member Functions | |
static TypeHandle | get_class_type () |
static void | init_type () |
static void | register_with_read_factory () |
Tells the BamReader how to create objects of type Fog. | |
Protected Member Functions | |
Fog (const Fog ©) | |
void | compute_density () |
void | fillin (DatagramIterator &scan, BamReader *manager) |
This internal function is called by make_from_bam to read in all of the relevant data from the BamFile for the new Fog. | |
Static Protected Member Functions | |
static TypedWritable * | make_from_bam (const FactoryParams ¶ms) |
This function is called by the BamReader's factory when a new object of type Fog is encountered in the Bam file. | |
Protected Attributes | |
LColor | _color |
PN_stdfloat | _exp_density |
PN_stdfloat | _linear_fallback_cosa |
PN_stdfloat | _linear_fallback_onset |
PN_stdfloat | _linear_fallback_opaque |
LPoint3 | _linear_onset_point |
LPoint3 | _linear_opaque_point |
Mode | _mode |
PN_stdfloat | _transformed_onset |
PN_stdfloat | _transformed_opaque |
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.
void Fog::adjust_to_camera | ( | const TransformState * | camera_transform | ) |
This function is intended to be called by the cull traverser to compute the appropriate camera-relative onset and opaque distances, based on the fog node's position within the scene graph (if linear fog is in effect).
Definition at line 155 of file fog.cxx.
References LVector3f::forward(), PandaNode::get_num_parents(), and LVecBase3f::normalize().
Referenced by CullTraverser::traverse().
void Fog::fillin | ( | DatagramIterator & | scan, |
BamReader * | manager | ||
) | [protected, virtual] |
This internal function is called by make_from_bam to read in all of the relevant data from the BamFile for the new Fog.
Reimplemented from PandaNode.
Definition at line 261 of file fog.cxx.
References DatagramIterator::get_int8(), DatagramIterator::get_stdfloat(), LVecBase4f::read_datagram(), and LVecBase3f::read_datagram().
Referenced by make_from_bam().
const LColor & Fog::get_color | ( | ) | const [inline] |
PN_stdfloat Fog::get_exp_density | ( | ) | const [inline] |
const LPoint3 & Fog::get_linear_onset_point | ( | ) | const [inline] |
const LPoint3 & Fog::get_linear_opaque_point | ( | ) | const [inline] |
void Fog::get_linear_range | ( | PN_stdfloat & | onset, |
PN_stdfloat & | opaque | ||
) |
PandaNode * Fog::make_copy | ( | ) | const [virtual] |
TypedWritable * Fog::make_from_bam | ( | const FactoryParams & | params | ) | [static, protected] |
This function is called by the BamReader's factory when a new object of type Fog is encountered in the Bam file.
It should create the Fog and extract its information from the file.
Reimplemented from PandaNode.
Definition at line 242 of file fog.cxx.
References fillin().
Referenced by register_with_read_factory().
void Fog::output | ( | ostream & | out | ) | const [virtual] |
void Fog::register_with_read_factory | ( | ) | [static] |
Tells the BamReader how to create objects of type Fog.
Reimplemented from PandaNode.
Definition at line 209 of file fog.cxx.
References BamReader::get_factory(), make_from_bam(), and Factory< Type >::register_factory().
void Fog::set_color | ( | PN_stdfloat | r, |
PN_stdfloat | g, | ||
PN_stdfloat | b | ||
) | [inline] |
void Fog::set_color | ( | const LColor & | color | ) | [inline] |
void Fog::set_exp_density | ( | PN_stdfloat | exp_density | ) | [inline] |
void Fog::set_linear_fallback | ( | PN_stdfloat | angle, |
PN_stdfloat | onset, | ||
PN_stdfloat | opaque | ||
) | [inline] |
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 Fog::set_linear_onset_point | ( | PN_stdfloat | x, |
PN_stdfloat | y, | ||
PN_stdfloat | z | ||
) | [inline] |
void Fog::set_linear_onset_point | ( | const LPoint3 & | linear_onset_point | ) | [inline] |
void Fog::set_linear_opaque_point | ( | const LPoint3 & | linear_opaque_point | ) | [inline] |
void Fog::set_linear_opaque_point | ( | PN_stdfloat | x, |
PN_stdfloat | y, | ||
PN_stdfloat | z | ||
) | [inline] |
void Fog::set_linear_range | ( | PN_stdfloat | onset, |
PN_stdfloat | opaque | ||
) | [inline] |
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.
Definition at line 95 of file fog.I.
References LVector3f::forward().
void Fog::set_mode | ( | Mode | mode | ) | [inline] |
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.
void Fog::write_datagram | ( | BamWriter * | manager, |
Datagram & | dg | ||
) | [virtual] |
Writes the contents of this object to the datagram for shipping out to a Bam file.
Reimplemented from PandaNode.
Definition at line 220 of file fog.cxx.
References Datagram::add_int8(), Datagram::add_stdfloat(), LVecBase4f::write_datagram(), and LVecBase3f::write_datagram().
void Fog::xform | ( | const LMatrix4 & | mat | ) | [virtual] |