Skip to content

Commit

Permalink
GRAPHICS: Implement shader-based rendering of NWN new game fog
Browse files Browse the repository at this point in the history
  • Loading branch information
vkremianskii authored and DrMcCoy committed Nov 17, 2018
1 parent bfcfc7c commit 0673b83
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/engines/nwn/gui/main/newgamefog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include <cstdlib>

#include "glm/gtc/matrix_transform.hpp"

#include "src/common/scopedptr.h"
#include "src/common/maths.h"
#include "src/common/readstream.h"
Expand Down Expand Up @@ -104,6 +106,44 @@ class NewGameFog : public Graphics::Aurora::Model_NWN {
_lastTime = curTime;
}

void renderImmediate(const glm::mat4 &parentTransform) {
uint32 curTime = EventMan.getTimestamp();

uint32 diffRotate = curTime - _timeRotate;
glm::mat4 transform = glm::mat4();
transform = glm::rotate(transform, Common::deg2rad(diffRotate / _rotateSpeed), glm::vec3(0.0f, 0.0f, -1.0f));
transform = glm::scale(transform, glm::vec3(_curZoom * 10.0f, _curZoom * 10.0f, 1.0f));

transform = glm::translate(transform, glm::vec3(_position[0], _position[1], _position[2]));
if (_orientation[0] != 0.0f ||
_orientation[1] != 0.0f ||
_orientation[2] != 0.0f) {
transform = glm::rotate(transform, _orientation[3], glm::vec3(_orientation[0], _orientation[1], _orientation[2]));
}
transform = glm::scale(transform, glm::vec3(_scale[0], _scale[1], _scale[2]));
_curZoom += ((curTime - _lastTime) / 3000.0f) * _curZoom;

if (_curFade >= 1.0f)
_fadeStep = -0.0005f - (std::rand() % 100) / 100000.0f;
if (_curFade <= 0.0f)
_fadeStep = 0.0005f + (std::rand() % 100) / 100000.0f;

_curFade += (curTime - _lastTime) * _fadeStep;
if (_curFade < 0.0f)
_curZoom = 0.8f;

for (NodeList::iterator n = _currentState->rootNodes.begin();
n != _currentState->rootNodes.end(); ++n) {
(*n)->setAlpha(_curFade);
}

Graphics::Aurora::Model_NWN::renderImmediate(parentTransform);
_absolutePosition = transform;

glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

_lastTime = curTime;
}
};


Expand Down
3 changes: 3 additions & 0 deletions src/engines/nwn/gui/main/newgamefog.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

#include "src/graphics/aurora/types.h"

#include "src/graphics/shader/shadermaterial.h"

namespace Engines {

namespace NWN {
Expand All @@ -46,6 +48,7 @@ class NewGameFogs {

private:
Common::PtrVector<Graphics::Aurora::Model> _fogs;
Graphics::Shader::ShaderMaterial *_fogMaterial;
};

} // End of namespace NWN
Expand Down

0 comments on commit 0673b83

Please sign in to comment.