Panda3D
Loading...
Searching...
No Matches
rpSpotLight.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 "rpSpotLight.h"
29
30#ifndef _USE_MATH_DEFINES
31#define _USE_MATH_DEFINES
32#endif
33#include <math.h>
34
35
36/**
37 * @brief Creates a new spot light
38 * @details This creates a new spot light with default properties set. You should
39 * set at least a direction, fov, radius and position to make the light useful.
40 */
42 _radius = 10.0;
43 _fov = 45.0;
44 _direction.set(0, 0, -1);
45}
46
47/**
48 * @brief Writes the light to a GPUCommand
49 * @details This writes the spot light data to a GPUCommand.
50 * @see RPLight::write_to_command
51 *
52 * @param cmd The target GPUCommand
53 */
56 cmd.push_float(_radius);
57
58 // Encode FOV as cos(fov)
59 cmd.push_float(cos(_fov / 360.0 * M_PI));
60 cmd.push_vec3(_direction);
61}
62
63/**
64 * @brief Inits the shadow sources of the light
65 * @details This inits all required shadow sources for the spot light.
66 * @see RPLight::init_shadow_sources
67 */
69 nassertv(_shadow_sources.size() == 0);
70 _shadow_sources.push_back(new ShadowSource());
71}
72
73/**
74 * @brief Updates the shadow sources
75 * @details This updates all shadow sources of the light.
76 * @see RPLight::update_shadow_sources
77 */
79 _shadow_sources[0]->set_resolution(get_shadow_map_resolution());
80 _shadow_sources[0]->set_perspective_lens(_fov, _near_plane, _radius, _position, _direction);
81}
82
Class for storing data to be transferred to the GPU.
Definition gpuCommand.h:47
void push_float(float v)
Appends a float to the GPUCommand.
Definition gpuCommand.I:75
void push_vec3(const LVecBase3 &v)
Appends a 3-component floating point vector to the GPUCommand.
Definition gpuCommand.I:91
RenderPipeline.
Definition rpLight.h:41
virtual void write_to_command(GPUCommand &cmd)
Writes the light to a GPUCommand.
Definition rpLight.cxx:60
get_shadow_map_resolution
Returns the shadow map resolution.
Definition rpLight.h:100
RPSpotLight()
Creates a new spot light.
virtual void update_shadow_sources()
Updates the shadow sources.
virtual void write_to_command(GPUCommand &cmd)
Writes the light to a GPUCommand.
virtual void init_shadow_sources()
Inits the shadow sources of the light.
RenderPipeline.