|
@@ -1,17 +1,10 @@
|
|
#include "client/Engine.h"
|
|
#include "client/Engine.h"
|
|
#include "client/rendering/wrapper/GLFWWrapper.h"
|
|
#include "client/rendering/wrapper/GLFWWrapper.h"
|
|
|
|
|
|
-bool Engine::useSSAO = true;
|
|
+Engine::Engine(Shaders& shaders, Framebuffers& fb, Camera& camera, const WindowSize& size,
|
|
-
|
|
+ RenderSettings& renderSettings) :
|
|
-float Engine::testRadius = 0.0005;
|
|
+shaders(shaders), fb(fb), camera(camera), size(size), renderSettings(renderSettings), frustum(60.0f, 0.1f, 80.0f),
|
|
-float Engine::testBias = 0.0005;
|
|
+ssaoNoise(4, 4) {
|
|
-bool Engine::ortho = false;
|
|
|
|
-Vector Engine::testOrthoCenter;
|
|
|
|
-
|
|
|
|
-Engine::Engine(Shaders& shaders, Framebuffers& fb, const Keys& keys, const MouseButtons& buttons, Camera& camera,
|
|
|
|
- Ray& ray, const Clock& fps, const WindowSize& size) :
|
|
|
|
-shaders(shaders), fb(fb), keys(keys), buttons(buttons), game(keys, buttons, camera, ray), camera(camera),
|
|
|
|
-frustum(60.0f, 0.1f, 80.0f), ssaoNoise(4, 4), fps(fps), size(size), running(!shaders.hasError() && !fb.hasError()) {
|
|
|
|
rectangle.add( {-1, -1, 0, 0, 0, 0, 0, 0});
|
|
rectangle.add( {-1, -1, 0, 0, 0, 0, 0, 0});
|
|
rectangle.add( {1, 1, 0, 1, 1, 0, 0, 0});
|
|
rectangle.add( {1, 1, 0, 1, 1, 0, 0, 0});
|
|
rectangle.add( {-1, 1, 0, 0, 1, 0, 0, 0});
|
|
rectangle.add( {-1, 1, 0, 0, 1, 0, 0, 0});
|
|
@@ -21,45 +14,21 @@ frustum(60.0f, 0.1f, 80.0f), ssaoNoise(4, 4), fps(fps), size(size), running(!sha
|
|
rectangle.build();
|
|
rectangle.build();
|
|
}
|
|
}
|
|
|
|
|
|
-bool Engine::isRunning() const {
|
|
+void Engine::renderTick(float lag, const Game& game) {
|
|
- return running;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void Engine::renderTick(float lag) {
|
|
|
|
camera.update(lag);
|
|
camera.update(lag);
|
|
updateWorldProjection();
|
|
updateWorldProjection();
|
|
updateWorldView();
|
|
updateWorldView();
|
|
|
|
|
|
- renderShadow(lag);
|
|
+ renderShadow(lag, game);
|
|
- renderWorld(lag);
|
|
+ renderWorld(lag, game);
|
|
- if(Engine::useSSAO) {
|
|
+ if(renderSettings.useSSAO) {
|
|
renderSSAO();
|
|
renderSSAO();
|
|
}
|
|
}
|
|
renderPostWorld();
|
|
renderPostWorld();
|
|
- renderTextOverlay(lag);
|
|
+ renderTextOverlay(lag, game);
|
|
}
|
|
}
|
|
|
|
|
|
-void Engine::tick() {
|
|
+void Engine::renderShadow(float lag, const Game& game) {
|
|
- game.tick();
|
|
|
|
- if(keys.test5.getDownTime() == 1) {
|
|
|
|
- ortho = !ortho;
|
|
|
|
- }
|
|
|
|
- if(keys.test.isDown()) {
|
|
|
|
-
|
|
|
|
- testRadius /= 0.95f;
|
|
|
|
- }
|
|
|
|
- if(keys.test2.isDown()) {
|
|
|
|
- testRadius *= 0.95f;
|
|
|
|
- }
|
|
|
|
- if(keys.test3.isDown()) {
|
|
|
|
- testBias /= 0.95f;
|
|
|
|
- }
|
|
|
|
- if(keys.test4.isDown()) {
|
|
|
|
- testBias *= 0.95f;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void Engine::renderShadow(float lag) {
|
|
|
|
fb.shadow.bind();
|
|
fb.shadow.bind();
|
|
glEnable(GL_DEPTH_TEST);
|
|
glEnable(GL_DEPTH_TEST);
|
|
shaders.shadow.use();
|
|
shaders.shadow.use();
|
|
@@ -73,7 +42,7 @@ void Engine::renderShadow(float lag) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-void Engine::renderWorld(float lag) {
|
|
+void Engine::renderWorld(float lag, const Game& game) {
|
|
fb.world.bind();
|
|
fb.world.bind();
|
|
glEnable(GL_DEPTH_TEST);
|
|
glEnable(GL_DEPTH_TEST);
|
|
shaders.world.use();
|
|
shaders.world.use();
|
|
@@ -89,8 +58,8 @@ void Engine::renderWorld(float lag) {
|
|
model.clear();
|
|
model.clear();
|
|
shaders.world.setMatrix("model", model.get().getValues());
|
|
shaders.world.setMatrix("model", model.get().getValues());
|
|
fb.shadow.bindDepthTexture(1);
|
|
fb.shadow.bindDepthTexture(1);
|
|
- shaders.world.setFloat("radius", Engine::testRadius);
|
|
+ shaders.world.setFloat("radius", renderSettings.testRadius);
|
|
- shaders.world.setFloat("bias", Engine::testBias);
|
|
+ shaders.world.setFloat("bias", renderSettings.testBias);
|
|
game.renderWorld(lag, model, shaders.world);
|
|
game.renderWorld(lag, model, shaders.world);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -127,11 +96,11 @@ void Engine::renderPostWorld() {
|
|
fb.ssaoBlur.bindRedTexture(1);
|
|
fb.ssaoBlur.bindRedTexture(1);
|
|
fb.world.bindRedTexture(2);
|
|
fb.world.bindRedTexture(2);
|
|
fb.world.bindNormalTexture(3);
|
|
fb.world.bindNormalTexture(3);
|
|
- shaders.postWorld.setInt("useSSAO", Engine::useSSAO);
|
|
+ shaders.postWorld.setInt("useSSAO", renderSettings.useSSAO);
|
|
rectangle.draw();
|
|
rectangle.draw();
|
|
}
|
|
}
|
|
|
|
|
|
-void Engine::renderTextOverlay(float lag) {
|
|
+void Engine::renderTextOverlay(float lag, const Game& game) {
|
|
glDisable(GL_DEPTH_TEST);
|
|
glDisable(GL_DEPTH_TEST);
|
|
shaders.text.use();
|
|
shaders.text.use();
|
|
|
|
|
|
@@ -147,9 +116,6 @@ void Engine::renderTextOverlay(float lag) {
|
|
glEnable(GL_BLEND);
|
|
glEnable(GL_BLEND);
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
glBlendEquation(GL_FUNC_ADD);
|
|
glBlendEquation(GL_FUNC_ADD);
|
|
- char buffer[50];
|
|
|
|
- snprintf(buffer, 50, "FPS: %f %f %f", fps.getUpdatesPerSecond(), Engine::testRadius, Engine::testBias);
|
|
|
|
- fontRenderer.drawString(20, 20, buffer);
|
|
|
|
game.renderTextOverlay(lag, model, shaders.text, fontRenderer);
|
|
game.renderTextOverlay(lag, model, shaders.text, fontRenderer);
|
|
glDisable(GL_BLEND);
|
|
glDisable(GL_BLEND);
|
|
}
|
|
}
|
|
@@ -158,52 +124,56 @@ void Engine::updateWorldProjection() {
|
|
frustum.setProjection(worldProj, size.width, size.height);
|
|
frustum.setProjection(worldProj, size.width, size.height);
|
|
|
|
|
|
|
|
|
|
-
|
|
+ const float fovY = 60.0f;
|
|
|
|
+ const float nearClip = 0.1f;
|
|
|
|
+ const float farClip = 80.0f;
|
|
|
|
+
|
|
|
|
+ float tan = tanf((0.5f * fovY) * M_PI / 180.0f);
|
|
float aspect = (float) size.width / size.height;
|
|
float aspect = (float) size.width / size.height;
|
|
-
|
|
+
|
|
float closeFarClip = 4;
|
|
float closeFarClip = 4;
|
|
float nearHigh = tan * nearClip;
|
|
float nearHigh = tan * nearClip;
|
|
float nearWidth = nearHigh * aspect;
|
|
float nearWidth = nearHigh * aspect;
|
|
float farHigh = tan * closeFarClip;
|
|
float farHigh = tan * closeFarClip;
|
|
float farWidth = farHigh * aspect;
|
|
float farWidth = farHigh * aspect;
|
|
|
|
|
|
- Vector farCenter = cam.getPosition();
|
|
+ Vector farCenter = camera.getPosition();
|
|
- farCenter.addMul(cam.getFront(), closeFarClip);
|
|
+ farCenter.addMul(camera.getBack(), -closeFarClip);
|
|
|
|
|
|
Vector farTopLeft = farCenter;
|
|
Vector farTopLeft = farCenter;
|
|
- farTopLeft.addMul(cam.getLeft(), farWidth);
|
|
+ farTopLeft.addMul(camera.getRight(), -farWidth);
|
|
- farTopLeft.addMul(cam.getUp(), farHigh);
|
|
+ farTopLeft.addMul(camera.getUp(), farHigh);
|
|
|
|
|
|
Vector farBottomLeft = farCenter;
|
|
Vector farBottomLeft = farCenter;
|
|
- farBottomLeft.addMul(cam.getLeft(), farWidth);
|
|
+ farBottomLeft.addMul(camera.getRight(), -farWidth);
|
|
- farBottomLeft.addMul(cam.getDown(), farHigh);
|
|
+ farBottomLeft.addMul(camera.getUp(), -farHigh);
|
|
|
|
|
|
Vector farTopRight = farCenter;
|
|
Vector farTopRight = farCenter;
|
|
- farTopRight.addMul(cam.getRight(), farWidth);
|
|
+ farTopRight.addMul(camera.getRight(), farWidth);
|
|
- farTopRight.addMul(cam.getUp(), farHigh);
|
|
+ farTopRight.addMul(camera.getUp(), farHigh);
|
|
|
|
|
|
Vector farBottomRight = farCenter;
|
|
Vector farBottomRight = farCenter;
|
|
- farBottomRight.addMul(cam.getRight(), farWidth);
|
|
+ farBottomRight.addMul(camera.getRight(), farWidth);
|
|
- farBottomRight.addMul(cam.getDown(), farHigh);
|
|
+ farBottomRight.addMul(camera.getUp(), -farHigh);
|
|
|
|
|
|
- Vector nearCenter = cam.getPosition();
|
|
+ Vector nearCenter = camera.getPosition();
|
|
- nearCenter.addMul(cam.getFront(), nearClip);
|
|
+ nearCenter.addMul(camera.getBack(), -nearClip);
|
|
|
|
|
|
Vector nearTopLeft = nearCenter;
|
|
Vector nearTopLeft = nearCenter;
|
|
- nearTopLeft.addMul(cam.getLeft(), nearWidth);
|
|
+ nearTopLeft.addMul(camera.getRight(), -nearWidth);
|
|
- nearTopLeft.addMul(cam.getUp(), nearHigh);
|
|
+ nearTopLeft.addMul(camera.getUp(), nearHigh);
|
|
|
|
|
|
Vector nearBottomLeft = nearCenter;
|
|
Vector nearBottomLeft = nearCenter;
|
|
- nearBottomLeft.addMul(cam.getLeft(), nearWidth);
|
|
+ nearBottomLeft.addMul(camera.getRight(), -nearWidth);
|
|
- nearBottomLeft.addMul(cam.getDown(), nearHigh);
|
|
+ nearBottomLeft.addMul(camera.getUp(), -nearHigh);
|
|
|
|
|
|
Vector nearTopRight = nearCenter;
|
|
Vector nearTopRight = nearCenter;
|
|
- nearTopRight.addMul(cam.getRight(), nearWidth);
|
|
+ nearTopRight.addMul(camera.getRight(), nearWidth);
|
|
- nearTopRight.addMul(cam.getUp(), nearHigh);
|
|
+ nearTopRight.addMul(camera.getUp(), nearHigh);
|
|
|
|
|
|
Vector nearBottomRight = nearCenter;
|
|
Vector nearBottomRight = nearCenter;
|
|
- nearBottomRight.addMul(cam.getRight(), nearWidth);
|
|
+ nearBottomRight.addMul(camera.getRight(), nearWidth);
|
|
- nearBottomRight.addMul(cam.getDown(), nearHigh);
|
|
+ nearBottomRight.addMul(camera.getUp(), -nearHigh);
|
|
|
|
|
|
Vector light(-0.280166, -0.573576, -0.769751);
|
|
Vector light(-0.280166, -0.573576, -0.769751);
|
|
Vector lightLeft = light;
|
|
Vector lightLeft = light;
|
|
@@ -260,22 +230,20 @@ void Engine::updateWorldProjection() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- testOrthoCenter = nearCenter;
|
|
+ renderSettings.testOrthoCenter = nearCenter;
|
|
- testOrthoCenter.addMul(cam.getFront(), closeFarClip * 0.5f);
|
|
+ renderSettings.testOrthoCenter.addMul(camera.getBack(), -closeFarClip * 0.5f);
|
|
|
|
|
|
- if(ortho) {
|
|
+ if(renderSettings.ortho) {
|
|
worldProj.setToIdentity();
|
|
worldProj.setToIdentity();
|
|
worldProj.set(0, 2.0f / lightWidth);
|
|
worldProj.set(0, 2.0f / lightWidth);
|
|
worldProj.set(5, 2.0f / lightHeight);
|
|
worldProj.set(5, 2.0f / lightHeight);
|
|
worldProj.set(10, -2.0f / (farClip - nearClip));
|
|
worldProj.set(10, -2.0f / (farClip - nearClip));
|
|
}
|
|
}
|
|
|
|
|
|
- if(once) {
|
|
+ worldShadowProj.setToIdentity();
|
|
- worldShadowProj.setToIdentity();
|
|
+ worldShadowProj.set(0, 2.0f / lightWidth);
|
|
- worldShadowProj.set(0, 2.0f / lightWidth);
|
|
+ worldShadowProj.set(5, 2.0f / lightHeight);
|
|
- worldShadowProj.set(5, 2.0f / lightHeight);
|
|
+ worldShadowProj.set(10, -2.0f / (farClip - nearClip));
|
|
- worldShadowProj.set(10, -2.0f / (farClip - nearClip));
|
|
|
|
- }*/
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void Engine::updateWorldView() {
|
|
void Engine::updateWorldView() {
|
|
@@ -284,11 +252,11 @@ void Engine::updateWorldView() {
|
|
Vector back = camera.getBack();
|
|
Vector back = camera.getBack();
|
|
Vector pos = camera.getPosition();
|
|
Vector pos = camera.getPosition();
|
|
|
|
|
|
- if(ortho) {
|
|
+ if(renderSettings.ortho) {
|
|
right.set(0.939693f, 0.0f, -0.34202f);
|
|
right.set(0.939693f, 0.0f, -0.34202f);
|
|
back.set(0.280166f, 0.573576f, 0.769751f);
|
|
back.set(0.280166f, 0.573576f, 0.769751f);
|
|
up.set(-0.196175f, 0.819152f, -0.538986f);
|
|
up.set(-0.196175f, 0.819152f, -0.538986f);
|
|
- pos = testOrthoCenter;
|
|
+ pos = renderSettings.testOrthoCenter;
|
|
}
|
|
}
|
|
|
|
|
|
worldView.set(0, right.getX());
|
|
worldView.set(0, right.getX());
|
|
@@ -304,14 +272,11 @@ void Engine::updateWorldView() {
|
|
worldView.set(13, up.dotInverse(pos));
|
|
worldView.set(13, up.dotInverse(pos));
|
|
worldView.set(14, back.dotInverse(pos));
|
|
worldView.set(14, back.dotInverse(pos));
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
right.set(0.939693f, 0.0f, -0.34202f);
|
|
right.set(0.939693f, 0.0f, -0.34202f);
|
|
back.set(0.280166f, 0.573576f, 0.769751f);
|
|
back.set(0.280166f, 0.573576f, 0.769751f);
|
|
up.set(-0.196175f, 0.819152f, -0.538986f);
|
|
up.set(-0.196175f, 0.819152f, -0.538986f);
|
|
- pos = testOrthoCenter;
|
|
+ pos = renderSettings.testOrthoCenter;
|
|
|
|
|
|
-
|
|
|
|
worldShadowView.set(0, right.getX());
|
|
worldShadowView.set(0, right.getX());
|
|
worldShadowView.set(1, up.getX());
|
|
worldShadowView.set(1, up.getX());
|
|
worldShadowView.set(2, back.getX());
|
|
worldShadowView.set(2, back.getX());
|
|
@@ -324,5 +289,4 @@ void Engine::updateWorldView() {
|
|
worldShadowView.set(12, right.dotInverse(pos));
|
|
worldShadowView.set(12, right.dotInverse(pos));
|
|
worldShadowView.set(13, up.dotInverse(pos));
|
|
worldShadowView.set(13, up.dotInverse(pos));
|
|
worldShadowView.set(14, back.dotInverse(pos));
|
|
worldShadowView.set(14, back.dotInverse(pos));
|
|
-
|
|
|
|
}
|
|
}
|