NAP
spotlightcomponent.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // Local includes
8 #include "lightcomponent.h"
9 
10 // External includes
11 #include <perspcameracomponent.h>
12 #include <renderfrustumcomponent.h>
13 #include <rendergnomoncomponent.h>
14 
15 namespace nap
16 {
17  // Forward declares
18  class SpotLightComponentInstance;
19  class SceneService;
20 
29  class NAPAPI SpotLightComponent : public LightComponent
30  {
31  RTTI_ENABLE(LightComponent)
33  public:
34  float mAttenuation = 0.1f;
35  float mAngle = 90.0f;
36  float mFOVClip = 1.0f;
37  float mFalloff = 0.5f;
38  glm::vec2 mClippingPlanes = { 1.0f, 1000.0f };
39  uint mShadowMapSize = 1024;
40  };
41 
42 
52  {
53  RTTI_ENABLE(LightComponentInstance)
54  public:
56  LightComponentInstance(entity, resource) { }
57 
63  virtual bool init(utility::ErrorState& errorState) override;
64 
68  virtual ELightType getLightType() const override { return ELightType::Spot; }
69 
73  virtual EShadowMapType getShadowMapType() const override { return EShadowMapType::Quad; }
74 
79  float getAttenuation() const { return mAttenuation; }
80 
85  void setAttenuation(float attenuation) { mAttenuation = attenuation; }
86 
91  float getAngle() const { return mAngle; }
92 
97  void setAngle(float angle);
98 
103  float getFOVClip() const { return mFOVClip; }
104 
109  void setFOVClip(float clip);
110 
115  float getFalloff() const { return mFalloff; }
116 
122  void setFalloff(float falloff) { mFalloff = falloff; }
123 
124  float mAttenuation = 0.1f;
125  float mAngle = 90.0f;
126  float mFOVClip = 1.0f;
127  float mFalloff = 0.5f;
128 
129  private:
130  // Shadow camera entity resource
131  std::unique_ptr<Entity> mShadowCamEntity = nullptr;
132  std::unique_ptr<PerspCameraComponent> mShadowCamComponent = nullptr;
133  std::unique_ptr<RenderFrustumComponent> mShadowFrustrumComponent = nullptr;
134  std::unique_ptr<RenderGnomonComponent> mShadowOriginComponent = nullptr;
135  std::unique_ptr<TransformComponent> mShadowCamXformComponent = nullptr;
136  std::unique_ptr<GnomonMesh> mGnomonMesh = nullptr;
137  };
138 }
nap::uint
unsigned int uint
Definition: numeric.h:23
nap::LightComponentInstance
Definition: lightcomponent.h:209
nap::SpotLightComponentInstance::getShadowMapType
virtual EShadowMapType getShadowMapType() const override
Definition: spotlightcomponent.h:73
nap::SpotLightComponent
Definition: spotlightcomponent.h:29
nap::LightComponent
Definition: lightcomponent.h:134
nap::SpotLightComponentInstance::setFalloff
void setFalloff(float falloff)
Definition: spotlightcomponent.h:122
nap::SpotLightComponentInstance::getFOVClip
float getFOVClip() const
Definition: spotlightcomponent.h:103
nap::utility::ErrorState
Definition: errorstate.h:19
nap::EShadowMapType
EShadowMapType
Definition: lightcomponent.h:36
nap::SpotLightComponentInstance::getLightType
virtual ELightType getLightType() const override
Definition: spotlightcomponent.h:68
nap::SpotLightComponentInstance::getFalloff
float getFalloff() const
Definition: spotlightcomponent.h:115
nap::EntityInstance
Definition: entity.h:34
nap::Component
Definition: component.h:151
nap::ELightType
ELightType
Definition: lightcomponent.h:25
nap::SpotLightComponentInstance::getAttenuation
float getAttenuation() const
Definition: spotlightcomponent.h:79
nap::ELightType::Spot
@ Spot
nap
Definition: templateapp.h:17
nap::SpotLightComponentInstance::setAttenuation
void setAttenuation(float attenuation)
Definition: spotlightcomponent.h:85
nap::SpotLightComponentInstance::getAngle
float getAngle() const
Definition: spotlightcomponent.h:91
nap::SpotLightComponentInstance
Definition: spotlightcomponent.h:51
nap::EShadowMapType::Quad
@ Quad
nap::SpotLightComponentInstance::SpotLightComponentInstance
SpotLightComponentInstance(EntityInstance &entity, Component &resource)
Definition: spotlightcomponent.h:55