Merge pull request #1220 from vpelletier/move_computations_out_of_renderer

Move computations out of renderer
This commit is contained in:
Paweł Kołodziejski 2016-01-09 12:17:35 +01:00
commit f40da7598e
5 changed files with 48 additions and 27 deletions

View file

@ -979,7 +979,7 @@ void GfxOpenGL::setupLight(Light *light, int lightId) {
GLfloat spot_exp = 0.0f;
GLfloat q_attenuation = 1.0f;
GLfloat intensity = light->_intensity / 15.0f;
GLfloat intensity = light->_scaledintensity;
lightColor[0] = (GLfloat)light->_color.getRed() * intensity;
lightColor[1] = (GLfloat)light->_color.getGreen() * intensity;
lightColor[2] = (GLfloat)light->_color.getBlue() * intensity;

View file

@ -1115,16 +1115,10 @@ void GfxOpenGLS::setupLight(Grim::Light *light, int lightId) {
Math::Vector4d &lightDir = _lights[lightId]._direction;
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.y() = (float)light->_color.getGreen();
lightColor.z() = (float)light->_color.getBlue();
lightColor.w() = intensity;
lightColor.w() = light->_scaledintensity;
if (light->_type == Grim::Light::Omni) {
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);
lightDir = Math::Vector4d(0.0f, 0.0f, 0.0f, -1.0f);
} 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);
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) {
lightPos = Math::Vector4d(0.0f, 0.0f, 0.0f, -1.0f);
lightDir = Math::Vector4d(0.0f, 0.0f, 0.0f, -1.0f);

View file

@ -899,7 +899,7 @@ void GfxTinyGL::setupLight(Light *light, int lightId) {
float spot_exp = 0.0f;
float q_attenuation = 1.0f;
float intensity = light->_intensity / 15.0f;
float intensity = light->_scaledintensity;
lightColor[0] = (float)light->_color.getRed() * intensity;
lightColor[1] = (float)light->_color.getGreen() * intensity;
lightColor[2] = (float)light->_color.getBlue() * intensity;

View file

@ -99,7 +99,7 @@ void Set::setupOverworldLights() {
l->_pos = Math::Vector3d(0, 0, 0);
l->_dir = Math::Vector3d(0, 0, 0);
l->_color = Color(255, 255, 255);
l->_intensity = 0.5f;
l->setIntensity(0.5f);
_overworldLightsList.push_back(l);
l = new Light();
@ -109,7 +109,7 @@ void Set::setupOverworldLights() {
l->_pos = Math::Vector3d(0, 0, 0);
l->_dir = Math::Vector3d(0, 0, -1);
l->_color = Color(255, 255, 255);
l->_intensity = 0.6f;
l->setIntensity(0.6f);
_overworldLightsList.push_back(l);
}
@ -488,8 +488,10 @@ bool Set::Setup::restoreState(SaveGame *savedState) {
return true;
}
Light::Light() : _intensity(0.0f), _umbraangle(0.0f), _penumbraangle(0.0f),
_falloffNear(0.0f), _falloffFar(0.0f), _enabled(false), _id(0) {
Light::Light() : _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) {
@ -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) {
char buf[256];
float tmp;
// Light names can be null, but ts doesn't seem flexible enough to allow this
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(" direction %f %f %f", 3, &_dir.x(), &_dir.y(), &_dir.z());
ts.scanString(" intensity %f", 1, &_intensity);
ts.scanString(" umbraangle %f", 1, &_umbraangle);
ts.scanString(" penumbraangle %f", 1, &_penumbraangle);
ts.scanString(" intensity %f", 1, &tmp);
setIntensity(tmp);
ts.scanString(" umbraangle %f", 1, &tmp);
setUmbra(tmp);
ts.scanString(" penumbraangle %f", 1, &tmp);
setPenumbra(tmp);
int 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();
data->read(v, sizeof(float));
_intensity = get_float(v);
setIntensity(get_float(v));
int j = data->readSint32LE();
// This always seems to be 0
@ -615,8 +640,8 @@ void Light::loadBinary(Common::SeekableReadStream *data) {
data->read(v, sizeof(float) * 4);
_falloffNear = get_float(v);
_falloffFar = get_float(v + 4);
_umbraangle = get_float(v + 8);
_penumbraangle = get_float(v + 12);
setUmbra(get_float(v + 8));
setPenumbra(get_float(v + 12));
_enabled = true;
}
@ -676,9 +701,9 @@ bool Light::restoreState(SaveGame *savedState) {
_color = savedState->readColor();
_intensity = savedState->readFloat();
_umbraangle = savedState->readFloat();
_penumbraangle = savedState->readFloat();
setIntensity( savedState->readFloat());
setUmbra( savedState->readFloat());
setPenumbra( savedState->readFloat());
if (savedState->saveMinorVersion() >= 20) {
_falloffNear = savedState->readFloat();
@ -964,7 +989,7 @@ void Set::setLightIntensity(const char *light, float intensity) {
for (int i = 0; i < _numLights; ++i) {
Light &l = _lights[i];
if (l._name == light) {
l._intensity = intensity;
l.setIntensity(intensity);
return;
}
}
@ -972,7 +997,7 @@ void Set::setLightIntensity(const char *light, float intensity) {
void Set::setLightIntensity(int light, float intensity) {
Light &l = _lights[light];
l._intensity = intensity;
l.setIntensity(intensity);
}
void Set::setLightEnabled(const char *light, bool enabled) {

View file

@ -184,6 +184,9 @@ struct Light {
void loadBinary(Common::SeekableReadStream *data);
void saveState(SaveGame *savedState) const;
bool restoreState(SaveGame *savedState);
void setIntensity(float intensity);
void setUmbra(float angle);
void setPenumbra(float angle);
enum LightType {
Omni = 1,
@ -197,6 +200,7 @@ struct Light {
Math::Vector3d _pos, _dir;
Color _color;
float _intensity, _umbraangle, _penumbraangle, _falloffNear, _falloffFar;
float _scaledintensity, _cosumbraangle, _cospenumbraangle;
bool _enabled;
// there may be more lights with the same position, so this is used to make the sort stable
int _id;