diff options
author | Peter Kohaut | 2016-09-26 23:38:35 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2016-09-29 22:33:41 +0200 |
commit | f1cb735ee07c11785f67080ea800a72dd551ae19 (patch) | |
tree | 7f67364d748a1091164ecaa98386165a76f78a8f /engines/bladerunner/set_effects.cpp | |
parent | cfc8ffed8af71714cc6378b412557d5fc03781d4 (diff) | |
download | scummvm-rg350-f1cb735ee07c11785f67080ea800a72dd551ae19.tar.gz scummvm-rg350-f1cb735ee07c11785f67080ea800a72dd551ae19.tar.bz2 scummvm-rg350-f1cb735ee07c11785f67080ea800a72dd551ae19.zip |
BLADERUNNER: added rendering support for lighting and effects, but its not working correctly yet
Diffstat (limited to 'engines/bladerunner/set_effects.cpp')
-rw-r--r-- | engines/bladerunner/set_effects.cpp | 53 |
1 files changed, 39 insertions, 14 deletions
diff --git a/engines/bladerunner/set_effects.cpp b/engines/bladerunner/set_effects.cpp index bc10a0fc2c..f4d2506292 100644 --- a/engines/bladerunner/set_effects.cpp +++ b/engines/bladerunner/set_effects.cpp @@ -2,7 +2,7 @@ namespace BladeRunner { -SetEffects::SetEffects(BladeRunnerEngine* vm) { +SetEffects::SetEffects(BladeRunnerEngine *vm) { _vm = vm; _distanceColor.r = 1.0f; @@ -23,7 +23,7 @@ SetEffects::~SetEffects() { reset(); } -void SetEffects::read(Common::ReadStream* stream, int framesCount) { +void SetEffects::read(Common::ReadStream *stream, int framesCount) { _distanceCoeficient = stream->readFloatLE(); _distanceColor.r = stream->readFloatLE(); _distanceColor.g = stream->readFloatLE(); @@ -33,9 +33,8 @@ void SetEffects::read(Common::ReadStream* stream, int framesCount) { int i; for (i = 0; i < _fogsCount; i++) { int type = stream->readUint32LE(); - Fog* fog = NULL; - switch (type) - { + Fog *fog = NULL; + switch (type) { case 0: fog = new FogCone(); break; @@ -46,8 +45,7 @@ void SetEffects::read(Common::ReadStream* stream, int framesCount) { fog = new FogBox(); break; } - if (!fog) - { + if (!fog) { //TODO exception, unknown fog type } fog->read(stream, framesCount); @@ -57,7 +55,7 @@ void SetEffects::read(Common::ReadStream* stream, int framesCount) { } void SetEffects::reset() { - Fog* fog, *nextFog; + Fog *fog, *nextFog; if (!_fogs) return; @@ -84,8 +82,8 @@ void SetEffects::setFadeDensity(float density) { _fadeDensity = density; } -void SetEffects::setFogColor(char* fogName, float r, float g, float b) { - Fog* fog = findFog(fogName); +void SetEffects::setFogColor(char *fogName, float r, float g, float b) { + Fog *fog = findFog(fogName); if (fog == nullptr) return; @@ -94,19 +92,46 @@ void SetEffects::setFogColor(char* fogName, float r, float g, float b) { fog->_fogColor.b = b; } -void SetEffects::setFogDensity(char* fogName, float density) { - Fog* fog = findFog(fogName); +void SetEffects::setFogDensity(char *fogName, float density) { + Fog *fog = findFog(fogName); if (fog == nullptr) return; fog->_fogDensity = density; } -Fog* SetEffects::findFog(char* fogName) { +void SetEffects::calculateColor(Vector3 viewPosition, Vector3 position, float *outCoeficient, Color *outColor) { + float distanceCoeficient = CLIP((position - viewPosition).length() * _distanceCoeficient, 0.0f, 1.0f); + + *outCoeficient = 1.0f - distanceCoeficient; + outColor->r = _distanceColor.r * distanceCoeficient; + outColor->g = _distanceColor.g * distanceCoeficient; + outColor->b = _distanceColor.b * distanceCoeficient; + + for (Fog *fog = this->_fogs; fog != nullptr; fog = fog->_next) { + float fogCoeficient = 0.0f; + fog->calculateCoeficient(position, viewPosition, &fogCoeficient); + if (fogCoeficient > 0.0f) { + fogCoeficient = CLIP(fog->_fogDensity * fogCoeficient, 0.0f, 1.0f); + + *outCoeficient = *outCoeficient * (1.0f - fogCoeficient); + outColor->r = outColor->r * (1.0f - fogCoeficient) + fog->_fogColor.r * fogCoeficient; + outColor->g = outColor->g * (1.0f - fogCoeficient) + fog->_fogColor.g * fogCoeficient; + outColor->b = outColor->b * (1.0f - fogCoeficient) + fog->_fogColor.b * fogCoeficient; + } + } + + *outCoeficient = *outCoeficient * (1.0f - this->_fadeDensity); + outColor->r = outColor->r * (1.0f - this->_fadeDensity) + this->_fadeColor.r * this->_fadeDensity; + outColor->g = outColor->g * (1.0f - this->_fadeDensity) + this->_fadeColor.g * this->_fadeDensity; + outColor->b = outColor->b * (1.0f - this->_fadeDensity) + this->_fadeColor.b * this->_fadeDensity; +} + +Fog *SetEffects::findFog(char *fogName) { if (!_fogs) return nullptr; - Fog* fog = _fogs; + Fog *fog = _fogs; while (fog != nullptr) { if (strcmp(fogName, fog->_name) == 0) { |