Panda3D
Loading...
Searching...
No Matches
rpLight.h
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#ifndef RPLIGHT_H
28#define RPLIGHT_H
29
30#include "referenceCount.h"
31#include "luse.h"
32#include "gpuCommand.h"
33#include "shadowSource.h"
34
35/**
36 * @brief Base class for Lights
37 * @details This is the base class for all lights in the render pipeline. It
38 * stores common properties, and provides methods to modify these.
39 * It also defines some interface functions which subclasses have to implement.
40 */
41class RPLight : public ReferenceCount {
42PUBLISHED:
43 /**
44 * Different types of light.
45 */
46 enum LightType {
47 LT_empty = 0,
48 LT_point_light = 1,
49 LT_spot_light = 2,
50 };
51
52public:
53 RPLight(LightType light_type);
54 virtual ~RPLight();
55
56 virtual void init_shadow_sources() = 0;
57 virtual void update_shadow_sources() = 0;
58 virtual void write_to_command(GPUCommand &cmd);
59
60 inline size_t get_num_shadow_sources() const;
61 inline ShadowSource* get_shadow_source(size_t index) const;
62 inline void clear_shadow_sources();
63
64 inline void set_needs_update(bool flag);
65 inline bool get_needs_update() const;
66
67 inline bool has_slot() const;
68 inline int get_slot() const;
69 inline void remove_slot();
70 inline void assign_slot(int slot);
71
72PUBLISHED:
73 inline void invalidate_shadows();
74
75 inline void set_pos(const LVecBase3 &pos);
76 inline void set_pos(float x, float y, float z);
77 inline const LVecBase3& get_pos() const;
78 MAKE_PROPERTY(pos, get_pos, set_pos);
79
80 inline void set_color(const LVecBase3 &color);
81 inline void set_color(float r, float g, float b);
82 inline const LVecBase3& get_color() const;
83 MAKE_PROPERTY(color, get_color, set_color);
84
85 void set_color_from_temperature(float temperature);
86
87 inline void set_energy(float energy);
88 inline float get_energy() const;
89 MAKE_PROPERTY(energy, get_energy, set_energy);
90
91 inline LightType get_light_type() const;
92 MAKE_PROPERTY(light_type, get_light_type);
93
94 inline void set_casts_shadows(bool flag = true);
95 inline bool get_casts_shadows() const;
96 MAKE_PROPERTY(casts_shadows, get_casts_shadows, set_casts_shadows);
97
98 inline void set_shadow_map_resolution(size_t resolution);
99 inline size_t get_shadow_map_resolution() const;
100 MAKE_PROPERTY(shadow_map_resolution, get_shadow_map_resolution, set_shadow_map_resolution);
101
102 inline void set_ies_profile(int profile);
103 inline int get_ies_profile() const;
104 inline bool has_ies_profile() const;
105 inline void clear_ies_profile();
106 MAKE_PROPERTY2(ies_profile, has_ies_profile, get_ies_profile,
108
109 inline void set_near_plane(float near_plane);
110 inline float get_near_plane() const;
111 MAKE_PROPERTY(near_plane, get_near_plane, set_near_plane);
112
113protected:
114 int _slot;
115 int _ies_profile;
116 size_t _source_resolution;
117 bool _needs_update;
118 bool _casts_shadows;
119 LVecBase3 _position;
120 LVecBase3 _color;
121 float _energy;
122 LightType _light_type;
123 float _near_plane;
124
125 std::vector<ShadowSource*> _shadow_sources;
126};
127
128#include "rpLight.I"
129
130#endif // RP_LIGHT_H
Class for storing data to be transferred to the GPU.
Definition gpuCommand.h:47
RenderPipeline.
Definition rpLight.h:41
get_casts_shadows
Returns whether the light casts shadows.
Definition rpLight.h:96
get_energy
Returns the energy of the light.
Definition rpLight.h:89
void clear_shadow_sources()
Clears all shadow source.
Definition rpLight.I:60
ShadowSource * get_shadow_source(size_t index) const
Returns the n-th shadow source.
Definition rpLight.I:49
bool has_slot() const
Returns whether the light has a slot.
Definition rpLight.I:106
RPLight(LightType light_type)
RenderPipeline.
Definition rpLight.cxx:38
set_near_plane
Sets the near plane of the light.
Definition rpLight.h:111
clear_ies_profile
Clears the IES profile.
Definition rpLight.h:107
get_light_type
Returns the type of the light.
Definition rpLight.h:92
virtual void write_to_command(GPUCommand &cmd)
Writes the light to a GPUCommand.
Definition rpLight.cxx:60
set_ies_profile
Sets the IES profile.
Definition rpLight.h:107
void assign_slot(int slot)
Assigns a slot to the light.
Definition rpLight.I:140
get_color
Returns the lights color.
Definition rpLight.h:83
size_t get_num_shadow_sources() const
RenderPipeline.
Definition rpLight.I:36
void invalidate_shadows()
Invalidates the shadows.
Definition rpLight.I:153
set_pos
Sets the position of the light.
Definition rpLight.h:78
get_shadow_map_resolution
Returns the shadow map resolution.
Definition rpLight.h:100
int get_slot() const
Returns the slot of the light.
Definition rpLight.I:118
get_near_plane
Returns the near plane of the light.
Definition rpLight.h:111
set_shadow_map_resolution
Sets the light's shadow map resolution.
Definition rpLight.h:100
get_pos
Returns the position of the light.
Definition rpLight.h:78
set_color
Sets the lights color.
Definition rpLight.h:83
void set_color_from_temperature(float temperature)
Sets the lights color from a given color temperature.
Definition rpLight.cxx:103
get_ies_profile
Returns the light's IES profile.
Definition rpLight.h:107
has_ies_profile
Returns whether the light has an IES profile assigned.
Definition rpLight.h:107
set_energy
Sets the energy of the light.
Definition rpLight.h:89
set_casts_shadows
Controls whether the light casts shadows.
Definition rpLight.h:96
void remove_slot()
Removes the light slot.
Definition rpLight.I:128
LightType
Different types of light.
Definition rpLight.h:46
virtual ~RPLight()
Light destructor.
Definition rpLight.cxx:90
void set_needs_update(bool flag)
Sets whether the light needs an update.
Definition rpLight.I:80
bool get_needs_update() const
Returns whether the light needs an update.
Definition rpLight.I:94
A base class for all things that want to be reference-counted.
RenderPipeline.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.