11 #ifndef hifi_model_Light_h
12 #define hifi_model_Light_h
17 #include <glm/glm.hpp>
18 #include "Transform.h"
19 #include "gpu/Resource.h"
20 #include "gpu/Texture.h"
23 typedef gpu::BufferView UniformBufferView;
24 typedef gpu::TextureView TextureView;
25 typedef glm::vec3
Vec3;
26 typedef glm::vec4 Vec4;
27 typedef glm::quat
Quat;
34 vec3 position { 0.f };
35 float radius { 1.0f };
36 vec3 direction { 0.f, 0.f, -1.f };
37 float spotCos { -1.f };
39 bool isPoint()
const {
return bool(spotCos < 0.f); }
40 bool isSpot()
const {
return bool(spotCos >= 0.f); }
42 vec3 getPosition()
const {
return position; }
43 float getRadius()
const {
return radius; }
44 float getRadiusSquare()
const {
return radius * radius; }
45 vec3 getDirection()
const {
return direction; }
47 float getSpotAngleCos()
const {
return spotCos; }
48 vec2 getSpotAngleCosSin()
const {
return vec2(spotCos, sqrt(1.f - spotCos * spotCos)); }
52 struct LightIrradiance {
54 float intensity { 1.f };
55 float falloffRadius { 0.1f };
56 float cutoffRadius { 0.1f };
57 float falloffSpot { 1.f };
60 vec3 getColor()
const {
return color; }
61 float getIntensity()
const {
return intensity; }
62 vec3 getIrradiance()
const {
return color * intensity; }
63 float getFalloffRadius()
const {
return falloffRadius; }
64 float getCutoffRadius()
const {
return cutoffRadius; }
65 float getFalloffSpot()
const {
return falloffSpot; }
90 typedef std::bitset<NUM_FLAGS> Flags;
93 Light(
const Light& light);
94 Light& operator= (
const Light& light);
97 void setType(Type type);
98 Type getType()
const {
return _type; }
100 void setPosition(
const Vec3& position);
101 const Vec3& getPosition()
const {
return _transform.getTranslation(); }
103 void setDirection(
const Vec3& direction);
104 const Vec3& getDirection()
const;
106 void setCastShadows(
const bool castShadows);
107 bool getCastShadows()
const;
109 void setShadowsMaxDistance(
const float maxDistance);
110 float getShadowsMaxDistance()
const;
112 void setShadowBias(
float bias);
113 float getShadowBias()
const;
115 void setOrientation(
const Quat& orientation);
116 const glm::quat& getOrientation()
const {
return _transform.getRotation(); }
118 const Color& getColor()
const {
return _lightSchemaBuffer->irradiance.color; }
119 void setColor(
const Color& color);
121 float getIntensity()
const {
return _lightSchemaBuffer->irradiance.intensity; }
122 void setIntensity(
float intensity);
124 bool isRanged()
const {
return (getType() == POINT) || (getType() == SPOT); }
129 void setFalloffRadius(
float radius);
130 float getFalloffRadius()
const {
return _lightSchemaBuffer->irradiance.falloffRadius; }
135 void setMaximumRadius(
float radius);
136 float getMaximumRadius()
const {
return _lightSchemaBuffer->volume.radius; }
139 bool isSpot()
const {
return getType() == SPOT; }
140 void setSpotAngle(
float angle);
141 float getSpotAngle()
const {
return acos(_lightSchemaBuffer->volume.getSpotAngleCos()); }
142 glm::vec2 getSpotAngleCosSin()
const {
return _lightSchemaBuffer->volume.getSpotAngleCosSin(); }
143 void setSpotExponent(
float exponent);
144 float getSpotExponent()
const {
return _lightSchemaBuffer->irradiance.falloffSpot; }
147 void setAmbientIntensity(
float intensity);
148 float getAmbientIntensity()
const {
return _ambientSchemaBuffer->intensity; }
151 void setAmbientSphere(
const gpu::SphericalHarmonics& sphere);
152 const gpu::SphericalHarmonics& getAmbientSphere()
const {
return _ambientSchemaBuffer->ambientSphere; }
153 void setAmbientSpherePreset(gpu::SphericalHarmonics::Preset preset);
155 void setAmbientMap(
const gpu::TexturePointer& ambientMap);
156 gpu::TexturePointer getAmbientMap()
const {
return _ambientMap; }
158 void setAmbientMapNumMips(uint16_t numMips);
159 uint16_t getAmbientMapNumMips()
const {
return (uint16_t) _ambientSchemaBuffer->mapNumMips; }
161 void setTransform(
const glm::mat4& transform);
167 LightIrradiance irradiance;
170 class AmbientSchema {
172 float intensity { 0.0f };
173 float mapNumMips { 0.0f };
177 gpu::SphericalHarmonics ambientSphere;
181 using LightSchemaBuffer = gpu::StructBuffer<LightSchema>;
182 using AmbientSchemaBuffer = gpu::StructBuffer<AmbientSchema>;
184 const LightSchemaBuffer& getLightSchemaBuffer()
const {
return _lightSchemaBuffer; }
185 const AmbientSchemaBuffer& getAmbientSchemaBuffer()
const {
return _ambientSchemaBuffer; }
191 LightSchemaBuffer _lightSchemaBuffer;
192 AmbientSchemaBuffer _ambientSchemaBuffer;
194 Transform _transform;
196 gpu::TexturePointer _ambientMap;
199 float _spotCos { -1.0f };
201 float _shadowsMaxDistance { 40.0f };
202 float _shadowBias { 0.5f };
203 bool _castShadows{
false };
205 void updateLightRadius();
207 typedef std::shared_ptr< Light > LightPointer;
Provides the Quat scripting interface.
Definition: Quat.h:61
Provides the Vec3 scripting interface.
Definition: Vec3.h:80