lightings seems to work correctly now

This commit is contained in:
Sam Gateau 2015-02-05 10:20:19 -08:00
parent 8e1eebbbd4
commit 00a9f55bc3
5 changed files with 13 additions and 17 deletions

View file

@ -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;
}

View file

@ -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>(); }
Schema& editSchema() { return _schemaBuffer.edit<Schema>(); }

View file

@ -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);
}

View file

@ -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) {

View file

@ -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);