Merge pull request #3748 from ey6es/master

Light radius fix: fixed winding order issues with spheres/cones, use near radius to detect when the near window is inside the light volume.
This commit is contained in:
Brad Hefta-Gaub 2014-11-06 14:11:13 -08:00
commit ca7b975c6a
2 changed files with 8 additions and 7 deletions

View file

@ -230,9 +230,10 @@ void DeferredLightingEffect::render() {
glTexGenfv(GL_T, GL_OBJECT_PLANE, (const GLfloat*)&tCoefficients);
// enlarge the scales slightly to account for tesselation
const float SCALE_EXPANSION = 0.1f;
const float SCALE_EXPANSION = 0.05f;
const glm::vec3& eyePoint = Application::getInstance()->getDisplayViewFrustum()->getPosition();
float nearRadius = glm::distance(eyePoint, Application::getInstance()->getDisplayViewFrustum()->getNearTopLeft());
if (!_pointLights.isEmpty()) {
_pointLight.bind();
@ -254,7 +255,7 @@ void DeferredLightingEffect::render() {
glPushMatrix();
float expandedRadius = light.radius * (1.0f + SCALE_EXPANSION);
if (glm::distance(eyePoint, glm::vec3(light.position)) < expandedRadius) {
if (glm::distance(eyePoint, glm::vec3(light.position)) < expandedRadius + nearRadius) {
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -1.0f);
@ -303,7 +304,7 @@ void DeferredLightingEffect::render() {
float expandedRadius = light.radius * (1.0f + SCALE_EXPANSION);
float edgeRadius = expandedRadius / glm::cos(light.cutoff);
if (glm::distance(eyePoint, glm::vec3(light.position)) < edgeRadius) {
if (glm::distance(eyePoint, glm::vec3(light.position)) < edgeRadius + nearRadius) {
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -1.0f);

View file

@ -173,12 +173,12 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks) {
for (int j = 0; j < slices; j++) {
int next = (j + 1) % slices;
*(index++) = bottom + j;
*(index++) = top + next;
*(index++) = bottom + j;
*(index++) = top + j;
*(index++) = bottom + j;
*(index++) = bottom + next;
*(index++) = bottom + j;
*(index++) = top + next;
}
}
@ -187,8 +187,8 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks) {
bottom = (stacks - 2) * slices + 1;
top = bottom + slices;
for (int i = 0; i < slices; i++) {
*(index++) = bottom + i;
*(index++) = bottom + (i + 1) % slices;
*(index++) = bottom + i;
*(index++) = top;
}
@ -408,8 +408,8 @@ void GeometryCache::renderCone(float base, float height, int slices, int stacks)
GLushort* index = indexData;
for (int i = 0; i < baseTriangles; i++) {
*(index++) = 0;
*(index++) = i + 1;
*(index++) = i + 2;
*(index++) = i + 1;
}
for (int i = 1; i <= stacks; i++) {
GLushort bottom = i * slices;