From 19e318c3f0291a222f8980a2c61c033393c2abe6 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Wed, 10 Feb 2016 15:56:58 -0800 Subject: [PATCH 01/15] Enforce maximum radius for lights Light attenuation is based on the intensity, in that intensity is used to calculate a light's surface area. Lights of sufficiently low intensities generated either incredibly large or negative surface areas, causing them to appear much brighter than similar lights of greater intensity. This enforces an already present maximum. --- libraries/model/src/model/Light.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libraries/model/src/model/Light.cpp b/libraries/model/src/model/Light.cpp index 917e3bed7e..ef0757f3c6 100755 --- a/libraries/model/src/model/Light.cpp +++ b/libraries/model/src/model/Light.cpp @@ -79,9 +79,12 @@ void Light::setMaximumRadius(float radius) { } void Light::updateLightRadius() { - float CutOffIntensityRatio = 0.05f; - float surfaceRadius = getMaximumRadius() / (sqrtf((getIntensity() * std::max(std::max(getColor().x, getColor().y), getColor().z)) / CutOffIntensityRatio) - 1.0f); - editSchema()._attenuation = Vec4(surfaceRadius, 1.0f/surfaceRadius, CutOffIntensityRatio, getMaximumRadius()); + const float CUTOFF_INTENSITY_RATIO = 0.05f; + float intensity = getIntensity() * std::max(std::max(getColor().x, getColor().y), getColor().z); + float denom = sqrtf(intensity / CUTOFF_INTENSITY_RATIO) - 1.0f; + float surfaceRadius = getMaximumRadius() / std::max(denom, 1.0f); + + editSchema()._attenuation = Vec4(surfaceRadius, 1.0f/surfaceRadius, CUTOFF_INTENSITY_RATIO, getMaximumRadius()); } #include From 399861087d7cfca38df29bd0cadcb4fa76cd99d9 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Wed, 10 Feb 2016 19:50:31 -0800 Subject: [PATCH 02/15] Reimplement lighting model --- libraries/model/src/model/Light.cpp | 32 ++++++++++++++----- libraries/model/src/model/Light.h | 14 +++++++-- libraries/model/src/model/Light.slh | 36 +++++++++++++--------- libraries/render-utils/src/point_light.slf | 2 +- libraries/render-utils/src/spot_light.slf | 2 +- 5 files changed, 60 insertions(+), 26 deletions(-) diff --git a/libraries/model/src/model/Light.cpp b/libraries/model/src/model/Light.cpp index ef0757f3c6..1b12aca8f0 100755 --- a/libraries/model/src/model/Light.cpp +++ b/libraries/model/src/model/Light.cpp @@ -15,22 +15,26 @@ using namespace model; Light::Light() : _flags(0), _schemaBuffer(), - _transform() { + _transform(), + _maximumRadius(1.0f) { // only if created from nothing shall we create the Buffer to store the properties Schema schema; _schemaBuffer = std::make_shared(sizeof(Schema), (const gpu::Byte*) &schema); + updateLightRadius(); } Light::Light(const Light& light) : _flags(light._flags), _schemaBuffer(light._schemaBuffer), - _transform(light._transform) { + _transform(light._transform), + _maximumRadius(1.0f) { } Light& Light::operator= (const Light& light) { _flags = (light._flags); _schemaBuffer = (light._schemaBuffer); _transform = (light._transform); + _maximumRadius = (light._maximumRadius); return (*this); } @@ -70,21 +74,35 @@ void Light::setAmbientIntensity(float intensity) { editSchema()._ambientIntensity = intensity; } +void Light::setSurfaceRadius(float radius) { + if (radius <= 0.0f) { + radius = 0.1f; + } + editSchema()._attenuation.x = radius; + updateLightRadius(); +} void Light::setMaximumRadius(float radius) { if (radius <= 0.f) { radius = 1.0f; } - editSchema()._attenuation.w = radius; + editSchema()._attenuation.y = radius; updateLightRadius(); } void Light::updateLightRadius() { - const float CUTOFF_INTENSITY_RATIO = 0.05f; float intensity = getIntensity() * std::max(std::max(getColor().x, getColor().y), getColor().z); - float denom = sqrtf(intensity / CUTOFF_INTENSITY_RATIO) - 1.0f; - float surfaceRadius = getMaximumRadius() / std::max(denom, 1.0f); + float maximumDistance = getMaximumRadius() - getSurfaceRadius(); - editSchema()._attenuation = Vec4(surfaceRadius, 1.0f/surfaceRadius, CUTOFF_INTENSITY_RATIO, getMaximumRadius()); + float denom = maximumDistance / getSurfaceRadius() + 1; + + // The cutoff intensity biases the light towards the source. + // If the source is small and the intensity high, many points may not be shaded. + // If the intensity is >=1.0, the lighting attenuation equation gets borked (see Light.slh). + // To maintain sanity, we cap it well before then. + const float MAX_CUTOFF_INTENSITY = 0.01f; // intensity = maximumRadius = 1.0f, surfaceRadius = 0.1f + float cutoffIntensity = std::min(intensity / (denom * denom), MAX_CUTOFF_INTENSITY); + + editSchema()._attenuation.z = cutoffIntensity; } #include diff --git a/libraries/model/src/model/Light.h b/libraries/model/src/model/Light.h index de7a846a25..f481d188ef 100755 --- a/libraries/model/src/model/Light.h +++ b/libraries/model/src/model/Light.h @@ -74,8 +74,17 @@ public: bool isRanged() const { return (getType() == POINT) || (getType() == SPOT ); } + // Surface Radius is the physical radius of the light sphere through wich the light energy shines + // It's expressed in meters and should be small for realistic lights since its in theory about the + // size of a light bulb filament (~1cm = 0.01m) + void setSurfaceRadius(float radius); + float getSurfaceRadius() const { return getSchema()._attenuation.x; } + + // Maximum radius defines the maximum distance of reach of our light model + // This is where our radial attenuation will reach 0 (even though in theory it should be infinity) + // If MaximumRadius < SurfaceRadius then the radial attenuation is constant at 100% Intensity void setMaximumRadius(float radius); - float getMaximumRadius() const { return getSchema()._attenuation.w; } + float getMaximumRadius() const { return getSchema()._attenuation.y; } // Spot properties bool isSpot() const { return getType() == SPOT; } @@ -107,7 +116,7 @@ public: float _ambientIntensity{0.0f}; Color _color{1.0f}; float _intensity{1.0f}; - Vec4 _attenuation{1.0f}; + Vec4 _attenuation{0.1f, 1.0f, 0.0f, 0.0f}; Vec4 _spot{0.0f, 0.0f, 0.0f, 0.0f}; Vec4 _shadow{0.0f}; @@ -122,6 +131,7 @@ protected: UniformBufferView _schemaBuffer; Transform _transform; gpu::SphericalHarmonics _ambientSphere; + float _maximumRadius; const Schema& getSchema() const { return _schemaBuffer.get(); } Schema& editSchema() { return _schemaBuffer.edit(); } diff --git a/libraries/model/src/model/Light.slh b/libraries/model/src/model/Light.slh index 708e092a0a..5cadef5cff 100644 --- a/libraries/model/src/model/Light.slh +++ b/libraries/model/src/model/Light.slh @@ -29,15 +29,7 @@ vec3 getLightColor(Light l) { return l._color.rgb; } float getLightIntensity(Light l) { return l._color.w; } float getLightAmbientIntensity(Light l) { return l._direction.w; } -float evalLightAttenuation(Light l, float r) { - float d = max(r - l._attenuation.x, 0.0); - float denom = d * l._attenuation.y + 1.0; - float attenuation = 1.0 / (denom * denom); - return max((attenuation - l._attenuation.z)/(1.0 - l._attenuation.z), 0.0); - // return clamp(1.0/(l._attenuation.x + l._attenuation.y * r + l._attenuation.z * r * r), 0.0, 1.0); -} - -float getLightSpotAngleCos(Light l) { + float getLightSpotAngleCos(Light l) { return l._spot.x; } @@ -49,15 +41,19 @@ float evalLightSpotAttenuation(Light l, float cosA) { return pow(cosA, l._spot.w); } -float getLightSquareRadius(Light l) { - return l._attenuation.w * l._attenuation.w; -} - float getLightRadius(Light l) { - return l._attenuation.w; + return l._attenuation.x; } -float getLightAttenuationCutoff(Light l) { +float getLightSquareRadius(Light l) { + return getLightRadius(l) * getLightRadius(l); +} + +float getLightCutoffRadius(Light l) { + return l._attenuation.y; +} + +float getLightCutoffIntensity(Light l) { return l._attenuation.z; } @@ -65,6 +61,16 @@ float getLightShowContour(Light l) { return l._control.w; } +float evalLightAttenuation(Light l, float r) { + float radius = getLightRadius(l); + float cutoff = getLightCutoffIntensity(l); + float d = max(r - radius, 0.0); + float denom = d/radius + 1.0; + float attenuation = min(1.0, 1.0 / (denom * denom)); + // Scale attenuation using cutoff from maximum radius + return max(0, (attenuation - cutoff) / (1 - cutoff)); +} + <@if GPU_FEATURE_PROFILE == GPU_CORE @> uniform lightBuffer { Light light; diff --git a/libraries/render-utils/src/point_light.slf b/libraries/render-utils/src/point_light.slf index fcfb0b336e..4e09275485 100644 --- a/libraries/render-utils/src/point_light.slf +++ b/libraries/render-utils/src/point_light.slf @@ -48,7 +48,7 @@ void main(void) { vec3 fragLightVec = getLightPosition(light) - fragPos.xyz; // Kill if too far from the light center - if (dot(fragLightVec, fragLightVec) > getLightSquareRadius(light)) { + if (dot(fragLightVec, fragLightVec) > getLightCutoffRadius(light)) { discard; } diff --git a/libraries/render-utils/src/spot_light.slf b/libraries/render-utils/src/spot_light.slf index 8170929636..fc7a1e986d 100644 --- a/libraries/render-utils/src/spot_light.slf +++ b/libraries/render-utils/src/spot_light.slf @@ -47,7 +47,7 @@ void main(void) { vec3 fragLightVec = getLightPosition(light) - fragPos.xyz; // Kill if too far from the light center - if (dot(fragLightVec, fragLightVec) > getLightSquareRadius(light)) { + if (dot(fragLightVec, fragLightVec) > getLightCutoffRadius(light)) { discard; } From 84f810bdc0d7872ab44368dcbf783f9050e5c549 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 11 Feb 2016 08:28:17 -0800 Subject: [PATCH 03/15] Style nits on Light --- libraries/model/src/model/Light.cpp | 8 ++------ libraries/model/src/model/Light.h | 4 ++-- libraries/model/src/model/Light.slh | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/libraries/model/src/model/Light.cpp b/libraries/model/src/model/Light.cpp index 1b12aca8f0..2670e5f6fc 100755 --- a/libraries/model/src/model/Light.cpp +++ b/libraries/model/src/model/Light.cpp @@ -12,11 +12,7 @@ using namespace model; -Light::Light() : - _flags(0), - _schemaBuffer(), - _transform(), - _maximumRadius(1.0f) { +Light::Light() { // only if created from nothing shall we create the Buffer to store the properties Schema schema; _schemaBuffer = std::make_shared(sizeof(Schema), (const gpu::Byte*) &schema); @@ -27,7 +23,7 @@ Light::Light(const Light& light) : _flags(light._flags), _schemaBuffer(light._schemaBuffer), _transform(light._transform), - _maximumRadius(1.0f) { + _maximumRadius(light._maximumRadius) { } Light& Light::operator= (const Light& light) { diff --git a/libraries/model/src/model/Light.h b/libraries/model/src/model/Light.h index f481d188ef..cda4e2a825 100755 --- a/libraries/model/src/model/Light.h +++ b/libraries/model/src/model/Light.h @@ -127,11 +127,11 @@ public: protected: - Flags _flags; + Flags _flags{ 0 }; UniformBufferView _schemaBuffer; Transform _transform; gpu::SphericalHarmonics _ambientSphere; - float _maximumRadius; + float _maximumRadius{ 1.0f }; const Schema& getSchema() const { return _schemaBuffer.get(); } Schema& editSchema() { return _schemaBuffer.edit(); } diff --git a/libraries/model/src/model/Light.slh b/libraries/model/src/model/Light.slh index 5cadef5cff..573337aa9c 100644 --- a/libraries/model/src/model/Light.slh +++ b/libraries/model/src/model/Light.slh @@ -29,7 +29,7 @@ vec3 getLightColor(Light l) { return l._color.rgb; } float getLightIntensity(Light l) { return l._color.w; } float getLightAmbientIntensity(Light l) { return l._direction.w; } - float getLightSpotAngleCos(Light l) { +float getLightSpotAngleCos(Light l) { return l._spot.x; } From bab29a0d3e77396f7b232d9a4f4249cf3117fe5d Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Wed, 17 Feb 2016 12:49:41 -0800 Subject: [PATCH 04/15] Compare fragLightVec square to LightCutoffSquareRadius --- libraries/model/src/model/Light.slh | 4 ++++ libraries/render-utils/src/point_light.slf | 2 +- libraries/render-utils/src/spot_light.slf | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libraries/model/src/model/Light.slh b/libraries/model/src/model/Light.slh index 573337aa9c..8f92116796 100644 --- a/libraries/model/src/model/Light.slh +++ b/libraries/model/src/model/Light.slh @@ -53,6 +53,10 @@ float getLightCutoffRadius(Light l) { return l._attenuation.y; } +float getLightCutoffSquareRadius(Light l) { + return getLightCutoffRadius(l) * getLightCutoffRadius(l); +} + float getLightCutoffIntensity(Light l) { return l._attenuation.z; } diff --git a/libraries/render-utils/src/point_light.slf b/libraries/render-utils/src/point_light.slf index 4e09275485..a64d4a81a8 100644 --- a/libraries/render-utils/src/point_light.slf +++ b/libraries/render-utils/src/point_light.slf @@ -48,7 +48,7 @@ void main(void) { vec3 fragLightVec = getLightPosition(light) - fragPos.xyz; // Kill if too far from the light center - if (dot(fragLightVec, fragLightVec) > getLightCutoffRadius(light)) { + if (dot(fragLightVec, fragLightVec) > getLightCutoffSquareRadius(light)) { discard; } diff --git a/libraries/render-utils/src/spot_light.slf b/libraries/render-utils/src/spot_light.slf index fc7a1e986d..b72598f810 100644 --- a/libraries/render-utils/src/spot_light.slf +++ b/libraries/render-utils/src/spot_light.slf @@ -47,7 +47,7 @@ void main(void) { vec3 fragLightVec = getLightPosition(light) - fragPos.xyz; // Kill if too far from the light center - if (dot(fragLightVec, fragLightVec) > getLightCutoffRadius(light)) { + if (dot(fragLightVec, fragLightVec) > getLightCutoffSquareRadius(light)) { discard; } From 329202def7c10dc20a66371bc1cbeb1d428c61d4 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 22 Feb 2016 13:06:12 -0800 Subject: [PATCH 05/15] Remove light curve scale/bias from cutoff Light intensity attenuation is still calculated as a function of distance from the light surface, but is biased back so that the curve begins at the light source, not the surface. Light maximum radius is still user-inputted, but if the radius is after a MIN_CUTOFF_INTENSITY, a new cutoff radius will be calculated from the intensity to avoid extra shader processing. --- libraries/model/src/model/Light.cpp | 22 +++++++++++----------- libraries/model/src/model/Light.h | 12 ++++++------ libraries/model/src/model/Light.slh | 15 ++++----------- 3 files changed, 21 insertions(+), 28 deletions(-) diff --git a/libraries/model/src/model/Light.cpp b/libraries/model/src/model/Light.cpp index f777ab7a99..9d4fb471ed 100755 --- a/libraries/model/src/model/Light.cpp +++ b/libraries/model/src/model/Light.cpp @@ -85,19 +85,19 @@ void Light::setMaximumRadius(float radius) { } void Light::updateLightRadius() { + // This function relies on the attenuation equation: + // I = Li / (1 + (d + Lr)/Lr)^2 + // where I = calculated intensity, Li = light intensity, Lr = light surface radius, d = distance from surface + // see: https://imdoingitwrong.wordpress.com/2011/01/31/light-attenuation/ + // This equation is biased back by Lr so that all lights act as true points, regardless of surface radii + + const float MIN_CUTOFF_INTENSITY = 0.001f; + // Get cutoff radius at minimum intensity float intensity = getIntensity() * std::max(std::max(getColor().x, getColor().y), getColor().z); - float maximumDistance = getMaximumRadius() - getSurfaceRadius(); + float cutoffRadius = getSurfaceRadius() * ((glm::sqrt(intensity / MIN_CUTOFF_INTENSITY) - 1) - 1); - float denom = maximumDistance / getSurfaceRadius() + 1; - - // The cutoff intensity biases the light towards the source. - // If the source is small and the intensity high, many points may not be shaded. - // If the intensity is >=1.0, the lighting attenuation equation gets borked (see Light.slh). - // To maintain sanity, we cap it well before then. - const float MAX_CUTOFF_INTENSITY = 0.01f; // intensity = maximumRadius = 1.0f, surfaceRadius = 0.1f - float cutoffIntensity = std::min(intensity / (denom * denom), MAX_CUTOFF_INTENSITY); - - editSchema()._attenuation.z = cutoffIntensity; + // If it is less than max radius, store it to buffer to avoid extra shading + editSchema()._attenuation.z = std::min(getMaximumRadius(), cutoffRadius); } #include diff --git a/libraries/model/src/model/Light.h b/libraries/model/src/model/Light.h index 0da1712ea3..357de8d69d 100755 --- a/libraries/model/src/model/Light.h +++ b/libraries/model/src/model/Light.h @@ -74,15 +74,15 @@ public: bool isRanged() const { return (getType() == POINT) || (getType() == SPOT ); } - // Surface Radius is the physical radius of the light sphere through wich the light energy shines - // It's expressed in meters and should be small for realistic lights since its in theory about the - // size of a light bulb filament (~1cm = 0.01m) + // Surface radius is the physical radius of the light sphere through which energy shines, + // expressed in meters. It is used only to calculate the falloff curve of the light. + // Actual lights will all have surface radii approaching 0. void setSurfaceRadius(float radius); float getSurfaceRadius() const { return getSchema()._attenuation.x; } - // Maximum radius defines the maximum distance of reach of our light model - // This is where our radial attenuation will reach 0 (even though in theory it should be infinity) - // If MaximumRadius < SurfaceRadius then the radial attenuation is constant at 100% Intensity + // Maximum radius is the cutoff radius of the light energy, expressed in meters. + // It is used to bound light entities, and *will not* affect the falloff curve of the light. + // Setting it low will result in a noticeable cutoff. void setMaximumRadius(float radius); float getMaximumRadius() const { return getSchema()._attenuation.y; } diff --git a/libraries/model/src/model/Light.slh b/libraries/model/src/model/Light.slh index 4755345dd2..af1c251ccb 100644 --- a/libraries/model/src/model/Light.slh +++ b/libraries/model/src/model/Light.slh @@ -87,29 +87,22 @@ float getLightSquareRadius(Light l) { } float getLightCutoffRadius(Light l) { - return l._attenuation.y; + return l._attenuation.z; } float getLightCutoffSquareRadius(Light l) { return getLightCutoffRadius(l) * getLightCutoffRadius(l); } -float getLightCutoffIntensity(Light l) { - return l._attenuation.z; -} - float getLightShowContour(Light l) { return l._control.w; } -float evalLightAttenuation(Light l, float r) { +float evalLightAttenuation(Light l, float d) { float radius = getLightRadius(l); - float cutoff = getLightCutoffIntensity(l); - float d = max(r - radius, 0.0); - float denom = d/radius + 1.0; + float denom = d / radius + 1.0; float attenuation = min(1.0, 1.0 / (denom * denom)); - // Scale attenuation using cutoff from maximum radius - return max(0, (attenuation - cutoff) / (1 - cutoff)); + return attenuation; } SphericalHarmonics getLightAmbientSphere(Light l) { From 6d7bf7d423421176b4606c4321f2d5e27e4cb86a Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 22 Feb 2016 14:46:00 -0800 Subject: [PATCH 06/15] Add PROP_SURFACE_RADIUS to LightEntity --- libraries/entities/src/EntityItemProperties.h | 1 + libraries/entities/src/EntityItemPropertiesDefaults.h | 1 + libraries/entities/src/EntityPropertyFlags.h | 2 ++ libraries/entities/src/LightEntityItem.cpp | 10 ++++++++++ libraries/entities/src/LightEntityItem.h | 4 ++++ 5 files changed, 18 insertions(+) diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 2cfef17c1b..09ac9bd750 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -131,6 +131,7 @@ public: DEFINE_PROPERTY(PROP_DYNAMIC, Dynamic, dynamic, bool, ENTITY_ITEM_DEFAULT_DYNAMIC); DEFINE_PROPERTY(PROP_IS_SPOTLIGHT, IsSpotlight, isSpotlight, bool, false); DEFINE_PROPERTY(PROP_INTENSITY, Intensity, intensity, float, 1.0f); + DEFINE_PROPERTY(PROP_SURFACE_RADIUS, SurfaceRadius, surfaceRadius, float, ENTITY_ITEM_DEFAULT_SURFACE_RADIUS); DEFINE_PROPERTY(PROP_EXPONENT, Exponent, exponent, float, 0.0f); DEFINE_PROPERTY(PROP_CUTOFF, Cutoff, cutoff, float, ENTITY_ITEM_DEFAULT_CUTOFF); DEFINE_PROPERTY(PROP_LOCKED, Locked, locked, bool, ENTITY_ITEM_DEFAULT_LOCKED); diff --git a/libraries/entities/src/EntityItemPropertiesDefaults.h b/libraries/entities/src/EntityItemPropertiesDefaults.h index 5375b1bc3a..09678cb34e 100644 --- a/libraries/entities/src/EntityItemPropertiesDefaults.h +++ b/libraries/entities/src/EntityItemPropertiesDefaults.h @@ -72,6 +72,7 @@ const bool ENTITY_ITEM_DEFAULT_COLLISIONLESS = false; const bool ENTITY_ITEM_DEFAULT_DYNAMIC = false; const bool ENTITY_ITEM_DEFAULT_BILLBOARDED = false; +const float ENTITY_ITEM_DEFAULT_SURFACE_RADIUS = 0.1f; const float ENTITY_ITEM_DEFAULT_CUTOFF = PI / 2; const QString ENTITY_ITEM_DEFAULT_NAME = QString(""); diff --git a/libraries/entities/src/EntityPropertyFlags.h b/libraries/entities/src/EntityPropertyFlags.h index b60fc6174c..8882fa9aa6 100644 --- a/libraries/entities/src/EntityPropertyFlags.h +++ b/libraries/entities/src/EntityPropertyFlags.h @@ -167,6 +167,8 @@ enum EntityPropertyList { PROP_COLLISION_MASK, // one byte of collision group flags + PROP_SURFACE_RADIUS, // for Light entity + //////////////////////////////////////////////////////////////////////////////////////////////////// // ATTENTION: add new properties to end of list just ABOVE this line PROP_AFTER_LAST_ITEM, diff --git a/libraries/entities/src/LightEntityItem.cpp b/libraries/entities/src/LightEntityItem.cpp index ac56fc9c1f..a9efb60814 100644 --- a/libraries/entities/src/LightEntityItem.cpp +++ b/libraries/entities/src/LightEntityItem.cpp @@ -36,6 +36,7 @@ LightEntityItem::LightEntityItem(const EntityItemID& entityItemID) : EntityItem( // default property values _color[RED_INDEX] = _color[GREEN_INDEX] = _color[BLUE_INDEX] = 0; _intensity = 1.0f; + _surfaceRadius = 0.1f; _exponent = 0.0f; _cutoff = PI; } @@ -62,10 +63,15 @@ EntityItemProperties LightEntityItem::getProperties(EntityPropertyFlags desiredP COPY_ENTITY_PROPERTY_TO_PROPERTIES(intensity, getIntensity); COPY_ENTITY_PROPERTY_TO_PROPERTIES(exponent, getExponent); COPY_ENTITY_PROPERTY_TO_PROPERTIES(cutoff, getCutoff); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(surfaceRadius, getSurfaceRadius); return properties; } +void LightEntityItem::setSurfaceRadius(float value) { + _surfaceRadius = glm::max(value, 0.0f); +} + void LightEntityItem::setIsSpotlight(bool value) { if (value != _isSpotlight) { _isSpotlight = value; @@ -101,6 +107,7 @@ bool LightEntityItem::setProperties(const EntityItemProperties& properties) { SET_ENTITY_PROPERTY_FROM_PROPERTIES(intensity, setIntensity); SET_ENTITY_PROPERTY_FROM_PROPERTIES(exponent, setExponent); SET_ENTITY_PROPERTY_FROM_PROPERTIES(cutoff, setCutoff); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(surfaceRadius, setSurfaceRadius); if (somethingChanged) { bool wantDebug = false; @@ -150,6 +157,7 @@ int LightEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, READ_ENTITY_PROPERTY(PROP_INTENSITY, float, setIntensity); READ_ENTITY_PROPERTY(PROP_EXPONENT, float, setExponent); READ_ENTITY_PROPERTY(PROP_CUTOFF, float, setCutoff); + READ_ENTITY_PROPERTY(PROP_SURFACE_RADIUS, float, setSurfaceRadius); } return bytesRead; @@ -164,6 +172,7 @@ EntityPropertyFlags LightEntityItem::getEntityProperties(EncodeBitstreamParams& requestedProperties += PROP_INTENSITY; requestedProperties += PROP_EXPONENT; requestedProperties += PROP_CUTOFF; + requestedProperties += PROP_SURFACE_RADIUS; return requestedProperties; } @@ -181,4 +190,5 @@ void LightEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBit APPEND_ENTITY_PROPERTY(PROP_INTENSITY, getIntensity()); APPEND_ENTITY_PROPERTY(PROP_EXPONENT, getExponent()); APPEND_ENTITY_PROPERTY(PROP_CUTOFF, getCutoff()); + APPEND_ENTITY_PROPERTY(PROP_SURFACE_RADIUS, getSurfaceRadius()); } diff --git a/libraries/entities/src/LightEntityItem.h b/libraries/entities/src/LightEntityItem.h index 103c462809..193b2832e8 100644 --- a/libraries/entities/src/LightEntityItem.h +++ b/libraries/entities/src/LightEntityItem.h @@ -65,6 +65,9 @@ public: float getIntensity() const { return _intensity; } void setIntensity(float value) { _intensity = value; } + float getSurfaceRadius() const { return _surfaceRadius; } + void setSurfaceRadius(float value); + float getExponent() const { return _exponent; } void setExponent(float value) { _exponent = value; } @@ -80,6 +83,7 @@ protected: rgbColor _color; bool _isSpotlight; float _intensity; + float _surfaceRadius; float _exponent; float _cutoff; From 292842261da06eb9b66825da1ed30a77e5468668 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 22 Feb 2016 14:55:00 -0800 Subject: [PATCH 07/15] Bump packet version to LIGHT_HAS_SURFACE_RADIUS --- libraries/networking/src/udt/PacketHeaders.cpp | 2 +- libraries/networking/src/udt/PacketHeaders.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/networking/src/udt/PacketHeaders.cpp b/libraries/networking/src/udt/PacketHeaders.cpp index 4e6418279d..e40ee7be12 100644 --- a/libraries/networking/src/udt/PacketHeaders.cpp +++ b/libraries/networking/src/udt/PacketHeaders.cpp @@ -41,7 +41,7 @@ PacketVersion versionForPacketType(PacketType packetType) { case PacketType::EntityAdd: case PacketType::EntityEdit: case PacketType::EntityData: - return VERSION_ATMOSPHERE_REMOVED; + return VERSION_LIGHT_HAS_SURFACE_RADIUS; case PacketType::AvatarData: case PacketType::BulkAvatarData: return static_cast(AvatarMixerPacketVersion::SoftAttachmentSupport); diff --git a/libraries/networking/src/udt/PacketHeaders.h b/libraries/networking/src/udt/PacketHeaders.h index af3fd49710..e36542e9f1 100644 --- a/libraries/networking/src/udt/PacketHeaders.h +++ b/libraries/networking/src/udt/PacketHeaders.h @@ -166,6 +166,7 @@ const PacketVersion VERSION_MODEL_ENTITIES_JOINTS_ON_WIRE = 53; const PacketVersion VERSION_ENTITITES_HAVE_QUERY_BOX = 54; const PacketVersion VERSION_ENTITITES_HAVE_COLLISION_MASK = 55; const PacketVersion VERSION_ATMOSPHERE_REMOVED = 56; +const PacketVersion VERSION_LIGHT_HAS_SURFACE_RADIUS = 57; enum class AvatarMixerPacketVersion : PacketVersion { TranslationSupport = 17, From 8ac84b3fc230b5d9ff8c996fa3d7af4841d99e37 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 22 Feb 2016 14:46:43 -0800 Subject: [PATCH 08/15] Render point/spot lights with surface radii --- interface/src/avatar/Avatar.cpp | 3 ++- .../entities-renderer/src/RenderableLightEntityItem.cpp | 5 +++-- libraries/render-utils/src/DeferredLightingEffect.cpp | 8 ++++---- libraries/render-utils/src/DeferredLightingEffect.h | 5 +++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index f62eb5a070..5a92f98fde 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -429,6 +429,7 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition) { if (renderArgs->_renderMode != RenderArgs::SHADOW_RENDER_MODE) { // add local lights const float BASE_LIGHT_DISTANCE = 2.0f; + const float LIGHT_SURFACE_RADIUS = 0.01f; const float LIGHT_EXPONENT = 1.0f; const float LIGHT_CUTOFF = glm::radians(80.0f); float distance = BASE_LIGHT_DISTANCE * getUniformScale(); @@ -437,7 +438,7 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition) { foreach (const AvatarManager::LocalLight& light, DependencyManager::get()->getLocalLights()) { glm::vec3 direction = orientation * light.direction; DependencyManager::get()->addSpotLight(position - direction * distance, - distance * 2.0f, light.color, 0.5f, orientation, LIGHT_EXPONENT, LIGHT_CUTOFF); + distance * 2.0f, light.color, 0.5f, LIGHT_SURFACE_RADIUS, orientation, LIGHT_EXPONENT, LIGHT_CUTOFF); } } diff --git a/libraries/entities-renderer/src/RenderableLightEntityItem.cpp b/libraries/entities-renderer/src/RenderableLightEntityItem.cpp index 39182f322c..10d447126d 100644 --- a/libraries/entities-renderer/src/RenderableLightEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLightEntityItem.cpp @@ -36,15 +36,16 @@ void RenderableLightEntityItem::render(RenderArgs* args) { glm::vec3 color = toGlm(getXColor()); float intensity = getIntensity(); + float surfaceRadius = getSurfaceRadius(); float exponent = getExponent(); float cutoff = glm::radians(getCutoff()); if (_isSpotlight) { DependencyManager::get()->addSpotLight(position, largestDiameter / 2.0f, - color, intensity, rotation, exponent, cutoff); + color, intensity, surfaceRadius, rotation, exponent, cutoff); } else { DependencyManager::get()->addPointLight(position, largestDiameter / 2.0f, - color, intensity); + color, intensity, surfaceRadius); } #ifdef WANT_DEBUG diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index e39c3f5de2..b18bdcdc5b 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -98,12 +98,12 @@ void DeferredLightingEffect::init() { } void DeferredLightingEffect::addPointLight(const glm::vec3& position, float radius, const glm::vec3& color, - float intensity) { - addSpotLight(position, radius, color, intensity); + float intensity, float surfaceRadius) { + addSpotLight(position, radius, color, intensity, surfaceRadius); } void DeferredLightingEffect::addSpotLight(const glm::vec3& position, float radius, const glm::vec3& color, - float intensity, const glm::quat& orientation, float exponent, float cutoff) { + float intensity, float surfaceRadius, const glm::quat& orientation, float exponent, float cutoff) { unsigned int lightID = (unsigned int)(_pointLights.size() + _spotLights.size() + _globalLights.size()); if (lightID >= _allocatedLights.size()) { @@ -115,7 +115,7 @@ void DeferredLightingEffect::addSpotLight(const glm::vec3& position, float radiu lp->setMaximumRadius(radius); lp->setColor(color); lp->setIntensity(intensity); - //lp->setShowContour(quadraticAttenuation); + lp->setSurfaceRadius(surfaceRadius); if (exponent == 0.0f && cutoff == PI) { lp->setType(model::Light::POINT); diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 8cb4bbba8f..20b8f972b8 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -37,11 +37,12 @@ public: /// Adds a point light to render for the current frame. void addPointLight(const glm::vec3& position, float radius, const glm::vec3& color = glm::vec3(0.0f, 0.0f, 0.0f), - float intensity = 0.5f); + float intensity = 0.5f, float surfaceRadius = 0.01f); /// Adds a spot light to render for the current frame. void addSpotLight(const glm::vec3& position, float radius, const glm::vec3& color = glm::vec3(1.0f, 1.0f, 1.0f), - float intensity = 0.5f, const glm::quat& orientation = glm::quat(), float exponent = 0.0f, float cutoff = PI); + float intensity = 0.5f, float surfaceRadius = 0.01f, + const glm::quat& orientation = glm::quat(), float exponent = 0.0f, float cutoff = PI); void prepare(RenderArgs* args); void render(const render::RenderContextPointer& renderContext); From 1506686b799d6f90f325541d8c27b1a3590be1f2 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 22 Feb 2016 15:00:08 -0800 Subject: [PATCH 09/15] Expose light surface to entityProperties --- examples/html/entityProperties.html | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index 0c6e37b192..7bedb9981a 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -285,6 +285,7 @@ var elLightColorBlue = document.getElementById("property-light-color-blue"); var elLightIntensity = document.getElementById("property-light-intensity"); + var elLightSurfaceRadius = document.getElementById("property-light-surface-radius"); var elLightExponent = document.getElementById("property-light-exponent"); var elLightCutoff = document.getElementById("property-light-cutoff"); @@ -564,6 +565,7 @@ elLightColorBlue.value = properties.color.blue; elLightIntensity.value = properties.intensity; + elLightSurfaceRadius.value = properties.surfaceRadius; elLightExponent.value = properties.exponent; elLightCutoff.value = properties.cutoff; } else if (properties.type == "Zone") { @@ -744,6 +746,7 @@ }) elLightIntensity.addEventListener('change', createEmitNumberPropertyUpdateFunction('intensity')); + elLightSurfaceRadius.addEventListener('change', createEmitNumberPropertyUpdateFunction('surfaceRadius')); elLightExponent.addEventListener('change', createEmitNumberPropertyUpdateFunction('exponent')); elLightCutoff.addEventListener('change', createEmitNumberPropertyUpdateFunction('cutoff')); @@ -1504,12 +1507,6 @@ -
- Spot Light - - - -
Color
@@ -1525,6 +1522,18 @@
+
+
Apparent Surface Radius (falloff factor)"
+
+ +
+
+
+ Spot Light + + + +
Spot Light Exponent
@@ -1539,4 +1548,4 @@
- \ No newline at end of file + From 868e2ec96157f569bb49000e72a31b35672f44b4 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 22 Feb 2016 15:02:21 -0800 Subject: [PATCH 10/15] Use "number" in entityProperties --- examples/html/entityProperties.html | 142 ++++++++++++++-------------- 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index 7bedb9981a..910544aad9 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -1001,25 +1001,25 @@
Line Height
- +
Text Color
-
R
-
G
-
B
+
R
+
G
+
B
Background Color
-
R
-
G
-
B
+
R
+
G
+
B
@@ -1043,32 +1043,32 @@
Light Color
-
R
-
G
-
B
+
R
+
G
+
B
Light Intensity
- +
Light Direction
-
Pitch
-
Yaw
-
Roll
+
Pitch
+
Yaw
+
Roll
Ambient Intensity
- +
@@ -1087,19 +1087,19 @@
Stage Latitude
- +
Stage Longitude
- +
Stage Altitude
- +
@@ -1113,13 +1113,13 @@
Stage Day
- +
Stage Hour
- +
@@ -1144,9 +1144,9 @@
Skybox Color
-
R
-
G
-
B
+
R
+
G
+
B
@@ -1195,9 +1195,9 @@
Position
-
X
-
Y
-
Z
+
X
+
Y
+
Z
@@ -1222,23 +1222,23 @@
Registration
-
X
-
Y
-
Z
+
X
+
Y
+
Z
Dimensions
-
X
-
Y
-
Z
+
X
+
Y
+
Z
- % + %
@@ -1249,9 +1249,9 @@
Voxel Volume Size
-
X
-
Y
-
Z
+
X
+
Y
+
Z
Surface Extractor
@@ -1283,9 +1283,9 @@
Rotation
-
Pitch
-
Yaw
-
Roll
+
Pitch
+
Yaw
+
Roll
@@ -1297,66 +1297,66 @@
Linear Velocity
-
X
-
Y
-
Z
+
X
+
Y
+
Z
Linear Damping
- +
Angular Velocity
-
Pitch
-
Yaw
-
Roll
+
Pitch
+
Yaw
+
Roll
Angular Damping
- +
Restitution
- +
Friction
- +
Gravity
-
X
-
Y
-
Z
+
X
+
Y
+
Z
Acceleration
-
X
-
Y
-
Z
+
X
+
Y
+
Z
Density
- +
@@ -1364,9 +1364,9 @@
Color
-
R
-
G
-
B
+
R
+
G
+
B
@@ -1399,7 +1399,7 @@
Lifetime
- +
@@ -1457,25 +1457,25 @@
Animation FPS
- +
Animation Frame
- +
Animation First Frame
- +
Animation Last Frame
- +
@@ -1511,21 +1511,21 @@
Color
-
R
-
G
-
B
+
R
+
G
+
B
Intensity
- +
Apparent Surface Radius (falloff factor)"
- +
@@ -1537,13 +1537,13 @@
Spot Light Exponent
- +
Spot Light Cutoff (degrees)
- +
From dacf9f712361dbfb7f2a512a4207ef05a428b977 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 22 Feb 2016 15:18:45 -0800 Subject: [PATCH 11/15] Rm extra " in entityProperties --- examples/html/entityProperties.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index 5cbbebe66b..69e5675efe 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -1610,7 +1610,7 @@
-
Apparent Surface Radius (falloff factor)"
+
Apparent Surface Radius (falloff factor)
From 8688bf2abbdc87879c23ca85a0c01d0756b1e214 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 22 Feb 2016 15:54:36 -0800 Subject: [PATCH 12/15] Move light entity defaults to light --- libraries/entities/src/EntityItemProperties.h | 11 ++++++----- .../entities/src/EntityItemPropertiesDefaults.h | 3 --- libraries/entities/src/LightEntityItem.cpp | 12 ++++++------ libraries/entities/src/LightEntityItem.h | 16 +++++++++++----- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 09ac9bd750..65510a28c4 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -35,6 +35,7 @@ #include "EntityItemPropertiesMacros.h" #include "EntityTypes.h" #include "EntityPropertyFlags.h" +#include "LightEntityItem.h" #include "LineEntityItem.h" #include "ParticleEffectEntityItem.h" #include "PolyVoxEntityItem.h" @@ -129,11 +130,11 @@ public: DEFINE_PROPERTY(PROP_COLLISIONLESS, Collisionless, collisionless, bool, ENTITY_ITEM_DEFAULT_COLLISIONLESS); DEFINE_PROPERTY(PROP_COLLISION_MASK, CollisionMask, collisionMask, uint8_t, ENTITY_COLLISION_MASK_DEFAULT); DEFINE_PROPERTY(PROP_DYNAMIC, Dynamic, dynamic, bool, ENTITY_ITEM_DEFAULT_DYNAMIC); - DEFINE_PROPERTY(PROP_IS_SPOTLIGHT, IsSpotlight, isSpotlight, bool, false); - DEFINE_PROPERTY(PROP_INTENSITY, Intensity, intensity, float, 1.0f); - DEFINE_PROPERTY(PROP_SURFACE_RADIUS, SurfaceRadius, surfaceRadius, float, ENTITY_ITEM_DEFAULT_SURFACE_RADIUS); - DEFINE_PROPERTY(PROP_EXPONENT, Exponent, exponent, float, 0.0f); - DEFINE_PROPERTY(PROP_CUTOFF, Cutoff, cutoff, float, ENTITY_ITEM_DEFAULT_CUTOFF); + DEFINE_PROPERTY(PROP_IS_SPOTLIGHT, IsSpotlight, isSpotlight, bool, LightEntityItem::DEFAULT_IS_SPOTLIGHT); + DEFINE_PROPERTY(PROP_INTENSITY, Intensity, intensity, float, LightEntityItem::DEFAULT_INTENSITY); + DEFINE_PROPERTY(PROP_SURFACE_RADIUS, SurfaceRadius, surfaceRadius, float, LightEntityItem::DEFAULT_SURFACE_RADIUS); + DEFINE_PROPERTY(PROP_EXPONENT, Exponent, exponent, float, LightEntityItem::DEFAULT_EXPONENT); + DEFINE_PROPERTY(PROP_CUTOFF, Cutoff, cutoff, float, LightEntityItem::DEFAULT_CUTOFF); DEFINE_PROPERTY(PROP_LOCKED, Locked, locked, bool, ENTITY_ITEM_DEFAULT_LOCKED); DEFINE_PROPERTY_REF(PROP_TEXTURES, Textures, textures, QString, ""); DEFINE_PROPERTY_REF(PROP_USER_DATA, UserData, userData, QString, ENTITY_ITEM_DEFAULT_USER_DATA); diff --git a/libraries/entities/src/EntityItemPropertiesDefaults.h b/libraries/entities/src/EntityItemPropertiesDefaults.h index 09678cb34e..aa4fb5c619 100644 --- a/libraries/entities/src/EntityItemPropertiesDefaults.h +++ b/libraries/entities/src/EntityItemPropertiesDefaults.h @@ -72,9 +72,6 @@ const bool ENTITY_ITEM_DEFAULT_COLLISIONLESS = false; const bool ENTITY_ITEM_DEFAULT_DYNAMIC = false; const bool ENTITY_ITEM_DEFAULT_BILLBOARDED = false; -const float ENTITY_ITEM_DEFAULT_SURFACE_RADIUS = 0.1f; -const float ENTITY_ITEM_DEFAULT_CUTOFF = PI / 2; - const QString ENTITY_ITEM_DEFAULT_NAME = QString(""); #endif // hifi_EntityItemPropertiesDefaults_h diff --git a/libraries/entities/src/LightEntityItem.cpp b/libraries/entities/src/LightEntityItem.cpp index a9efb60814..a8ca4d9301 100644 --- a/libraries/entities/src/LightEntityItem.cpp +++ b/libraries/entities/src/LightEntityItem.cpp @@ -21,6 +21,12 @@ #include "EntityTreeElement.h" #include "LightEntityItem.h" +const bool LightEntityItem::DEFAULT_IS_SPOTLIGHT = false; +const float LightEntityItem::DEFAULT_INTENSITY = 1.0f; +const float LightEntityItem::DEFAULT_SURFACE_RADIUS = 0.1f; +const float LightEntityItem::DEFAULT_EXPONENT = 0.0f; +const float LightEntityItem::DEFAULT_CUTOFF = PI / 2.0f; + bool LightEntityItem::_lightsArePickable = false; EntityItemPointer LightEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { @@ -32,13 +38,7 @@ EntityItemPointer LightEntityItem::factory(const EntityItemID& entityID, const E // our non-pure virtual subclass for now... LightEntityItem::LightEntityItem(const EntityItemID& entityItemID) : EntityItem(entityItemID) { _type = EntityTypes::Light; - - // default property values _color[RED_INDEX] = _color[GREEN_INDEX] = _color[BLUE_INDEX] = 0; - _intensity = 1.0f; - _surfaceRadius = 0.1f; - _exponent = 0.0f; - _cutoff = PI; } void LightEntityItem::setDimensions(const glm::vec3& value) { diff --git a/libraries/entities/src/LightEntityItem.h b/libraries/entities/src/LightEntityItem.h index 193b2832e8..2186df70ed 100644 --- a/libraries/entities/src/LightEntityItem.h +++ b/libraries/entities/src/LightEntityItem.h @@ -16,6 +16,12 @@ class LightEntityItem : public EntityItem { public: + static const bool DEFAULT_IS_SPOTLIGHT; + static const float DEFAULT_INTENSITY; + static const float DEFAULT_SURFACE_RADIUS; + static const float DEFAULT_EXPONENT; + static const float DEFAULT_CUTOFF; + static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties); LightEntityItem(const EntityItemID& entityItemID); @@ -81,11 +87,11 @@ protected: // properties of a light rgbColor _color; - bool _isSpotlight; - float _intensity; - float _surfaceRadius; - float _exponent; - float _cutoff; + bool _isSpotlight { DEFAULT_IS_SPOTLIGHT }; + float _intensity { DEFAULT_INTENSITY }; + float _surfaceRadius { DEFAULT_SURFACE_RADIUS }; + float _exponent { DEFAULT_EXPONENT }; + float _cutoff { DEFAULT_CUTOFF }; static bool _lightsArePickable; }; From 1e3cfd6baf12311a4489b738ce453cd14179bd27 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 22 Feb 2016 17:03:27 -0800 Subject: [PATCH 13/15] Detect changes for surfaceRadius --- libraries/entities/src/EntityItemProperties.cpp | 10 ++++++++++ libraries/entities/src/EntityItemProperties.h | 1 + 2 files changed, 11 insertions(+) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 8e0983f62a..c34627793a 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -245,6 +245,7 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_DYNAMIC, dynamic); CHECK_PROPERTY_CHANGE(PROP_IS_SPOTLIGHT, isSpotlight); CHECK_PROPERTY_CHANGE(PROP_INTENSITY, intensity); + CHECK_PROPERTY_CHANGE(PROP_SURFACE_RADIUS, surfaceRadius); CHECK_PROPERTY_CHANGE(PROP_EXPONENT, exponent); CHECK_PROPERTY_CHANGE(PROP_CUTOFF, cutoff); CHECK_PROPERTY_CHANGE(PROP_LOCKED, locked); @@ -445,6 +446,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool if (_type == EntityTypes::Light) { COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_IS_SPOTLIGHT, isSpotlight); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_INTENSITY, intensity); + COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_SURFACE_RADIUS, surfaceRadius); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_EXPONENT, exponent); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_CUTOFF, cutoff); } @@ -597,6 +599,7 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool COPY_PROPERTY_FROM_QSCRIPTVALUE(dynamic, bool, setDynamic); COPY_PROPERTY_FROM_QSCRIPTVALUE(isSpotlight, bool, setIsSpotlight); COPY_PROPERTY_FROM_QSCRIPTVALUE(intensity, float, setIntensity); + COPY_PROPERTY_FROM_QSCRIPTVALUE(surfaceRadius, float, setSurfaceRadius); COPY_PROPERTY_FROM_QSCRIPTVALUE(exponent, float, setExponent); COPY_PROPERTY_FROM_QSCRIPTVALUE(cutoff, float, setCutoff); COPY_PROPERTY_FROM_QSCRIPTVALUE(locked, bool, setLocked); @@ -762,6 +765,7 @@ void EntityItemProperties::entityPropertyFlagsFromScriptValue(const QScriptValue ADD_PROPERTY_TO_MAP(PROP_DYNAMIC, unused, dynamic, unused); ADD_PROPERTY_TO_MAP(PROP_IS_SPOTLIGHT, IsSpotlight, isSpotlight, bool); ADD_PROPERTY_TO_MAP(PROP_INTENSITY, Intensity, intensity, float); + ADD_PROPERTY_TO_MAP(PROP_SURFACE_RADIUS, SurfaceRadius, surfaceRadius, float); ADD_PROPERTY_TO_MAP(PROP_EXPONENT, Exponent, exponent, float); ADD_PROPERTY_TO_MAP(PROP_CUTOFF, Cutoff, cutoff, float); ADD_PROPERTY_TO_MAP(PROP_LOCKED, Locked, locked, bool); @@ -1043,6 +1047,7 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem APPEND_ENTITY_PROPERTY(PROP_IS_SPOTLIGHT, properties.getIsSpotlight()); APPEND_ENTITY_PROPERTY(PROP_COLOR, properties.getColor()); APPEND_ENTITY_PROPERTY(PROP_INTENSITY, properties.getIntensity()); + APPEND_ENTITY_PROPERTY(PROP_SURFACE_RADIUS, properties.getSurfaceRadius()); APPEND_ENTITY_PROPERTY(PROP_EXPONENT, properties.getExponent()); APPEND_ENTITY_PROPERTY(PROP_CUTOFF, properties.getCutoff()); } @@ -1332,6 +1337,7 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_IS_SPOTLIGHT, bool, setIsSpotlight); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_COLOR, xColor, setColor); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_INTENSITY, float, setIntensity); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_SURFACE_RADIUS, float, setSurfaceRadius); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_EXPONENT, float, setExponent); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_CUTOFF, float, setCutoff); } @@ -1477,6 +1483,7 @@ void EntityItemProperties::markAllChanged() { _dynamicChanged = true; _intensityChanged = true; + _surfaceRadiusChanged = true; _exponentChanged = true; _cutoffChanged = true; _lockedChanged = true; @@ -1719,6 +1726,9 @@ QList EntityItemProperties::listChangedProperties() { if (intensityChanged()) { out += "intensity"; } + if (surfaceRadiusChanged()) { + out += "surfaceRadius"; + } if (exponentChanged()) { out += "exponent"; } diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 65510a28c4..1d0e447758 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -361,6 +361,7 @@ inline QDebug operator<<(QDebug debug, const EntityItemProperties& properties) { DEBUG_PROPERTY_IF_CHANGED(debug, properties, Dynamic, dynamic, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, IsSpotlight, isSpotlight, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, Intensity, intensity, ""); + DEBUG_PROPERTY_IF_CHANGED(debug, properties, SurfaceRadius, surfaceRadius, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, Exponent, exponent, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, Cutoff, cutoff, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, Locked, locked, ""); From 2534bb14f3de6a1936ab0b5f2ef9dcf90d05d47f Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 22 Feb 2016 18:35:35 -0800 Subject: [PATCH 14/15] Amend entityProperties for fixed-dec light values --- examples/html/entityProperties.html | 32 ++++++++++++++++------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index 69e5675efe..826101a1fe 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -72,10 +72,14 @@ }; } - function createEmitNumberPropertyUpdateFunction(propertyName) { + function createEmitNumberPropertyUpdateFunction(propertyName, decimals) { + decimals = decimals == undefined ? 4 : decimals; return function() { + var value = +this.value; + value = +value.toFixed(decimals); + EventBridge.emitWebEvent( - '{ "type":"update", "properties":{"' + propertyName + '":' + Number(this.value.toFixed(4)) + '}}' + '{ "type":"update", "properties":{"' + propertyName + '":' + value + '}}' ); }; } @@ -605,10 +609,10 @@ elLightColorGreen.value = properties.color.green; elLightColorBlue.value = properties.color.blue; - elLightIntensity.value = properties.intensity; - elLightSurfaceRadius.value = properties.surfaceRadius; - elLightExponent.value = properties.exponent; - elLightCutoff.value = properties.cutoff; + elLightIntensity.value = properties.intensity.toFixed(1); + elLightSurfaceRadius.value = properties.surfaceRadius.toFixed(1); + elLightExponent.value = properties.exponent.toFixed(2); + elLightCutoff.value = properties.cutoff.toFixed(2); } else if (properties.type == "Zone") { for (var i = 0; i < elZoneSections.length; i++) { elZoneSections[i].style.display = 'block'; @@ -797,10 +801,10 @@ } }) - elLightIntensity.addEventListener('change', createEmitNumberPropertyUpdateFunction('intensity')); - elLightSurfaceRadius.addEventListener('change', createEmitNumberPropertyUpdateFunction('surfaceRadius')); - elLightExponent.addEventListener('change', createEmitNumberPropertyUpdateFunction('exponent')); - elLightCutoff.addEventListener('change', createEmitNumberPropertyUpdateFunction('cutoff')); + elLightIntensity.addEventListener('change', createEmitNumberPropertyUpdateFunction('intensity', 1)); + elLightSurfaceRadius.addEventListener('change', createEmitNumberPropertyUpdateFunction('surfaceRadius', 1)); + elLightExponent.addEventListener('change', createEmitNumberPropertyUpdateFunction('exponent', 2)); + elLightCutoff.addEventListener('change', createEmitNumberPropertyUpdateFunction('cutoff', 2)); elWebSourceURL.addEventListener('change', createEmitTextPropertyUpdateFunction('sourceUrl')); @@ -1606,13 +1610,13 @@
Intensity
- +
Apparent Surface Radius (falloff factor)
- +
@@ -1624,13 +1628,13 @@
Spot Light Exponent
- +
Spot Light Cutoff (degrees)
- +
From 32ce7c6eab7ad6d0a5e72a9a32912f2760a3ded1 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 25 Feb 2016 10:02:33 -0800 Subject: [PATCH 15/15] Rename light surfaceRadius->falloffRadius --- examples/html/entityProperties.html | 10 +++++----- interface/src/avatar/Avatar.cpp | 4 ++-- .../src/RenderableLightEntityItem.cpp | 6 +++--- .../entities/src/EntityItemProperties.cpp | 18 +++++++++--------- libraries/entities/src/EntityItemProperties.h | 4 ++-- libraries/entities/src/EntityPropertyFlags.h | 2 +- libraries/entities/src/LightEntityItem.cpp | 16 ++++++++-------- libraries/entities/src/LightEntityItem.h | 8 ++++---- libraries/model/src/model/Light.cpp | 7 ++++--- libraries/model/src/model/Light.h | 8 ++++---- libraries/networking/src/udt/PacketHeaders.cpp | 2 +- libraries/networking/src/udt/PacketHeaders.h | 2 +- .../src/DeferredLightingEffect.cpp | 8 ++++---- .../render-utils/src/DeferredLightingEffect.h | 4 ++-- 14 files changed, 50 insertions(+), 49 deletions(-) diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index fdbe7d7c38..ccbbc5557a 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -326,7 +326,7 @@ var elLightColorBlue = document.getElementById("property-light-color-blue"); var elLightIntensity = document.getElementById("property-light-intensity"); - var elLightSurfaceRadius = document.getElementById("property-light-surface-radius"); + var elLightFalloffRadius = document.getElementById("property-light-falloff-radius"); var elLightExponent = document.getElementById("property-light-exponent"); var elLightCutoff = document.getElementById("property-light-cutoff"); @@ -609,7 +609,7 @@ elLightColorBlue.value = properties.color.blue; elLightIntensity.value = properties.intensity.toFixed(1); - elLightSurfaceRadius.value = properties.surfaceRadius.toFixed(1); + elLightFalloffRadius.value = properties.falloffRadius.toFixed(1); elLightExponent.value = properties.exponent.toFixed(2); elLightCutoff.value = properties.cutoff.toFixed(2); } else if (properties.type == "Zone") { @@ -801,7 +801,7 @@ }) elLightIntensity.addEventListener('change', createEmitNumberPropertyUpdateFunction('intensity', 1)); - elLightSurfaceRadius.addEventListener('change', createEmitNumberPropertyUpdateFunction('surfaceRadius', 1)); + elLightFalloffRadius.addEventListener('change', createEmitNumberPropertyUpdateFunction('falloffRadius', 1)); elLightExponent.addEventListener('change', createEmitNumberPropertyUpdateFunction('exponent', 2)); elLightCutoff.addEventListener('change', createEmitNumberPropertyUpdateFunction('cutoff', 2)); @@ -1613,9 +1613,9 @@
-
Apparent Surface Radius (falloff factor)
+
Falloff Radius
- +
diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 4cbfc2af17..60eaffff88 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -430,7 +430,7 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition) { if (renderArgs->_renderMode != RenderArgs::SHADOW_RENDER_MODE) { // add local lights const float BASE_LIGHT_DISTANCE = 2.0f; - const float LIGHT_SURFACE_RADIUS = 0.01f; + const float LIGHT_FALLOFF_RADIUS = 0.01f; const float LIGHT_EXPONENT = 1.0f; const float LIGHT_CUTOFF = glm::radians(80.0f); float distance = BASE_LIGHT_DISTANCE * getUniformScale(); @@ -439,7 +439,7 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition) { foreach (const AvatarManager::LocalLight& light, DependencyManager::get()->getLocalLights()) { glm::vec3 direction = orientation * light.direction; DependencyManager::get()->addSpotLight(position - direction * distance, - distance * 2.0f, light.color, 0.5f, LIGHT_SURFACE_RADIUS, orientation, LIGHT_EXPONENT, LIGHT_CUTOFF); + distance * 2.0f, light.color, 0.5f, LIGHT_FALLOFF_RADIUS, orientation, LIGHT_EXPONENT, LIGHT_CUTOFF); } } diff --git a/libraries/entities-renderer/src/RenderableLightEntityItem.cpp b/libraries/entities-renderer/src/RenderableLightEntityItem.cpp index 10d447126d..fb6061e94f 100644 --- a/libraries/entities-renderer/src/RenderableLightEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLightEntityItem.cpp @@ -36,16 +36,16 @@ void RenderableLightEntityItem::render(RenderArgs* args) { glm::vec3 color = toGlm(getXColor()); float intensity = getIntensity(); - float surfaceRadius = getSurfaceRadius(); + float falloffRadius = getFalloffRadius(); float exponent = getExponent(); float cutoff = glm::radians(getCutoff()); if (_isSpotlight) { DependencyManager::get()->addSpotLight(position, largestDiameter / 2.0f, - color, intensity, surfaceRadius, rotation, exponent, cutoff); + color, intensity, falloffRadius, rotation, exponent, cutoff); } else { DependencyManager::get()->addPointLight(position, largestDiameter / 2.0f, - color, intensity, surfaceRadius); + color, intensity, falloffRadius); } #ifdef WANT_DEBUG diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index c34627793a..550ec205c0 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -245,7 +245,7 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_DYNAMIC, dynamic); CHECK_PROPERTY_CHANGE(PROP_IS_SPOTLIGHT, isSpotlight); CHECK_PROPERTY_CHANGE(PROP_INTENSITY, intensity); - CHECK_PROPERTY_CHANGE(PROP_SURFACE_RADIUS, surfaceRadius); + CHECK_PROPERTY_CHANGE(PROP_FALLOFF_RADIUS, falloffRadius); CHECK_PROPERTY_CHANGE(PROP_EXPONENT, exponent); CHECK_PROPERTY_CHANGE(PROP_CUTOFF, cutoff); CHECK_PROPERTY_CHANGE(PROP_LOCKED, locked); @@ -446,7 +446,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool if (_type == EntityTypes::Light) { COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_IS_SPOTLIGHT, isSpotlight); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_INTENSITY, intensity); - COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_SURFACE_RADIUS, surfaceRadius); + COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_FALLOFF_RADIUS, falloffRadius); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_EXPONENT, exponent); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_CUTOFF, cutoff); } @@ -599,7 +599,7 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool COPY_PROPERTY_FROM_QSCRIPTVALUE(dynamic, bool, setDynamic); COPY_PROPERTY_FROM_QSCRIPTVALUE(isSpotlight, bool, setIsSpotlight); COPY_PROPERTY_FROM_QSCRIPTVALUE(intensity, float, setIntensity); - COPY_PROPERTY_FROM_QSCRIPTVALUE(surfaceRadius, float, setSurfaceRadius); + COPY_PROPERTY_FROM_QSCRIPTVALUE(falloffRadius, float, setFalloffRadius); COPY_PROPERTY_FROM_QSCRIPTVALUE(exponent, float, setExponent); COPY_PROPERTY_FROM_QSCRIPTVALUE(cutoff, float, setCutoff); COPY_PROPERTY_FROM_QSCRIPTVALUE(locked, bool, setLocked); @@ -765,7 +765,7 @@ void EntityItemProperties::entityPropertyFlagsFromScriptValue(const QScriptValue ADD_PROPERTY_TO_MAP(PROP_DYNAMIC, unused, dynamic, unused); ADD_PROPERTY_TO_MAP(PROP_IS_SPOTLIGHT, IsSpotlight, isSpotlight, bool); ADD_PROPERTY_TO_MAP(PROP_INTENSITY, Intensity, intensity, float); - ADD_PROPERTY_TO_MAP(PROP_SURFACE_RADIUS, SurfaceRadius, surfaceRadius, float); + ADD_PROPERTY_TO_MAP(PROP_FALLOFF_RADIUS, FalloffRadius, falloffRadius, float); ADD_PROPERTY_TO_MAP(PROP_EXPONENT, Exponent, exponent, float); ADD_PROPERTY_TO_MAP(PROP_CUTOFF, Cutoff, cutoff, float); ADD_PROPERTY_TO_MAP(PROP_LOCKED, Locked, locked, bool); @@ -1047,7 +1047,7 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem APPEND_ENTITY_PROPERTY(PROP_IS_SPOTLIGHT, properties.getIsSpotlight()); APPEND_ENTITY_PROPERTY(PROP_COLOR, properties.getColor()); APPEND_ENTITY_PROPERTY(PROP_INTENSITY, properties.getIntensity()); - APPEND_ENTITY_PROPERTY(PROP_SURFACE_RADIUS, properties.getSurfaceRadius()); + APPEND_ENTITY_PROPERTY(PROP_FALLOFF_RADIUS, properties.getFalloffRadius()); APPEND_ENTITY_PROPERTY(PROP_EXPONENT, properties.getExponent()); APPEND_ENTITY_PROPERTY(PROP_CUTOFF, properties.getCutoff()); } @@ -1337,7 +1337,7 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_IS_SPOTLIGHT, bool, setIsSpotlight); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_COLOR, xColor, setColor); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_INTENSITY, float, setIntensity); - READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_SURFACE_RADIUS, float, setSurfaceRadius); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_FALLOFF_RADIUS, float, setFalloffRadius); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_EXPONENT, float, setExponent); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_CUTOFF, float, setCutoff); } @@ -1483,7 +1483,7 @@ void EntityItemProperties::markAllChanged() { _dynamicChanged = true; _intensityChanged = true; - _surfaceRadiusChanged = true; + _falloffRadiusChanged = true; _exponentChanged = true; _cutoffChanged = true; _lockedChanged = true; @@ -1726,8 +1726,8 @@ QList EntityItemProperties::listChangedProperties() { if (intensityChanged()) { out += "intensity"; } - if (surfaceRadiusChanged()) { - out += "surfaceRadius"; + if (falloffRadiusChanged()) { + out += "falloffRadius"; } if (exponentChanged()) { out += "exponent"; diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 1d0e447758..c732d01fa5 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -132,7 +132,7 @@ public: DEFINE_PROPERTY(PROP_DYNAMIC, Dynamic, dynamic, bool, ENTITY_ITEM_DEFAULT_DYNAMIC); DEFINE_PROPERTY(PROP_IS_SPOTLIGHT, IsSpotlight, isSpotlight, bool, LightEntityItem::DEFAULT_IS_SPOTLIGHT); DEFINE_PROPERTY(PROP_INTENSITY, Intensity, intensity, float, LightEntityItem::DEFAULT_INTENSITY); - DEFINE_PROPERTY(PROP_SURFACE_RADIUS, SurfaceRadius, surfaceRadius, float, LightEntityItem::DEFAULT_SURFACE_RADIUS); + DEFINE_PROPERTY(PROP_FALLOFF_RADIUS, FalloffRadius, falloffRadius, float, LightEntityItem::DEFAULT_FALLOFF_RADIUS); DEFINE_PROPERTY(PROP_EXPONENT, Exponent, exponent, float, LightEntityItem::DEFAULT_EXPONENT); DEFINE_PROPERTY(PROP_CUTOFF, Cutoff, cutoff, float, LightEntityItem::DEFAULT_CUTOFF); DEFINE_PROPERTY(PROP_LOCKED, Locked, locked, bool, ENTITY_ITEM_DEFAULT_LOCKED); @@ -361,7 +361,7 @@ inline QDebug operator<<(QDebug debug, const EntityItemProperties& properties) { DEBUG_PROPERTY_IF_CHANGED(debug, properties, Dynamic, dynamic, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, IsSpotlight, isSpotlight, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, Intensity, intensity, ""); - DEBUG_PROPERTY_IF_CHANGED(debug, properties, SurfaceRadius, surfaceRadius, ""); + DEBUG_PROPERTY_IF_CHANGED(debug, properties, FalloffRadius, falloffRadius, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, Exponent, exponent, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, Cutoff, cutoff, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, Locked, locked, ""); diff --git a/libraries/entities/src/EntityPropertyFlags.h b/libraries/entities/src/EntityPropertyFlags.h index 8882fa9aa6..90a7c1e2f7 100644 --- a/libraries/entities/src/EntityPropertyFlags.h +++ b/libraries/entities/src/EntityPropertyFlags.h @@ -167,7 +167,7 @@ enum EntityPropertyList { PROP_COLLISION_MASK, // one byte of collision group flags - PROP_SURFACE_RADIUS, // for Light entity + PROP_FALLOFF_RADIUS, // for Light entity //////////////////////////////////////////////////////////////////////////////////////////////////// // ATTENTION: add new properties to end of list just ABOVE this line diff --git a/libraries/entities/src/LightEntityItem.cpp b/libraries/entities/src/LightEntityItem.cpp index a8ca4d9301..852b37a751 100644 --- a/libraries/entities/src/LightEntityItem.cpp +++ b/libraries/entities/src/LightEntityItem.cpp @@ -23,7 +23,7 @@ const bool LightEntityItem::DEFAULT_IS_SPOTLIGHT = false; const float LightEntityItem::DEFAULT_INTENSITY = 1.0f; -const float LightEntityItem::DEFAULT_SURFACE_RADIUS = 0.1f; +const float LightEntityItem::DEFAULT_FALLOFF_RADIUS = 0.1f; const float LightEntityItem::DEFAULT_EXPONENT = 0.0f; const float LightEntityItem::DEFAULT_CUTOFF = PI / 2.0f; @@ -63,13 +63,13 @@ EntityItemProperties LightEntityItem::getProperties(EntityPropertyFlags desiredP COPY_ENTITY_PROPERTY_TO_PROPERTIES(intensity, getIntensity); COPY_ENTITY_PROPERTY_TO_PROPERTIES(exponent, getExponent); COPY_ENTITY_PROPERTY_TO_PROPERTIES(cutoff, getCutoff); - COPY_ENTITY_PROPERTY_TO_PROPERTIES(surfaceRadius, getSurfaceRadius); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(falloffRadius, getFalloffRadius); return properties; } -void LightEntityItem::setSurfaceRadius(float value) { - _surfaceRadius = glm::max(value, 0.0f); +void LightEntityItem::setFalloffRadius(float value) { + _falloffRadius = glm::max(value, 0.0f); } void LightEntityItem::setIsSpotlight(bool value) { @@ -107,7 +107,7 @@ bool LightEntityItem::setProperties(const EntityItemProperties& properties) { SET_ENTITY_PROPERTY_FROM_PROPERTIES(intensity, setIntensity); SET_ENTITY_PROPERTY_FROM_PROPERTIES(exponent, setExponent); SET_ENTITY_PROPERTY_FROM_PROPERTIES(cutoff, setCutoff); - SET_ENTITY_PROPERTY_FROM_PROPERTIES(surfaceRadius, setSurfaceRadius); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(falloffRadius, setFalloffRadius); if (somethingChanged) { bool wantDebug = false; @@ -157,7 +157,7 @@ int LightEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, READ_ENTITY_PROPERTY(PROP_INTENSITY, float, setIntensity); READ_ENTITY_PROPERTY(PROP_EXPONENT, float, setExponent); READ_ENTITY_PROPERTY(PROP_CUTOFF, float, setCutoff); - READ_ENTITY_PROPERTY(PROP_SURFACE_RADIUS, float, setSurfaceRadius); + READ_ENTITY_PROPERTY(PROP_FALLOFF_RADIUS, float, setFalloffRadius); } return bytesRead; @@ -172,7 +172,7 @@ EntityPropertyFlags LightEntityItem::getEntityProperties(EncodeBitstreamParams& requestedProperties += PROP_INTENSITY; requestedProperties += PROP_EXPONENT; requestedProperties += PROP_CUTOFF; - requestedProperties += PROP_SURFACE_RADIUS; + requestedProperties += PROP_FALLOFF_RADIUS; return requestedProperties; } @@ -190,5 +190,5 @@ void LightEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBit APPEND_ENTITY_PROPERTY(PROP_INTENSITY, getIntensity()); APPEND_ENTITY_PROPERTY(PROP_EXPONENT, getExponent()); APPEND_ENTITY_PROPERTY(PROP_CUTOFF, getCutoff()); - APPEND_ENTITY_PROPERTY(PROP_SURFACE_RADIUS, getSurfaceRadius()); + APPEND_ENTITY_PROPERTY(PROP_FALLOFF_RADIUS, getFalloffRadius()); } diff --git a/libraries/entities/src/LightEntityItem.h b/libraries/entities/src/LightEntityItem.h index 2186df70ed..4c84d3204c 100644 --- a/libraries/entities/src/LightEntityItem.h +++ b/libraries/entities/src/LightEntityItem.h @@ -18,7 +18,7 @@ class LightEntityItem : public EntityItem { public: static const bool DEFAULT_IS_SPOTLIGHT; static const float DEFAULT_INTENSITY; - static const float DEFAULT_SURFACE_RADIUS; + static const float DEFAULT_FALLOFF_RADIUS; static const float DEFAULT_EXPONENT; static const float DEFAULT_CUTOFF; @@ -71,8 +71,8 @@ public: float getIntensity() const { return _intensity; } void setIntensity(float value) { _intensity = value; } - float getSurfaceRadius() const { return _surfaceRadius; } - void setSurfaceRadius(float value); + float getFalloffRadius() const { return _falloffRadius; } + void setFalloffRadius(float value); float getExponent() const { return _exponent; } void setExponent(float value) { _exponent = value; } @@ -89,7 +89,7 @@ protected: rgbColor _color; bool _isSpotlight { DEFAULT_IS_SPOTLIGHT }; float _intensity { DEFAULT_INTENSITY }; - float _surfaceRadius { DEFAULT_SURFACE_RADIUS }; + float _falloffRadius { DEFAULT_FALLOFF_RADIUS }; float _exponent { DEFAULT_EXPONENT }; float _cutoff { DEFAULT_CUTOFF }; diff --git a/libraries/model/src/model/Light.cpp b/libraries/model/src/model/Light.cpp index 9d4fb471ed..8a016c4d77 100755 --- a/libraries/model/src/model/Light.cpp +++ b/libraries/model/src/model/Light.cpp @@ -69,7 +69,7 @@ void Light::setAmbientIntensity(float intensity) { editSchema()._ambientIntensity = intensity; } -void Light::setSurfaceRadius(float radius) { +void Light::setFalloffRadius(float radius) { if (radius <= 0.0f) { radius = 0.1f; } @@ -87,14 +87,15 @@ void Light::setMaximumRadius(float radius) { void Light::updateLightRadius() { // This function relies on the attenuation equation: // I = Li / (1 + (d + Lr)/Lr)^2 - // where I = calculated intensity, Li = light intensity, Lr = light surface radius, d = distance from surface + // where I = calculated intensity, Li = light intensity, Lr = light falloff radius, d = distance from surface // see: https://imdoingitwrong.wordpress.com/2011/01/31/light-attenuation/ + // note that falloff radius replaces surface radius in linked example // This equation is biased back by Lr so that all lights act as true points, regardless of surface radii const float MIN_CUTOFF_INTENSITY = 0.001f; // Get cutoff radius at minimum intensity float intensity = getIntensity() * std::max(std::max(getColor().x, getColor().y), getColor().z); - float cutoffRadius = getSurfaceRadius() * ((glm::sqrt(intensity / MIN_CUTOFF_INTENSITY) - 1) - 1); + float cutoffRadius = getFalloffRadius() * ((glm::sqrt(intensity / MIN_CUTOFF_INTENSITY) - 1) - 1); // If it is less than max radius, store it to buffer to avoid extra shading editSchema()._attenuation.z = std::min(getMaximumRadius(), cutoffRadius); diff --git a/libraries/model/src/model/Light.h b/libraries/model/src/model/Light.h index 357de8d69d..dafbf90397 100755 --- a/libraries/model/src/model/Light.h +++ b/libraries/model/src/model/Light.h @@ -74,11 +74,11 @@ public: bool isRanged() const { return (getType() == POINT) || (getType() == SPOT ); } - // Surface radius is the physical radius of the light sphere through which energy shines, + // FalloffRradius is the physical radius of the light sphere through which energy shines, // expressed in meters. It is used only to calculate the falloff curve of the light. - // Actual lights will all have surface radii approaching 0. - void setSurfaceRadius(float radius); - float getSurfaceRadius() const { return getSchema()._attenuation.x; } + // Actual rendered lights will all have surface radii approaching 0. + void setFalloffRadius(float radius); + float getFalloffRadius() const { return getSchema()._attenuation.x; } // Maximum radius is the cutoff radius of the light energy, expressed in meters. // It is used to bound light entities, and *will not* affect the falloff curve of the light. diff --git a/libraries/networking/src/udt/PacketHeaders.cpp b/libraries/networking/src/udt/PacketHeaders.cpp index e40ee7be12..88fabf1a5a 100644 --- a/libraries/networking/src/udt/PacketHeaders.cpp +++ b/libraries/networking/src/udt/PacketHeaders.cpp @@ -41,7 +41,7 @@ PacketVersion versionForPacketType(PacketType packetType) { case PacketType::EntityAdd: case PacketType::EntityEdit: case PacketType::EntityData: - return VERSION_LIGHT_HAS_SURFACE_RADIUS; + return VERSION_LIGHT_HAS_FALLOFF_RADIUS; case PacketType::AvatarData: case PacketType::BulkAvatarData: return static_cast(AvatarMixerPacketVersion::SoftAttachmentSupport); diff --git a/libraries/networking/src/udt/PacketHeaders.h b/libraries/networking/src/udt/PacketHeaders.h index e36542e9f1..0f586018db 100644 --- a/libraries/networking/src/udt/PacketHeaders.h +++ b/libraries/networking/src/udt/PacketHeaders.h @@ -166,7 +166,7 @@ const PacketVersion VERSION_MODEL_ENTITIES_JOINTS_ON_WIRE = 53; const PacketVersion VERSION_ENTITITES_HAVE_QUERY_BOX = 54; const PacketVersion VERSION_ENTITITES_HAVE_COLLISION_MASK = 55; const PacketVersion VERSION_ATMOSPHERE_REMOVED = 56; -const PacketVersion VERSION_LIGHT_HAS_SURFACE_RADIUS = 57; +const PacketVersion VERSION_LIGHT_HAS_FALLOFF_RADIUS = 57; enum class AvatarMixerPacketVersion : PacketVersion { TranslationSupport = 17, diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index b18bdcdc5b..949fbbfae4 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -98,12 +98,12 @@ void DeferredLightingEffect::init() { } void DeferredLightingEffect::addPointLight(const glm::vec3& position, float radius, const glm::vec3& color, - float intensity, float surfaceRadius) { - addSpotLight(position, radius, color, intensity, surfaceRadius); + float intensity, float falloffRadius) { + addSpotLight(position, radius, color, intensity, falloffRadius); } void DeferredLightingEffect::addSpotLight(const glm::vec3& position, float radius, const glm::vec3& color, - float intensity, float surfaceRadius, const glm::quat& orientation, float exponent, float cutoff) { + float intensity, float falloffRadius, const glm::quat& orientation, float exponent, float cutoff) { unsigned int lightID = (unsigned int)(_pointLights.size() + _spotLights.size() + _globalLights.size()); if (lightID >= _allocatedLights.size()) { @@ -115,7 +115,7 @@ void DeferredLightingEffect::addSpotLight(const glm::vec3& position, float radiu lp->setMaximumRadius(radius); lp->setColor(color); lp->setIntensity(intensity); - lp->setSurfaceRadius(surfaceRadius); + lp->setFalloffRadius(falloffRadius); if (exponent == 0.0f && cutoff == PI) { lp->setType(model::Light::POINT); diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 20b8f972b8..76a5f7ef3c 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -37,11 +37,11 @@ public: /// Adds a point light to render for the current frame. void addPointLight(const glm::vec3& position, float radius, const glm::vec3& color = glm::vec3(0.0f, 0.0f, 0.0f), - float intensity = 0.5f, float surfaceRadius = 0.01f); + float intensity = 0.5f, float falloffRadius = 0.01f); /// Adds a spot light to render for the current frame. void addSpotLight(const glm::vec3& position, float radius, const glm::vec3& color = glm::vec3(1.0f, 1.0f, 1.0f), - float intensity = 0.5f, float surfaceRadius = 0.01f, + float intensity = 0.5f, float falloffRadius = 0.01f, const glm::quat& orientation = glm::quat(), float exponent = 0.0f, float cutoff = PI); void prepare(RenderArgs* args);