Panda3D
rpPointLight.cxx
1 /**
2  *
3  * RenderPipeline
4  *
5  * Copyright (c) 2014-2016 tobspr <tobias.springer1@gmail.com>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  *
25  */
26 
27 
28 #include "rpPointLight.h"
29 
30 
31 /**
32  * @brief Constructs a new point light
33  * @details This contructs a new point light with default settings. By default
34  * the light is set to be an infinitely small point light source. You can
35  * change this with RPPointLight::set_inner_radius.
36  */
38  _radius = 10.0;
39  _inner_radius = 0.01;
40 }
41 
42 /**
43  * @brief Writes the light to a GPUCommand
44  * @details This writes the point light data to a GPUCommand.
45  * @see RPLight::write_to_command
46  *
47  * @param cmd The target GPUCommand
48  */
51  cmd.push_float(_radius);
52  cmd.push_float(_inner_radius);
53 }
54 
55 /**
56  * @brief Inits the shadow sources of the light
57  * @details This inits all required shadow sources for the point light.
58  * @see RPLight::init_shadow_sources
59  */
61  nassertv(_shadow_sources.size() == 0);
62  // Create 6 shadow sources, one for each direction
63  for(size_t i = 0; i < 6; ++i) {
64  _shadow_sources.push_back(new ShadowSource());
65  }
66 }
67 
68 /**
69  * @brief Updates the shadow sources
70  * @details This updates all shadow sources of the light.
71  * @see RPLight::update_shadow_sources
72  */
74  LVecBase3 directions[6] = {
75  LVecBase3( 1, 0, 0),
76  LVecBase3(-1, 0, 0),
77  LVecBase3( 0, 1, 0),
78  LVecBase3( 0, -1, 0),
79  LVecBase3( 0, 0, 1),
80  LVecBase3( 0, 0, -1)
81  };
82 
83  // Increase fov to prevent artifacts at the shadow map transitions
84  const float fov = 90.0f + 3.0f;
85  for (size_t i = 0; i < _shadow_sources.size(); ++i) {
86  _shadow_sources[i]->set_resolution(get_shadow_map_resolution());
87  _shadow_sources[i]->set_perspective_lens(fov, _near_plane, _radius,
88  _position, directions[i]);
89  }
90 }
virtual void update_shadow_sources()
Updates the shadow sources.
RenderPipeline.
Definition: shadowSource.h:51
get_shadow_map_resolution
Returns the shadow map resolution.
Definition: rpLight.h:100
void push_float(float v)
Appends a float to the GPUCommand.
Definition: gpuCommand.I:75
virtual void write_to_command(GPUCommand &cmd)
Writes the light to a GPUCommand.
Definition: rpLight.cxx:60
virtual void write_to_command(GPUCommand &cmd)
Writes the light to a GPUCommand.
Class for storing data to be transferred to the GPU.
Definition: gpuCommand.h:47
virtual void init_shadow_sources()
Inits the shadow sources of the light.
RenderPipeline.
Definition: rpLight.h:41
RPPointLight()
RenderPipeline.