12 #ifndef hifi_model_Light_h
13 #define hifi_model_Light_h
18 #include <glm/glm.hpp>
19 #include "Transform.h"
20 #include "gpu/Resource.h"
21 #include "gpu/Texture.h"
24 typedef gpu::BufferView UniformBufferView;
25 typedef gpu::TextureView TextureView;
26 typedef glm::vec3
Vec3;
27 typedef glm::vec4 Vec4;
28 typedef glm::quat
Quat;
35 vec3 position { 0.f };
36 float radius { 1.0f };
37 vec3 direction { 0.f, 0.f, -1.f };
38 float spotCos { -1.f };
40 bool isPoint()
const {
return bool(spotCos < 0.f); }
41 bool isSpot()
const {
return bool(spotCos >= 0.f); }
43 vec3 getPosition()
const {
return position; }
44 float getRadius()
const {
return radius; }
45 float getRadiusSquare()
const {
return radius * radius; }
46 vec3 getDirection()
const {
return direction; }
48 float getSpotAngleCos()
const {
return spotCos; }
49 vec2 getSpotAngleCosSin()
const {
return vec2(spotCos, sqrt(1.f - spotCos * spotCos)); }
53 struct LightIrradiance {
55 float intensity { 1.f };
56 float falloffRadius { 0.1f };
57 float cutoffRadius { 0.1f };
58 float falloffSpot { 1.f };
61 vec3 getColor()
const {
return color; }
62 float getIntensity()
const {
return intensity; }
63 vec3 getIrradiance()
const {
return color * intensity; }
64 float getFalloffRadius()
const {
return falloffRadius; }
65 float getCutoffRadius()
const {
return cutoffRadius; }
66 float getFalloffSpot()
const {
return falloffSpot; }
91 typedef std::bitset<NUM_FLAGS> Flags;
94 Light(
const Light& light);
95 Light& operator= (
const Light& light);
98 void setType(Type type);
99 Type getType()
const {
return _type; }
101 void setPosition(
const Vec3& position);
102 const Vec3& getPosition()
const {
return _transform.getTranslation(); }
104 void setDirection(
const Vec3& direction);
105 const Vec3& getDirection()
const;
107 void setCastShadows(
const bool castShadows);
108 bool getCastShadows()
const;
110 void setShadowsMaxDistance(
const float maxDistance);
111 float getShadowsMaxDistance()
const;
113 void setShadowBias(
float bias);
114 float getShadowBias()
const;
116 void setOrientation(
const Quat& orientation);
117 const glm::quat& getOrientation()
const {
return _transform.getRotation(); }
119 const Color& getColor()
const {
return _lightSchemaBuffer->irradiance.color; }
120 void setColor(
const Color& color);
122 float getIntensity()
const {
return _lightSchemaBuffer->irradiance.intensity; }
123 void setIntensity(
float intensity);
125 bool isRanged()
const {
return (getType() == POINT) || (getType() == SPOT); }
130 void setFalloffRadius(
float radius);
131 float getFalloffRadius()
const {
return _lightSchemaBuffer->irradiance.falloffRadius; }
136 void setMaximumRadius(
float radius);
137 float getMaximumRadius()
const {
return _lightSchemaBuffer->volume.radius; }
140 bool isSpot()
const {
return getType() == SPOT; }
141 void setSpotAngle(
float angle);
142 float getSpotAngle()
const {
return acos(_lightSchemaBuffer->volume.getSpotAngleCos()); }
143 glm::vec2 getSpotAngleCosSin()
const {
return _lightSchemaBuffer->volume.getSpotAngleCosSin(); }
144 void setSpotExponent(
float exponent);
145 float getSpotExponent()
const {
return _lightSchemaBuffer->irradiance.falloffSpot; }
148 void setAmbientColor(vec3 color);
149 vec3 getAmbientColor()
const {
return _ambientSchemaBuffer->color; }
150 void setAmbientIntensity(
float intensity);
151 float getAmbientIntensity()
const {
return _ambientSchemaBuffer->intensity; }
154 void setAmbientSphere(
const gpu::SphericalHarmonics& sphere);
155 const gpu::SphericalHarmonics& getAmbientSphere()
const {
return _ambientSchemaBuffer->ambientSphere; }
156 void setAmbientSpherePreset(gpu::SphericalHarmonics::Preset preset);
158 void setAmbientMap(
const gpu::TexturePointer& ambientMap);
159 gpu::TexturePointer getAmbientMap()
const {
return _ambientMap; }
161 void setAmbientMapNumMips(uint16_t numMips);
162 uint16_t getAmbientMapNumMips()
const {
return (uint16_t) _ambientSchemaBuffer->mapNumMips; }
164 void setTransform(
const glm::mat4& transform);
170 LightIrradiance irradiance;
173 class AmbientSchema {
176 float blend { 0.0f };
178 float intensity { 0.0f };
179 float mapNumMips { 0.0f };
183 gpu::SphericalHarmonics ambientSphere;
187 using LightSchemaBuffer = gpu::StructBuffer<LightSchema>;
188 using AmbientSchemaBuffer = gpu::StructBuffer<AmbientSchema>;
190 const LightSchemaBuffer& getLightSchemaBuffer()
const {
return _lightSchemaBuffer; }
191 const AmbientSchemaBuffer& getAmbientSchemaBuffer();
197 LightSchemaBuffer _lightSchemaBuffer;
198 AmbientSchemaBuffer _ambientSchemaBuffer;
200 Transform _transform;
202 gpu::TexturePointer _ambientMap;
205 float _spotCos { -1.0f };
207 float _shadowsMaxDistance { 40.0f };
208 float _shadowBias { 0.5f };
209 bool _castShadows{
false };
211 void updateLightRadius();
213 typedef std::shared_ptr< Light > LightPointer;
Provides the Quat scripting interface.
Definition: Quat.h:61
Provides the Vec3 scripting interface.
Definition: Vec3.h:80