Merge pull request #1220 from vpelletier/move_computations_out_of_renderer
Move computations out of renderer
This commit is contained in:
commit
f40da7598e
5 changed files with 48 additions and 27 deletions
|
@ -979,7 +979,7 @@ void GfxOpenGL::setupLight(Light *light, int lightId) {
|
||||||
GLfloat spot_exp = 0.0f;
|
GLfloat spot_exp = 0.0f;
|
||||||
GLfloat q_attenuation = 1.0f;
|
GLfloat q_attenuation = 1.0f;
|
||||||
|
|
||||||
GLfloat intensity = light->_intensity / 15.0f;
|
GLfloat intensity = light->_scaledintensity;
|
||||||
lightColor[0] = (GLfloat)light->_color.getRed() * intensity;
|
lightColor[0] = (GLfloat)light->_color.getRed() * intensity;
|
||||||
lightColor[1] = (GLfloat)light->_color.getGreen() * intensity;
|
lightColor[1] = (GLfloat)light->_color.getGreen() * intensity;
|
||||||
lightColor[2] = (GLfloat)light->_color.getBlue() * intensity;
|
lightColor[2] = (GLfloat)light->_color.getBlue() * intensity;
|
||||||
|
|
|
@ -1115,16 +1115,10 @@ void GfxOpenGLS::setupLight(Grim::Light *light, int lightId) {
|
||||||
Math::Vector4d &lightDir = _lights[lightId]._direction;
|
Math::Vector4d &lightDir = _lights[lightId]._direction;
|
||||||
Math::Vector4d &lightParams = _lights[lightId]._params;
|
Math::Vector4d &lightParams = _lights[lightId]._params;
|
||||||
|
|
||||||
float intensity = light->_intensity;
|
|
||||||
if (g_grim->getGameType() == GType_MONKEY4) {
|
|
||||||
intensity /= 255.0f;
|
|
||||||
} else {
|
|
||||||
intensity /= 15.0f;
|
|
||||||
}
|
|
||||||
lightColor.x() = (float)light->_color.getRed();
|
lightColor.x() = (float)light->_color.getRed();
|
||||||
lightColor.y() = (float)light->_color.getGreen();
|
lightColor.y() = (float)light->_color.getGreen();
|
||||||
lightColor.z() = (float)light->_color.getBlue();
|
lightColor.z() = (float)light->_color.getBlue();
|
||||||
lightColor.w() = intensity;
|
lightColor.w() = light->_scaledintensity;
|
||||||
|
|
||||||
if (light->_type == Grim::Light::Omni) {
|
if (light->_type == Grim::Light::Omni) {
|
||||||
lightPos = Math::Vector4d(light->_pos.x(), light->_pos.y(), light->_pos.z(), 1.0f);
|
lightPos = Math::Vector4d(light->_pos.x(), light->_pos.y(), light->_pos.z(), 1.0f);
|
||||||
|
@ -1134,11 +1128,9 @@ void GfxOpenGLS::setupLight(Grim::Light *light, int lightId) {
|
||||||
lightPos = Math::Vector4d(-light->_dir.x(), -light->_dir.y(), -light->_dir.z(), 0.0f);
|
lightPos = Math::Vector4d(-light->_dir.x(), -light->_dir.y(), -light->_dir.z(), 0.0f);
|
||||||
lightDir = Math::Vector4d(0.0f, 0.0f, 0.0f, -1.0f);
|
lightDir = Math::Vector4d(0.0f, 0.0f, 0.0f, -1.0f);
|
||||||
} else if (light->_type == Grim::Light::Spot) {
|
} else if (light->_type == Grim::Light::Spot) {
|
||||||
float cosPenumbra = cosf(light->_penumbraangle * M_PI / 180.0f);
|
|
||||||
float cosUmbra = cosf(light->_umbraangle * M_PI / 180.0f);
|
|
||||||
lightPos = Math::Vector4d(light->_pos.x(), light->_pos.y(), light->_pos.z(), 1.0f);
|
lightPos = Math::Vector4d(light->_pos.x(), light->_pos.y(), light->_pos.z(), 1.0f);
|
||||||
lightDir = Math::Vector4d(light->_dir.x(), light->_dir.y(), light->_dir.z(), 1.0f);
|
lightDir = Math::Vector4d(light->_dir.x(), light->_dir.y(), light->_dir.z(), 1.0f);
|
||||||
lightParams = Math::Vector4d(light->_falloffNear, light->_falloffFar, cosPenumbra, cosUmbra);
|
lightParams = Math::Vector4d(light->_falloffNear, light->_falloffFar, light->_cospenumbraangle, light->_cosumbraangle);
|
||||||
} else if (light->_type == Grim::Light::Ambient) {
|
} else if (light->_type == Grim::Light::Ambient) {
|
||||||
lightPos = Math::Vector4d(0.0f, 0.0f, 0.0f, -1.0f);
|
lightPos = Math::Vector4d(0.0f, 0.0f, 0.0f, -1.0f);
|
||||||
lightDir = Math::Vector4d(0.0f, 0.0f, 0.0f, -1.0f);
|
lightDir = Math::Vector4d(0.0f, 0.0f, 0.0f, -1.0f);
|
||||||
|
|
|
@ -899,7 +899,7 @@ void GfxTinyGL::setupLight(Light *light, int lightId) {
|
||||||
float spot_exp = 0.0f;
|
float spot_exp = 0.0f;
|
||||||
float q_attenuation = 1.0f;
|
float q_attenuation = 1.0f;
|
||||||
|
|
||||||
float intensity = light->_intensity / 15.0f;
|
float intensity = light->_scaledintensity;
|
||||||
lightColor[0] = (float)light->_color.getRed() * intensity;
|
lightColor[0] = (float)light->_color.getRed() * intensity;
|
||||||
lightColor[1] = (float)light->_color.getGreen() * intensity;
|
lightColor[1] = (float)light->_color.getGreen() * intensity;
|
||||||
lightColor[2] = (float)light->_color.getBlue() * intensity;
|
lightColor[2] = (float)light->_color.getBlue() * intensity;
|
||||||
|
|
|
@ -99,7 +99,7 @@ void Set::setupOverworldLights() {
|
||||||
l->_pos = Math::Vector3d(0, 0, 0);
|
l->_pos = Math::Vector3d(0, 0, 0);
|
||||||
l->_dir = Math::Vector3d(0, 0, 0);
|
l->_dir = Math::Vector3d(0, 0, 0);
|
||||||
l->_color = Color(255, 255, 255);
|
l->_color = Color(255, 255, 255);
|
||||||
l->_intensity = 0.5f;
|
l->setIntensity(0.5f);
|
||||||
_overworldLightsList.push_back(l);
|
_overworldLightsList.push_back(l);
|
||||||
|
|
||||||
l = new Light();
|
l = new Light();
|
||||||
|
@ -109,7 +109,7 @@ void Set::setupOverworldLights() {
|
||||||
l->_pos = Math::Vector3d(0, 0, 0);
|
l->_pos = Math::Vector3d(0, 0, 0);
|
||||||
l->_dir = Math::Vector3d(0, 0, -1);
|
l->_dir = Math::Vector3d(0, 0, -1);
|
||||||
l->_color = Color(255, 255, 255);
|
l->_color = Color(255, 255, 255);
|
||||||
l->_intensity = 0.6f;
|
l->setIntensity(0.6f);
|
||||||
_overworldLightsList.push_back(l);
|
_overworldLightsList.push_back(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -488,8 +488,10 @@ bool Set::Setup::restoreState(SaveGame *savedState) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Light::Light() : _intensity(0.0f), _umbraangle(0.0f), _penumbraangle(0.0f),
|
Light::Light() : _falloffNear(0.0f), _falloffFar(0.0f), _enabled(false), _id(0) {
|
||||||
_falloffNear(0.0f), _falloffFar(0.0f), _enabled(false), _id(0) {
|
setIntensity(0.0f);
|
||||||
|
setUmbra(0.0f);
|
||||||
|
setPenumbra(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Set::Setup::getRotation(float *x, float *y, float *z) {
|
void Set::Setup::getRotation(float *x, float *y, float *z) {
|
||||||
|
@ -540,8 +542,28 @@ void Set::Setup::setRoll(Math::Angle roll) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Light::setUmbra(float angle) {
|
||||||
|
_umbraangle = angle;
|
||||||
|
_cosumbraangle = cosf(angle * M_PI / 180.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Light::setPenumbra(float angle) {
|
||||||
|
_penumbraangle = angle;
|
||||||
|
_cospenumbraangle = cosf(angle * M_PI / 180.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Light::setIntensity(float intensity) {
|
||||||
|
_intensity = intensity;
|
||||||
|
if (g_grim->getGameType() == GType_MONKEY4) {
|
||||||
|
_scaledintensity = intensity / 255;
|
||||||
|
} else {
|
||||||
|
_scaledintensity = intensity / 15;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Light::load(TextSplitter &ts) {
|
void Light::load(TextSplitter &ts) {
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
float tmp;
|
||||||
|
|
||||||
// Light names can be null, but ts doesn't seem flexible enough to allow this
|
// Light names can be null, but ts doesn't seem flexible enough to allow this
|
||||||
if (strlen(ts.getCurrentLine()) > strlen(" light"))
|
if (strlen(ts.getCurrentLine()) > strlen(" light"))
|
||||||
|
@ -566,9 +588,12 @@ void Light::load(TextSplitter &ts) {
|
||||||
|
|
||||||
ts.scanString(" position %f %f %f", 3, &_pos.x(), &_pos.y(), &_pos.z());
|
ts.scanString(" position %f %f %f", 3, &_pos.x(), &_pos.y(), &_pos.z());
|
||||||
ts.scanString(" direction %f %f %f", 3, &_dir.x(), &_dir.y(), &_dir.z());
|
ts.scanString(" direction %f %f %f", 3, &_dir.x(), &_dir.y(), &_dir.z());
|
||||||
ts.scanString(" intensity %f", 1, &_intensity);
|
ts.scanString(" intensity %f", 1, &tmp);
|
||||||
ts.scanString(" umbraangle %f", 1, &_umbraangle);
|
setIntensity(tmp);
|
||||||
ts.scanString(" penumbraangle %f", 1, &_penumbraangle);
|
ts.scanString(" umbraangle %f", 1, &tmp);
|
||||||
|
setUmbra(tmp);
|
||||||
|
ts.scanString(" penumbraangle %f", 1, &tmp);
|
||||||
|
setPenumbra(tmp);
|
||||||
|
|
||||||
int r, g, b;
|
int r, g, b;
|
||||||
ts.scanString(" color %d %d %d", 3, &r, &g, &b);
|
ts.scanString(" color %d %d %d", 3, &r, &g, &b);
|
||||||
|
@ -600,7 +625,7 @@ void Light::loadBinary(Common::SeekableReadStream *data) {
|
||||||
_type = (LightType)data->readSint32LE();
|
_type = (LightType)data->readSint32LE();
|
||||||
|
|
||||||
data->read(v, sizeof(float));
|
data->read(v, sizeof(float));
|
||||||
_intensity = get_float(v);
|
setIntensity(get_float(v));
|
||||||
|
|
||||||
int j = data->readSint32LE();
|
int j = data->readSint32LE();
|
||||||
// This always seems to be 0
|
// This always seems to be 0
|
||||||
|
@ -615,8 +640,8 @@ void Light::loadBinary(Common::SeekableReadStream *data) {
|
||||||
data->read(v, sizeof(float) * 4);
|
data->read(v, sizeof(float) * 4);
|
||||||
_falloffNear = get_float(v);
|
_falloffNear = get_float(v);
|
||||||
_falloffFar = get_float(v + 4);
|
_falloffFar = get_float(v + 4);
|
||||||
_umbraangle = get_float(v + 8);
|
setUmbra(get_float(v + 8));
|
||||||
_penumbraangle = get_float(v + 12);
|
setPenumbra(get_float(v + 12));
|
||||||
|
|
||||||
_enabled = true;
|
_enabled = true;
|
||||||
}
|
}
|
||||||
|
@ -676,9 +701,9 @@ bool Light::restoreState(SaveGame *savedState) {
|
||||||
|
|
||||||
_color = savedState->readColor();
|
_color = savedState->readColor();
|
||||||
|
|
||||||
_intensity = savedState->readFloat();
|
setIntensity( savedState->readFloat());
|
||||||
_umbraangle = savedState->readFloat();
|
setUmbra( savedState->readFloat());
|
||||||
_penumbraangle = savedState->readFloat();
|
setPenumbra( savedState->readFloat());
|
||||||
|
|
||||||
if (savedState->saveMinorVersion() >= 20) {
|
if (savedState->saveMinorVersion() >= 20) {
|
||||||
_falloffNear = savedState->readFloat();
|
_falloffNear = savedState->readFloat();
|
||||||
|
@ -964,7 +989,7 @@ void Set::setLightIntensity(const char *light, float intensity) {
|
||||||
for (int i = 0; i < _numLights; ++i) {
|
for (int i = 0; i < _numLights; ++i) {
|
||||||
Light &l = _lights[i];
|
Light &l = _lights[i];
|
||||||
if (l._name == light) {
|
if (l._name == light) {
|
||||||
l._intensity = intensity;
|
l.setIntensity(intensity);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -972,7 +997,7 @@ void Set::setLightIntensity(const char *light, float intensity) {
|
||||||
|
|
||||||
void Set::setLightIntensity(int light, float intensity) {
|
void Set::setLightIntensity(int light, float intensity) {
|
||||||
Light &l = _lights[light];
|
Light &l = _lights[light];
|
||||||
l._intensity = intensity;
|
l.setIntensity(intensity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Set::setLightEnabled(const char *light, bool enabled) {
|
void Set::setLightEnabled(const char *light, bool enabled) {
|
||||||
|
|
|
@ -184,6 +184,9 @@ struct Light {
|
||||||
void loadBinary(Common::SeekableReadStream *data);
|
void loadBinary(Common::SeekableReadStream *data);
|
||||||
void saveState(SaveGame *savedState) const;
|
void saveState(SaveGame *savedState) const;
|
||||||
bool restoreState(SaveGame *savedState);
|
bool restoreState(SaveGame *savedState);
|
||||||
|
void setIntensity(float intensity);
|
||||||
|
void setUmbra(float angle);
|
||||||
|
void setPenumbra(float angle);
|
||||||
|
|
||||||
enum LightType {
|
enum LightType {
|
||||||
Omni = 1,
|
Omni = 1,
|
||||||
|
@ -197,6 +200,7 @@ struct Light {
|
||||||
Math::Vector3d _pos, _dir;
|
Math::Vector3d _pos, _dir;
|
||||||
Color _color;
|
Color _color;
|
||||||
float _intensity, _umbraangle, _penumbraangle, _falloffNear, _falloffFar;
|
float _intensity, _umbraangle, _penumbraangle, _falloffNear, _falloffFar;
|
||||||
|
float _scaledintensity, _cosumbraangle, _cospenumbraangle;
|
||||||
bool _enabled;
|
bool _enabled;
|
||||||
// there may be more lights with the same position, so this is used to make the sort stable
|
// there may be more lights with the same position, so this is used to make the sort stable
|
||||||
int _id;
|
int _id;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue