Nebula
Loading...
Searching...
No Matches
csmutil.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
11#include "core/refcounted.h"
12#include "math/frustum.h"
13#include "math/mat4.h"
15
16#ifndef FLT_MAX
17#define FLT_MAX 3.402823466e+38F
18#endif
19
20#ifndef FLT_MIN
21#define FLT_MIN 1.175494351e-38F
22#endif
23
24//------------------------------------------------------------------------------
25namespace Lighting
26{
28{
29public:
30
34 virtual ~CSMUtil();
35
41 void SetShadowBox(const Math::bbox& sceneBox);
47 void SetTextureWidth(int width);
49 void SetBlurSize(int size);
51 void SetFitTexels(bool state);
52
54 const Math::mat4& GetCascadeViewProjection(IndexT cascadeIndex) const;
56 const Math::mat4& GetShadowView() const;
61
63 const Math::mat4& GetCascadeCamera(IndexT index) const;
64
67
68private:
69
71 {
72 float rightSlope; // positive X-slope (X/Z)
73 float leftSlope; // negative X-slope
74 float topSlope; // positive Y-slope (Y/Z)
75 float bottomSlope; // negative Y-slope
76 float nearPlane, farPlane; // Z of near and far plane
77 };
78
79
84
90
91};
92
93//------------------------------------------------------------------------------
96inline void
97CSMUtil::SetShadowBox( const Math::bbox& shadowRange )
98{
99 this->shadowBox = shadowRange;
100}
101
102//------------------------------------------------------------------------------
105inline void
107{
108 this->cameraEntity = camera;
109}
110
111//------------------------------------------------------------------------------
116{
117 return this->cameraEntity;
118}
119
120//------------------------------------------------------------------------------
123inline void
125{
126 this->globalLight = globalLight;
127}
128
129//------------------------------------------------------------------------------
134{
135 return this->globalLight;
136}
137
138//------------------------------------------------------------------------------
141inline const Math::mat4&
143{
144 return this->cascadeViewProjectionTransform[cascadeIndex];
145}
146
147//------------------------------------------------------------------------------
150inline const Math::mat4&
152{
153 return this->shadowView;
154}
155
156//------------------------------------------------------------------------------
164
165//------------------------------------------------------------------------------
168inline const Util::FixedArray<float>&
170{
171 return this->intervalDistances;
172}
173
174} // namespace Lighting
175//------------------------------------------------------------------------------
Helper class for creating and rendering Cascading Shadow Maps.
Definition csmutil.h:28
const Math::mat4 & GetShadowView() const
gets the shadow view transform (valid after Compute)
Definition csmutil.h:151
Math::vec4 frustumCenter
Definition csmutil.h:81
Util::FixedArray< float > intervalDistances
Definition csmutil.h:87
Util::FixedArray< float > cascadeDistances
Definition csmutil.h:87
void SetBlurSize(int size)
sets the CSM blur size
void SetGlobalLight(const Graphics::GraphicsEntityId globalLight)
sets the global light entity
Definition csmutil.h:124
uint numCascades
Definition csmutil.h:85
const Graphics::GraphicsEntityId GetCameraEntity() const
get the camera entity
Definition csmutil.h:115
Graphics::GraphicsEntityId cameraEntity
Definition csmutil.h:83
Math::mat4 shadowView
Definition csmutil.h:88
Util::FixedArray< Math::mat4 > cascadeViewProjectionTransform
Definition csmutil.h:86
Util::FixedArray< Math::mat4 > cascadeProjectionTransform
Definition csmutil.h:86
const Graphics::GraphicsEntityId GetGlobalLight() const
gets the global light entity
Definition csmutil.h:133
Math::bbox shadowBox
Definition csmutil.h:80
virtual ~CSMUtil()
destructor
Definition csmutil.cc:40
const Util::FixedArray< Math::mat4 > & GetCascadeProjectionTransforms() const
returns raw pointer to array of cascade transforms
Definition csmutil.h:160
const Util::FixedArray< float > & GetCascadeDistances() const
returns raw pointer to array of cascade distances
Definition csmutil.h:169
void Compute(const Graphics::GraphicsEntityId camera, const Graphics::GraphicsEntityId light)
computes the splits
Definition csmutil.cc:100
void SetCameraEntity(const Graphics::GraphicsEntityId camera)
sets the camera entity
Definition csmutil.h:106
const Math::mat4 & GetCascadeViewProjection(IndexT cascadeIndex) const
gets computed view projection transform (valid after Compute)
Definition csmutil.h:142
CSMUtil(const uint numCascades)
constructor
Definition csmutil.cc:23
float cascadeMaxDistance
Definition csmutil.h:89
void SetShadowBox(const Math::bbox &sceneBox)
sets the scene bounding box
Definition csmutil.h:97
void SetFitTexels(bool state)
sets whether or not the CSM should clamp the cascades to fit the size of the texels
const Math::mat4 & GetCascadeCamera(IndexT index) const
gets cascade debug camera (only valid after Compute, and if the debug flag is set)
Graphics::GraphicsEntityId globalLight
Definition csmutil.h:82
void SetTextureWidth(int width)
sets the texture width for the CSM texture buffer
Nebula's bounding box class.
Definition bbox.h:24
Implements a fixed size one-dimensional array.
Definition fixedarray.h:20
The lighting subsystem allows for attaching light source functionality to a GraphicsEntityId.
Definition csmutil.cc:19
The graphics entity is only an Id, to which we can attach GraphicsContexts.
Definition graphicsentity.h:16
Definition csmutil.h:71
float rightSlope
Definition csmutil.h:72
float topSlope
Definition csmutil.h:74
float bottomSlope
Definition csmutil.h:75
float leftSlope
Definition csmutil.h:73
float nearPlane
Definition csmutil.h:76
float farPlane
Definition csmutil.h:76
A 4x4 single point precision float matrix.
Definition mat4.h:49
A 4D vector.
Definition vec4.h:24
unsigned int uint
Definition types.h:31
int IndexT
Definition types.h:48