Panda3D
fog.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file fog.I
10  * @author drose
11  * @date 2002-03-14
12  */
13 
14 /**
15  *
16  */
17 INLINE Fog::Mode Fog::
18 get_mode() const {
19  return _mode;
20 }
21 
22 /**
23  * Specifies the computation that is used to determine the fog effect. If
24  * this is M_linear, then the fog will range from linearly from the onset
25  * point to the opaque point (or for the distances specified in
26  * set_linear_range), and the fog object should be parented into the scene
27  * graph, or to the camera.
28  *
29  * If this is anything else, the onset point and opaque point are not used,
30  * and the fog effect is based on the value specified to set_exp_density(),
31  * and it doesn't matter to which node the fog object is parented, or if it is
32  * parented anywhere at all.
33  */
34 INLINE void Fog::
35 set_mode(Mode mode) {
36  _mode = mode;
37 }
38 
39 /**
40  * Returns the color of the fog.
41  */
42 INLINE const LColor &Fog::
43 get_color() const {
44  return _color;
45 }
46 
47 /**
48  * Sets the color of the fog.
49  */
50 INLINE void Fog::
51 set_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b) {
52  _color[0] = r;
53  _color[1] = g;
54  _color[2] = b;
55 }
56 
57 /**
58  * Sets the color of the fog. The alpha component is not used.
59  */
60 INLINE void Fog::
61 set_color(const LColor &color) {
62  _color = color;
63 }
64 
65 /**
66  * Specifies the effects of the fog in linear distance units. This is only
67  * used if the mode is M_linear.
68  *
69  * This specifies a fog that begins at distance onset units from the origin,
70  * and becomes totally opaque at distance opaque units from the origin, along
71  * the forward axis (usually Y).
72  *
73  * This function also implicitly sets the mode the M_linear, if it is not
74  * already set.
75  */
76 INLINE void Fog::
77 set_linear_range(PN_stdfloat onset, PN_stdfloat opaque) {
78  LVector3 forward = LVector3::forward();
79  _linear_onset_point = onset * forward;
80  _linear_opaque_point = opaque * forward;
81  _transformed_onset = onset;
82  _transformed_opaque = opaque;
83  _mode = M_linear;
84 }
85 
86 /**
87  * Returns the point in space at which the fog begins. This is only used if
88  * the mode is M_linear.
89  */
90 INLINE const LPoint3 &Fog::
91 get_linear_onset_point() const {
92  return _linear_onset_point;
93 }
94 
95 /**
96  * Specifies the point in space at which the fog begins. This is only used if
97  * the mode is M_linear.
98  */
99 INLINE void Fog::
100 set_linear_onset_point(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
101  _linear_onset_point.set(x, y, z);
102 }
103 
104 /**
105  * Specifies the point in space at which the fog begins. This is only used if
106  * the mode is M_linear.
107  */
108 INLINE void Fog::
109 set_linear_onset_point(const LPoint3 &linear_onset_point) {
110  _linear_onset_point = linear_onset_point;
111 }
112 
113 /**
114  * Returns the point in space at which the fog completely obscures geometry.
115  * This is only used if the mode is M_linear.
116  */
117 INLINE const LPoint3 &Fog::
118 get_linear_opaque_point() const {
119  return _linear_opaque_point;
120 }
121 
122 /**
123  * Specifies the point in space at which the fog completely obscures geometry.
124  * This is only used if the mode is M_linear.
125  */
126 INLINE void Fog::
127 set_linear_opaque_point(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
128  _linear_opaque_point.set(x, y, z);
129 }
130 
131 /**
132  * Specifies the point in space at which the fog completely obscures geometry.
133  * This is only used if the mode is M_linear.
134  */
135 INLINE void Fog::
136 set_linear_opaque_point(const LPoint3 &linear_opaque_point) {
137  _linear_opaque_point = linear_opaque_point;
138 }
139 
140 /**
141  * Fog effects are traditionally defined in camera-relative space, but the
142  * Panda Fog node has a special mode in which it can define a linear fog
143  * effect in an arbitrary coordinate space.
144  *
145  * This is done by specifying 3-d onset and opaque points, and parenting the
146  * Fog object somewhere within the scene graph. In this mode, the fog will be
147  * rendered as if it extended along the vector from the onset point to the
148  * opaque point, in 3-d space.
149  *
150  * However, the underlying fog effect supported by hardware is generally only
151  * one-dimensional, and must be rendered based on linear distance from the
152  * camera plane. Thus, this in-the-world effect is most effective when the
153  * fog vector from onset point to opaque point is most nearly parallel to the
154  * camera's eye vector.
155  *
156  * As the angle between the fog vector and the eye vector increases, the
157  * accuracy of the effect diminishes, up to a complete breakdown of the effect
158  * at a 90 degree angle.
159  *
160  * This function exists to define the workaround to this problem. The linear
161  * fallback parameters given here specify how the fog should be rendered when
162  * the parameters are exceeded in this way.
163  *
164  * The angle parameter is the minimum angle, in degrees, of the fog vector to
165  * the eye vector, at which the fallback effect should be employed. The onset
166  * and opaque parameters specify the camera-relative onset and opaque
167  * distances to pass to the rendering hardware when employing the fallback
168  * effect. This supercedes the 3-d onset point and opaque points.
169  */
170 INLINE void Fog::
171 set_linear_fallback(PN_stdfloat angle, PN_stdfloat onset, PN_stdfloat opaque) {
172  _linear_fallback_cosa = ccos(deg_2_rad(angle));
173  _linear_fallback_onset = onset;
174  _linear_fallback_opaque = opaque;
175 }
176 
177 /**
178  * Returns the density of the fog for exponential calculations. This is only
179  * used if the mode is not M_linear.
180  */
181 INLINE PN_stdfloat Fog::
182 get_exp_density() const {
183  return _exp_density;
184 }
185 
186 /**
187  * Sets the density of the fog for exponential calculations. This is only
188  * used if the mode is not M_linear.
189  *
190  * If the mode is currently set to M_linear, this function implicitly sets it
191  * to M_exponential.
192  */
193 INLINE void Fog::
194 set_exp_density(PN_stdfloat exp_density) {
195  nassertv((exp_density >= 0.0) && (exp_density <= 1.0));
196  _exp_density = exp_density;
197 
198  if (_mode == M_linear) {
199  _mode = M_exponential;
200  }
201 }
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 ...
Definition: fog.I:171
set_exp_density
Sets the density of the fog for exponential calculations.
Definition: fog.h:86
set_linear_onset_point
Specifies the point in space at which the fog begins.
Definition: fog.h:75
void set_linear_range(PN_stdfloat onset, PN_stdfloat opaque)
Specifies the effects of the fog in linear distance units.
Definition: fog.I:77
set_color
Sets the color of the fog.
Definition: fog.h:68
set_linear_opaque_point
Specifies the point in space at which the fog completely obscures geometry.
Definition: fog.h:80
set_mode
Specifies the computation that is used to determine the fog effect.
Definition: fog.h:63