Cogs.Core
LightComponent.h
1#pragma once
2
3#include "../../EntityPtr.h"
4
5#include "Foundation/Geometry/Glm.hpp"
6
7namespace Cogs
8{
9 namespace Core
10 {
14 enum class LightType
15 {
28 Point,
35 Spot,
36 };
37
38 enum class LightingLayers : uint32_t
39 {
40 None = 0,
41 Default = 1 << 0,
42 All = 0xFFFFFFFFu
43 };
44
45 ENABLE_ENUM_FLAGS(LightingLayers);
46
47 enum class ShadowUpdate
48 {
49 Default = 0,
50 Dynamic = 1,
51 Partial = 2,
52 Static = 3,
53 StaticPartial = 4,
54 None = 5,
55 };
56
57 enum class SoftShadows
58 {
59 None = 0,
60 Low,
61 High,
62 Default = High
63 };
64
69 {
70 public:
72 static void registerType();
73
75 glm::vec4 lightColor = glm::vec4(1, 1, 1, 1);
76
83
87 LightingLayers lightingLayer = LightingLayers::Default;
88
90 float intensity = 1;
91
93 float range = 1000.0f;
94
96 float shadowNearPlane = 0.0f;
97
99 bool enabled = true;
100
102 bool mainLight = false;
103
105 bool castShadows = false;
106
108 bool tightShadowBounds = false;
109
112
115
117 float shadowSampleBias = 0.004f;
118
120 float shadowBias = 2.f;
121
123 float shadowSlopedBias = 5.f;
124
126 float shadowBiasClamp = 4.f;
127
130
133
135 std::vector<WeakEntityPtr> cameras;
136
137 size_t hash(size_t hashValue = Cogs::hash()) const {
138 hashValue = Component::hash(hashValue);
139
140 hashValue = Cogs::hash(lightColor, hashValue);
141 hashValue = Cogs::hash(lightType, hashValue);
142 hashValue = Cogs::hash(lightingLayer, hashValue);
143 hashValue = Cogs::hash(intensity, hashValue);
144 hashValue = Cogs::hash(range, hashValue);
145 hashValue = Cogs::hash(shadowNearPlane, hashValue);
146 hashValue = Cogs::hash(enabled, hashValue);
147 hashValue = Cogs::hash(mainLight, hashValue);
148 hashValue = Cogs::hash(castShadows, hashValue);
149 hashValue = Cogs::hash(tightShadowBounds, hashValue);
150 hashValue = Cogs::hash(dynamicCascadeCount, hashValue);
151 hashValue = Cogs::hash(shadowIntensityOffset, hashValue);
152 hashValue = Cogs::hash(shadowSampleBias, hashValue);
153 hashValue = Cogs::hash(shadowBias, hashValue);
154 hashValue = Cogs::hash(shadowSlopedBias, hashValue);
155 hashValue = Cogs::hash(shadowBiasClamp, hashValue);
156 hashValue = Cogs::hash(_shadowNormalOffsetBias, hashValue);
157
158 return hashValue;
159 }
160 };
161 }
162}
163
164template<> inline Cogs::StringView getName<Cogs::Core::LightComponent>() { return "LightComponent"; }
165
166template<> inline Cogs::StringView getName<Cogs::Core::LightType>() { return "LightType"; }
167template<> inline Cogs::StringView getName<Cogs::Core::LightingLayers>() { return "LightingLayers"; }
168template<> inline Cogs::StringView getName<Cogs::Core::ShadowUpdate>() { return "ShadowUpdate"; }
169template<> inline Cogs::StringView getName<Cogs::Core::SoftShadows>() { return "SoftShadows"; }
Base class for Component instances.
Definition: Component.h:143
Defines a single light source and its behavior.
LightType lightType
The type of light.
float shadowBias
Constant term shadow map rasterization bias.
bool mainLight
If this light is the main light of the application.
bool castShadows
If this light should cast shadows.
bool enabled
If the light is enabled.
float shadowBiasClamp
Shadow map bias rasterization clamp.
static void registerType()
Register the type in the type system.
float intensity
Intensity of the light source.
float shadowNearPlane
Shadow near plane. If set to 0 near plane is 1/1000th of the radius.
float shadowSampleBias
Constant term shadow map sampling bias.
std::vector< WeakEntityPtr > cameras
Cameras from which the shadow maps will be used, defaults to main camera.
WeakEntityPtr lodReference
Camera entity of which its z-axis define the shadowmap cascade split axis, defaults to main camera.
float shadowSlopedBias
Linear term of shadow map rasterization bias.
float shadowIntensityOffset
Shadow intensity offset.
bool tightShadowBounds
If the shadows should have tight bounds.
glm::vec4 lightColor
Color contribution of the light.
bool dynamicCascadeCount
Dynamically determine how many cascades should be drawn.
LightingLayers lightingLayer
The lighting layer the light belongs to.
float _shadowNormalOffsetBias
Shadow normal bias.
float range
Falloff range.
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
std::weak_ptr< ComponentModel::Entity > WeakEntityPtr
Weak Smart pointer for Entity access.
Definition: EntityPtr.h:18
LightType
Defines light types.
@ Point
Point light source.
@ Spot
Spot light source.
@ Directional
Directional light.
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
constexpr size_t hash() noexcept
Simple getter function that returns the initial value for fnv1a hashing.
Definition: HashFunctions.h:62