From 00a9f55bc329b41aa41b1ff128dec10e6f0d2741 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Thu, 5 Feb 2015 10:20:19 -0800 Subject: [PATCH] lightings seems to work correctly now --- libraries/model/src/model/Light.cpp | 10 ++++------ libraries/model/src/model/Light.h | 9 ++++----- libraries/render-utils/src/DeferredLightingEffect.cpp | 8 ++++---- libraries/render-utils/src/Light.slh | 2 +- libraries/render-utils/src/point_light.slf | 1 - 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/libraries/model/src/model/Light.cpp b/libraries/model/src/model/Light.cpp index a658c57be9..d66c82ee16 100755 --- a/libraries/model/src/model/Light.cpp +++ b/libraries/model/src/model/Light.cpp @@ -31,7 +31,6 @@ Light& Light::operator= (const Light& light) { _flags = (light._flags); _schemaBuffer = (light._schemaBuffer); _transform = (light._transform); - _spotConeAngle = (light._spotConeAngle); return (*this); } @@ -73,18 +72,17 @@ void Light::setMaximumRadius(float radius) { editSchema()._attenuation = Vec4(surfaceRadius, 1.0f/surfaceRadius, CutOffIntensityRatio, radius); } -void Light::setSpotCone(float angle) { +void Light::setSpotAngle(float angle) { if (angle <= 0.f) { angle = 0.0f; } float cosAngle = cos(angle); - editSchema()._spot.x = cosAngle; + editSchema()._spot.x = cos(angle); editSchema()._spot.y = sin(angle); - editSchema()._spot.z = 1.0f / cosAngle; - _spotConeAngle = angle; + editSchema()._spot.z = angle; } -void Light::setSpotConeExponent(float exponent) { +void Light::setSpotExponent(float exponent) { if (exponent <= 0.f) { exponent = 1.0f; } diff --git a/libraries/model/src/model/Light.h b/libraries/model/src/model/Light.h index c1b8a351e5..c016d54491 100755 --- a/libraries/model/src/model/Light.h +++ b/libraries/model/src/model/Light.h @@ -79,10 +79,10 @@ public: // Spot properties bool isSpot() const { return getType() == SPOT; } - void setSpotCone(float angle); - void setSpotConeExponent(float exponent); - float getSpotConeAngle() const { return _spotConeAngle; } - float getSpotConeExponent() const { return getSchema()._spot.w; } + void setSpotAngle(float angle); + float getSpotAngle() const { return getSchema()._spot.z; } + void setSpotExponent(float exponent); + float getSpotExponent() const { return getSchema()._spot.w; } // Schema to access the attribute values of the light class Schema { @@ -117,7 +117,6 @@ protected: Flags _flags; UniformBufferView _schemaBuffer; Transform _transform; - float _spotConeAngle = 0.0f; const Schema& getSchema() const { return _schemaBuffer.get(); } Schema& editSchema() { return _schemaBuffer.edit(); } diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index e0fd3787f6..61330b8943 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -303,8 +303,8 @@ void DeferredLightingEffect::addSpotLight(const glm::vec3& position, float radiu lp->setPosition(position); lp->setDirection(direction); lp->setMaximumRadius(radius); - lp->setSpotCone(cutoff); - lp->setSpotConeExponent(exponent); + lp->setSpotAngle(cutoff); + lp->setSpotExponent(exponent); lp->setColor(diffuse); lp->setIntensity(1.0f); lp->setType(model::Light::SPOT); @@ -527,7 +527,7 @@ void DeferredLightingEffect::render() { glPushMatrix(); float expandedRadius = light->getMaximumRadius() * (1.0f + SCALE_EXPANSION); - float edgeRadius = expandedRadius / glm::cos(light->getSpotConeAngle()); + float edgeRadius = expandedRadius / glm::cos(light->getSpotAngle()); if (glm::distance(eyePoint, glm::vec3(light->getPosition())) < edgeRadius + nearRadius) { glLoadIdentity(); glTranslatef(0.0f, 0.0f, -1.0f); @@ -547,7 +547,7 @@ void DeferredLightingEffect::render() { glm::vec3 axis = glm::axis(spotRotation); glRotatef(glm::degrees(glm::angle(spotRotation)), axis.x, axis.y, axis.z); glTranslatef(0.0f, 0.0f, -light->getMaximumRadius() * (1.0f + SCALE_EXPANSION * 0.5f)); - geometryCache->renderCone(expandedRadius * glm::tan(light->getSpotConeAngle()), + geometryCache->renderCone(expandedRadius * glm::tan(light->getSpotAngle()), expandedRadius, 32, 1); } diff --git a/libraries/render-utils/src/Light.slh b/libraries/render-utils/src/Light.slh index ab9bf216de..0560898d09 100755 --- a/libraries/render-utils/src/Light.slh +++ b/libraries/render-utils/src/Light.slh @@ -46,7 +46,7 @@ vec2 getLightSpotOutsideNormal2(Light l) { } float evalLightSpotAttenuation(Light l, float cosA) { - return pow(cosA * l._spot.z, l._spot.w); + return pow(cosA, l._spot.w); } float getLightSquareRadius(Light l) { diff --git a/libraries/render-utils/src/point_light.slf b/libraries/render-utils/src/point_light.slf index 4a96f3ae3d..3d3d922203 100644 --- a/libraries/render-utils/src/point_light.slf +++ b/libraries/render-utils/src/point_light.slf @@ -51,7 +51,6 @@ void main(void) { float fragLightDistance = length(fragLightVec); vec3 fragLightDir = fragLightVec / fragLightDistance; - // Eval shading vec3 fragNormal = vec3(invViewMat * vec4(frag.normal, 0.0)); vec4 fragEyeVector = invViewMat * vec4(-frag.position.xyz, 0.0);