13 #ifndef hifi_render_utils_LightStage_h
14 #define hifi_render_utils_LightStage_h
16 #include <gpu/Framebuffer.h>
17 #include <graphics/Light.h>
18 #include <render/Stage.h>
19 #include <render/StageSetup.h>
27 using Index = render::indexed_container::Index;
29 void clear() { _pointLights.clear(); _spotLights.clear(); _sunLights.clear(); _ambientLights.clear(); }
30 void pushLight(Index index, graphics::Light::Type type) {
32 case graphics::Light::POINT: { pushPointLight(index);
break; }
33 case graphics::Light::SPOT: { pushSpotLight(index);
break; }
34 case graphics::Light::SUN: { pushSunLight(index);
break; }
35 case graphics::Light::AMBIENT: { pushAmbientLight(index);
break; }
39 void pushPointLight(Index index) { _pointLights.emplace_back(index); }
40 void pushSpotLight(Index index) { _spotLights.emplace_back(index); }
41 void pushSunLight(Index index) { _sunLights.emplace_back(index); }
42 void pushAmbientLight(Index index) { _ambientLights.emplace_back(index); }
44 render::ElementIndices _pointLights;
45 render::ElementIndices _spotLights;
46 render::ElementIndices _sunLights;
47 render::ElementIndices _ambientLights;
51 class LightStage :
public render::PointerStage<graphics::Light, graphics::LightPointer, LightFrame> {
53 using LightPointer = graphics::LightPointer;
57 using UniformBufferView = gpu::BufferView;
58 static const int MAP_SIZE;
66 gpu::FramebufferPointer framebuffer;
68 const std::shared_ptr<ViewFrustum>& getFrustum()
const {
return _frustum; }
70 const glm::mat4& getView()
const;
71 const glm::mat4& getProjection()
const;
73 void setMinDistance(
float value) { _minDistance = value; }
74 void setMaxDistance(
float value) { _maxDistance = value; }
75 float getMinDistance()
const {
return _minDistance; }
76 float getMaxDistance()
const {
return _maxDistance; }
80 std::shared_ptr<ViewFrustum> _frustum;
84 float computeFarDistance(
const ViewFrustum& viewFrustum,
const Transform& shadowViewInverse,
85 float left,
float right,
float bottom,
float top,
float viewMaxShadowDistance)
const;
88 Shadow(LightPointer light,
unsigned int cascadeCount = 1);
90 void setLight(LightPointer light);
92 void setKeylightFrustum(
const ViewFrustum& viewFrustum,
93 float nearDepth = 1.0f,
float farDepth = 1000.0f);
94 void setKeylightCascadeFrustum(
unsigned int cascadeIndex,
const ViewFrustum& viewFrustum,
95 float nearDepth = 1.0f,
float farDepth = 1000.0f);
96 void setKeylightCascadeBias(
unsigned int cascadeIndex,
float constantBias,
float slopeBias);
97 void setCascadeFrustum(
unsigned int cascadeIndex,
const ViewFrustum& shadowFrustum);
99 const UniformBufferView& getBuffer()
const {
return _schemaBuffer; }
101 unsigned int getCascadeCount()
const {
return (
unsigned int)_cascades.size(); }
102 const Cascade& getCascade(
unsigned int index)
const {
return _cascades[index]; }
104 float getMaxDistance()
const {
return _maxDistance; }
105 void setMaxDistance(
float value);
107 const LightPointer& getLight()
const {
return _light; }
109 gpu::TexturePointer map;
110 #include "Shadows_shared.slh"
111 class Schema :
public ShadowParameters {
118 using Cascades = std::vector<Cascade>;
120 static const glm::mat4 _biasMatrix;
123 float _maxDistance{ 0.0f };
126 UniformBufferView _schemaBuffer =
nullptr;
128 using ShadowPointer = std::shared_ptr<Shadow>;
130 Index addElement(
const LightPointer& light)
override {
return addElement(light,
false); }
131 Index addElement(
const LightPointer& light,
const bool shouldSetAsDefault);
132 LightPointer removeElement(Index index)
override;
134 Index getDefaultLight() {
return _defaultLightId; }
138 gpu::BufferPointer getLightArrayBuffer()
const {
return _lightArrayBuffer; }
139 void updateLightArrayBuffer(Index lightId);
147 using Object = ShadowPointer;
148 using Objects = std::vector<Object>;
150 void pushShadow(
const ShadowPointer& shadow) {
151 _objects.emplace_back(shadow);
156 using ShadowFramePointer = std::shared_ptr<ShadowFrame>;
158 Index getAmbientOffLight() {
return _ambientOffLightId; }
159 Index getPointOffLight() {
return _pointOffLightId; }
160 Index getSpotOffLight() {
return _spotOffLightId; }
161 Index getSunOffLight() {
return _sunOffLightId; }
163 LightPointer getCurrentKeyLight(
const LightFrame& frame)
const;
164 LightPointer getCurrentAmbientLight(
const LightFrame& frame)
const;
169 Index shadowId{ INVALID_INDEX };
171 using Descs = std::vector<Desc>;
173 gpu::BufferPointer _lightArrayBuffer;
178 Index _ambientOffLightId;
179 Index _pointOffLightId;
180 Index _spotOffLightId;
181 Index _sunOffLightId;
183 Index _defaultLightId;
186 using LightStagePointer = std::shared_ptr<LightStage>;
188 class LightStageSetup :
public render::StageSetup<LightStage> {
190 using JobModel = render::Job::Model<LightStageSetup>;