Merge pull request #1177 from vpelletier/for_upstream
GRIM: Assorted lighting fixes
This commit is contained in:
commit
0eb20ae8d5
4 changed files with 26 additions and 25 deletions
|
@ -158,8 +158,8 @@ byte *GfxOpenGL::setupScreen(int screenW, int screenH, bool fullscreen) {
|
||||||
|
|
||||||
GLfloat ambientSource[] = { 0.0f, 0.0f, 0.0f, 1.0f };
|
GLfloat ambientSource[] = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||||
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientSource);
|
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientSource);
|
||||||
GLfloat specularReflectance[] = { 0.3f, 0.3f, 0.3f, 1.0f };
|
GLfloat diffuseReflectance[] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specularReflectance);
|
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseReflectance);
|
||||||
|
|
||||||
if (g_grim->getGameType() == GType_GRIM) {
|
if (g_grim->getGameType() == GType_GRIM) {
|
||||||
glPolygonOffset(-6.0, -6.0);
|
glPolygonOffset(-6.0, -6.0);
|
||||||
|
@ -972,17 +972,17 @@ void GfxOpenGL::setupLight(Light *light, int lightId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
GLfloat diffuse[] = { 0.0f, 0.0f, 0.0f, 1.0f };
|
GLfloat lightColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||||
GLfloat specular[] = { 0.0f, 0.0f, 0.0f, 1.0f };
|
|
||||||
GLfloat lightPos[] = { 0.0f, 0.0f, 0.0f, 1.0f };
|
GLfloat lightPos[] = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||||
GLfloat lightDir[] = { 0.0f, 0.0f, -1.0f };
|
GLfloat lightDir[] = { 0.0f, 0.0f, -1.0f };
|
||||||
GLfloat cutoff = 180.0f;
|
GLfloat cutoff = 180.0f;
|
||||||
GLfloat spot_exp = 0.0f;
|
GLfloat spot_exp = 0.0f;
|
||||||
|
GLfloat q_attenuation = 1.0f;
|
||||||
|
|
||||||
GLfloat intensity = light->_intensity;
|
GLfloat intensity = light->_intensity / 15.0f;
|
||||||
diffuse[0] = ((GLfloat)light->_color.getRed() / 15.0f) * intensity;
|
lightColor[0] = (GLfloat)light->_color.getRed() * intensity;
|
||||||
diffuse[1] = ((GLfloat)light->_color.getGreen() / 15.0f) * intensity;
|
lightColor[1] = (GLfloat)light->_color.getGreen() * intensity;
|
||||||
diffuse[2] = ((GLfloat)light->_color.getBlue() / 15.0f) * intensity;
|
lightColor[2] = (GLfloat)light->_color.getBlue() * intensity;
|
||||||
|
|
||||||
if (light->_type == Light::Omni) {
|
if (light->_type == Light::Omni) {
|
||||||
lightPos[0] = light->_pos.x();
|
lightPos[0] = light->_pos.x();
|
||||||
|
@ -1000,21 +1000,18 @@ void GfxOpenGL::setupLight(Light *light, int lightId) {
|
||||||
lightDir[0] = light->_dir.x();
|
lightDir[0] = light->_dir.x();
|
||||||
lightDir[1] = light->_dir.y();
|
lightDir[1] = light->_dir.y();
|
||||||
lightDir[2] = light->_dir.z();
|
lightDir[2] = light->_dir.z();
|
||||||
specular[0] = diffuse[0];
|
|
||||||
specular[1] = diffuse[1];
|
|
||||||
specular[2] = diffuse[2];
|
|
||||||
spot_exp = 2.0f;
|
spot_exp = 2.0f;
|
||||||
cutoff = light->_penumbraangle;
|
cutoff = light->_penumbraangle;
|
||||||
|
q_attenuation = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
glDisable(GL_LIGHT0 + lightId);
|
glDisable(GL_LIGHT0 + lightId);
|
||||||
glLightfv(GL_LIGHT0 + lightId, GL_DIFFUSE, diffuse);
|
glLightfv(GL_LIGHT0 + lightId, GL_DIFFUSE, lightColor);
|
||||||
glLightfv(GL_LIGHT0 + lightId, GL_SPECULAR, specular);
|
|
||||||
glLightfv(GL_LIGHT0 + lightId, GL_POSITION, lightPos);
|
glLightfv(GL_LIGHT0 + lightId, GL_POSITION, lightPos);
|
||||||
glLightfv(GL_LIGHT0 + lightId, GL_SPOT_DIRECTION, lightDir);
|
glLightfv(GL_LIGHT0 + lightId, GL_SPOT_DIRECTION, lightDir);
|
||||||
glLightf(GL_LIGHT0 + lightId, GL_SPOT_EXPONENT, spot_exp);
|
glLightf(GL_LIGHT0 + lightId, GL_SPOT_EXPONENT, spot_exp);
|
||||||
glLightf(GL_LIGHT0 + lightId, GL_SPOT_CUTOFF, cutoff);
|
glLightf(GL_LIGHT0 + lightId, GL_SPOT_CUTOFF, cutoff);
|
||||||
glLightf(GL_LIGHT0 + lightId, GL_QUADRATIC_ATTENUATION, 0.2f);
|
glLightf(GL_LIGHT0 + lightId, GL_QUADRATIC_ATTENUATION, q_attenuation);
|
||||||
glEnable(GL_LIGHT0 + lightId);
|
glEnable(GL_LIGHT0 + lightId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,6 +103,8 @@ byte *GfxTinyGL::setupScreen(int screenW, int screenH, bool fullscreen) {
|
||||||
|
|
||||||
TGLfloat ambientSource[] = { 0.0f, 0.0f, 0.0f, 1.0f };
|
TGLfloat ambientSource[] = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||||
tglLightModelfv(TGL_LIGHT_MODEL_AMBIENT, ambientSource);
|
tglLightModelfv(TGL_LIGHT_MODEL_AMBIENT, ambientSource);
|
||||||
|
TGLfloat diffuseReflectance[] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||||
|
tglMaterialfv(TGL_FRONT, TGL_DIFFUSE, diffuseReflectance);
|
||||||
|
|
||||||
// we now generate a buffer (id 1), which we will use as a backing buffer, where the actors' clean buffers
|
// we now generate a buffer (id 1), which we will use as a backing buffer, where the actors' clean buffers
|
||||||
// will blit to. everu frame this will be blitted to screen, but the actors' buffers will be blitted to
|
// will blit to. everu frame this will be blitted to screen, but the actors' buffers will be blitted to
|
||||||
|
@ -894,11 +896,13 @@ void GfxTinyGL::setupLight(Light *light, int lightId) {
|
||||||
float lightPos[] = { 0.0f, 0.0f, 0.0f, 1.0f };
|
float lightPos[] = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||||
float lightDir[] = { 0.0f, 0.0f, -1.0f };
|
float lightDir[] = { 0.0f, 0.0f, -1.0f };
|
||||||
float cutoff = 180.0f;
|
float cutoff = 180.0f;
|
||||||
|
float spot_exp = 0.0f;
|
||||||
|
float q_attenuation = 1.0f;
|
||||||
|
|
||||||
float intensity = light->_intensity / 1.3f;
|
float intensity = light->_intensity / 15.0f;
|
||||||
lightColor[0] = ((float)light->_color.getRed() / 15.0f) * intensity;
|
lightColor[0] = (float)light->_color.getRed() * intensity;
|
||||||
lightColor[1] = ((float)light->_color.getGreen() / 15.0f) * intensity;
|
lightColor[1] = (float)light->_color.getGreen() * intensity;
|
||||||
lightColor[2] = ((float)light->_color.getBlue() / 15.0f) * intensity;
|
lightColor[2] = (float)light->_color.getBlue() * intensity;
|
||||||
|
|
||||||
if (light->_type == Light::Omni) {
|
if (light->_type == Light::Omni) {
|
||||||
lightPos[0] = light->_pos.x();
|
lightPos[0] = light->_pos.x();
|
||||||
|
@ -916,18 +920,18 @@ void GfxTinyGL::setupLight(Light *light, int lightId) {
|
||||||
lightDir[0] = light->_dir.x();
|
lightDir[0] = light->_dir.x();
|
||||||
lightDir[1] = light->_dir.y();
|
lightDir[1] = light->_dir.y();
|
||||||
lightDir[2] = light->_dir.z();
|
lightDir[2] = light->_dir.z();
|
||||||
/* FIXME: TGL_SPOT_CUTOFF should be light->_penumbraangle, but there
|
spot_exp = 2.0f;
|
||||||
seems to be a bug in tinygl as it renders differently from OpenGL.
|
cutoff = light->_penumbraangle;
|
||||||
Reproducing: turn off all lights (comment out), go to scene "al",
|
q_attenuation = 0.0f;
|
||||||
and walk along left wall under the lamp. */
|
|
||||||
cutoff = 90.0f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tglDisable(TGL_LIGHT0 + lightId);
|
tglDisable(TGL_LIGHT0 + lightId);
|
||||||
tglLightfv(TGL_LIGHT0 + lightId, TGL_DIFFUSE, lightColor);
|
tglLightfv(TGL_LIGHT0 + lightId, TGL_DIFFUSE, lightColor);
|
||||||
tglLightfv(TGL_LIGHT0 + lightId, TGL_POSITION, lightPos);
|
tglLightfv(TGL_LIGHT0 + lightId, TGL_POSITION, lightPos);
|
||||||
tglLightfv(TGL_LIGHT0 + lightId, TGL_SPOT_DIRECTION, lightDir);
|
tglLightfv(TGL_LIGHT0 + lightId, TGL_SPOT_DIRECTION, lightDir);
|
||||||
|
tglLightf(TGL_LIGHT0 + lightId, TGL_SPOT_EXPONENT, spot_exp);
|
||||||
tglLightf(TGL_LIGHT0 + lightId, TGL_SPOT_CUTOFF, cutoff);
|
tglLightf(TGL_LIGHT0 + lightId, TGL_SPOT_CUTOFF, cutoff);
|
||||||
|
tglLightf(TGL_LIGHT0 + lightId, TGL_QUADRATIC_ATTENUATION, q_attenuation);
|
||||||
tglEnable(TGL_LIGHT0 + lightId);
|
tglEnable(TGL_LIGHT0 + lightId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const float CONSTANT_ATTENUATION = 0.0;
|
const float CONSTANT_ATTENUATION = 1.0;
|
||||||
const float LINEAR_ATTENUATION = 0.0;
|
const float LINEAR_ATTENUATION = 0.0;
|
||||||
const float QUADRATIC_ATTENUATION = 1.0;
|
const float QUADRATIC_ATTENUATION = 1.0;
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ void glopLight(GLContext *c, GLParam *p) {
|
||||||
l->spot_direction.X = v.X;
|
l->spot_direction.X = v.X;
|
||||||
l->spot_direction.Y = v.Y;
|
l->spot_direction.Y = v.Y;
|
||||||
l->spot_direction.Z = v.Z;
|
l->spot_direction.Z = v.Z;
|
||||||
l->norm_spot_direction = l->spot_direction;
|
c->matrix_stack_ptr[0]->transform3x3(l->spot_direction, l->norm_spot_direction);
|
||||||
l->norm_spot_direction.normalize();
|
l->norm_spot_direction.normalize();
|
||||||
break;
|
break;
|
||||||
case TGL_SPOT_EXPONENT:
|
case TGL_SPOT_EXPONENT:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue