1 /**************************************************************************\
2 * Copyright (c) Kongsberg Oil & Gas Technologies AS
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 \**************************************************************************/
32
33 /*!
34 \class SoShadowSpotLight SoShadowSpotLight.h Inventor/annex/FXViz/nodes/SoShadowSpotLight.h
35 \brief The SoShadowSpotLight class is a node for setting up a spot light which casts shadows.
36
37 This node can be used instead of a normal SpotLight if you need to
38 improve the performance by supplying a simplified scene graph to be
39 used when rendering the shadow map(s). For instance, the shadow map
40 scene graph doesn't need any textures or materials, and any
41 non-casters can also be excluded from this scene graph. It's more
42 optimal to use this node than to use the SoShadowStyle node to
43 control this, at the cost of some extra application complexity.
44
45 It's especially useful if you have a scene with few shadow caster
46 nodes and lots of shadow receiver nodes.
47
48 Currently, this node must be placed somewhere in the SoShadowGroup
49 subgraph to cast shadows.
50
51 \ingroup nodes
52
53 <b>FILE FORMAT/DEFAULTS:</b>
54 \code
55 ShadowSpotLight {
56 shadowMapScene NULL
57 nearDistance -1
58 farDistance -1
59 }
60 \endcode
61
62 Here is the the example from SoShadowGroup, modified to use SoShadowSpotLight
63 instead of a normal SoSpotLight. Notice that only the sphere casts shadows.
64
65 \code
66
67 DirectionalLight { direction 0 0 -1 intensity 0.2 }
68
69 ShadowGroup {
70 quality 1 # to get per pixel lighting
71
72 ShadowSpotLight {
73 location -8 -8 8.0
74 direction 1 1 -1
75 cutOffAngle 0.35
76 dropOffRate 0.7
77
78 shadowMapScene
79 DEF sphere Separator {
80 Complexity { value 1.0 }
81 Material { diffuseColor 1 1 0 specularColor 1 1 1 shininess 0.9 }
82 Shuttle { translation0 -3 1 0 translation1 3 -5 0 speed 0.25 on TRUE }
83 Translation { translation -5 0 2 }
84 Sphere { radius 2.0 }
85 }
86 }
87 # need to insert the sphere in the regular scene graph as well
88 USE sphere
89
90 Separator {
91 Material { diffuseColor 1 0 0 specularColor 1 1 1 shininess 0.9 }
92 Shuttle { translation0 0 -5 0 translation1 0 5 0 speed 0.15 on TRUE }
93 Translation { translation 0 0 -3 }
94 Cube { depth 1.8 }
95 }
96 Separator {
97 Material { diffuseColor 0 1 0 specularColor 1 1 1 shininess 0.9 }
98 Shuttle { translation0 -5 0 0 translation1 5 0 0 speed 0.3 on TRUE }
99 Translation { translation 0 0 -3 }
100 Cube { }
101 }
102
103 Coordinate3 { point [ -10 -10 -3, 10 -10 -3, 10 10 -3, -10 10 -3 ] }
104 Material { specularColor 1 1 1 shininess 0.9 }
105
106 Complexity { textureQuality 0.1 }
107 Texture2 { image 2 2 3 0xffffff 0x225588 0x225588 0xffffff }
108 Texture2Transform { scaleFactor 4 4 }
109 FaceSet { numVertices 4 }
110 }
111
112 \endcode
113
114 \since Coin 3.0
115 */
116
117 /*!
118 \var SoSFNode SoShadowSpotLight::shadowMapScene
119
120 The shadow map scene graph. If this is NULL (the default), the node
121 will behave as a normal SoSpotLight node.
122
123 */
124
125 /*!
126 \var SoSFFloat SoShadowSpotLight::nearDistance
127
128 Can be used to set a fixed near distance for this spot light. The value in this
129 field will be used if it's set to > 0.0. Default value is -1.0.
130 */
131
132 /*!
133 \var SoSFFloat SoShadowSpotLight::farDistance
134
135 Can be used to set a fixed far distance for this spot light. The value in this
136 field will be used if it's set to > 0.0. Default value is -1.0.
137 */
138
139
140
141 // *************************************************************************
142
143 #include <Inventor/annex/FXViz/nodes/SoShadowSpotLight.h>
144
145 #include <cstdio>
146 #include <Inventor/actions/SoGLRenderAction.h>
147
148 #include "nodes/SoSubNodeP.h"
149
150 // *************************************************************************
151
152
153 SO_NODE_SOURCE(SoShadowSpotLight);
154
155 /*!
156 Constructor.
157 */
SoShadowSpotLight(void)158 SoShadowSpotLight::SoShadowSpotLight(void)
159 {
160 SO_NODE_INTERNAL_CONSTRUCTOR(SoShadowSpotLight);
161 SO_NODE_ADD_FIELD(shadowMapScene, (NULL));
162 SO_NODE_ADD_FIELD(nearDistance, (-1.0f));
163 SO_NODE_ADD_FIELD(farDistance, (-1.0f));
164 }
165
166 /*!
167 Destructor.
168 */
~SoShadowSpotLight()169 SoShadowSpotLight::~SoShadowSpotLight()
170 {
171 }
172
173 // Doc from superclass.
174 void
initClass(void)175 SoShadowSpotLight::initClass(void)
176 {
177 SO_NODE_INTERNAL_INIT_CLASS(SoShadowSpotLight, SO_FROM_COIN_3_0);
178 }
179
180 // Doc from superclass.
181 void
GLRender(SoGLRenderAction * action)182 SoShadowSpotLight::GLRender(SoGLRenderAction * action)
183 {
184 inherited::GLRender(action);
185 }
186
187
188
189 #ifdef COIN_TEST_SUITE
190
BOOST_AUTO_TEST_CASE(initialized)191 BOOST_AUTO_TEST_CASE(initialized)
192 {
193 SoShadowSpotLight * node = new SoShadowSpotLight;
194 assert(node);
195 node->ref();
196 BOOST_CHECK_MESSAGE(node->getTypeId() != SoType::badType(),
197 "missing class initialization");
198 node->unref();
199 }
200
201 #endif // COIN_TEST_SUITE
202