diff --git a/include/Engine/Rendering/IRenderer.h b/include/Engine/Rendering/IRenderer.h index 6808f10f..1b6d945c 100644 --- a/include/Engine/Rendering/IRenderer.h +++ b/include/Engine/Rendering/IRenderer.h @@ -3,6 +3,7 @@ #include "../Common.h" #include "../OpenGL.h" +#include "../GLM.h" #include "../Core/Util/Rectangle.h" #include "Camera.h" #include "RenderQueue.h" @@ -29,6 +30,7 @@ public: } virtual void Initialize() = 0; + virtual void Update(double dt) = 0; virtual void Draw(RenderQueueCollection& rq) = 0; protected: diff --git a/include/Engine/Rendering/Renderer.h b/include/Engine/Rendering/Renderer.h index 0054f796..423365f6 100644 --- a/include/Engine/Rendering/Renderer.h +++ b/include/Engine/Rendering/Renderer.h @@ -12,20 +12,22 @@ class Renderer : public IRenderer { public: virtual void Initialize() override; + virtual void Update(double dt) override; virtual void Draw(RenderQueueCollection& rq) override; private: //----------------------Variables----------------------// RenderQueueCollection m_TempRQ; Texture* m_ErrorTexture; - + Texture* m_WhiteTexture; + float m_CameraMoveSpeed = 3.f; //----------------------Functions----------------------// void InitializeWindow(); void InitializeShaders(); //TODO: Render: Remove ModelsToDraw from Renderer. void ModelsToDraw(); void EnqueueModel(Model* model); - + void InputUpdate(double dt); //--------------------ShaderPrograms-------------------// ShaderProgram m_BasicForwardProgram; }; diff --git a/resources/Shaders/BasicForward.frag.glsl b/resources/Shaders/BasicForward.frag.glsl index 1461e51f..a7b7cb1f 100644 --- a/resources/Shaders/BasicForward.frag.glsl +++ b/resources/Shaders/BasicForward.frag.glsl @@ -8,10 +8,12 @@ uniform sampler2D texture0; in VertexData{ - vec3 VertexPosition; + vec3 Position; vec3 Normal; vec2 TextureCoordinate; -} Input; + vec4 DiffuseColor; +}Input; + out vec4 fragmentColor; @@ -19,7 +21,7 @@ out vec4 fragmentColor; void main() { vec4 texel = texture2D(texture0, Input.TextureCoordinate); - fragmentColor = texel; + fragmentColor = texel * Input.DiffuseColor; } diff --git a/resources/Shaders/BasicForward.vert.glsl b/resources/Shaders/BasicForward.vert.glsl index e5f8e7ac..20ab9051 100644 --- a/resources/Shaders/BasicForward.vert.glsl +++ b/resources/Shaders/BasicForward.vert.glsl @@ -5,20 +5,30 @@ uniform mat4 V; uniform mat4 P; layout(location = 0) in vec3 Position; -layout(location = 1) in vec2 TextureCoord; -layout(location = 2) in vec3 Normal; +layout(location = 1) in vec3 Normal; +layout(location = 2) in vec3 Tangent; +layout(location = 3) in vec3 BiTangent; +layout(location = 4) in vec2 TextureCoords; +layout(location = 5) in vec4 DiffuseVertexColor; +layout(location = 6) in vec4 SpecularVertexColor; +layout(location = 7) in vec4 BoneIndices1; +layout(location = 8) in vec4 BoneIndices2; +layout(location = 9) in vec4 BoneWeights1; +layout(location = 10) in vec4 BoneWeights2; out VertexData{ - vec3 VertexPosition; + vec3 Position; vec3 Normal; vec2 TextureCoordinate; -} Output; + vec4 DiffuseColor; +}Output; void main() { gl_Position = P*V*M * vec4(Position, 1.0); - Output.VertexPosition = Position; - Output.TextureCoordinate = TextureCoord; + Output.Position = Position; + Output.TextureCoordinate = TextureCoords; Output.Normal = Normal; + Output.DiffuseColor = DiffuseVertexColor; } \ No newline at end of file diff --git a/src/Engine/Rendering/Camera.cpp b/src/Engine/Rendering/Camera.cpp index 8896b6a8..6ddf1c6c 100644 --- a/src/Engine/Rendering/Camera.cpp +++ b/src/Engine/Rendering/Camera.cpp @@ -17,6 +17,12 @@ glm::vec3 Camera::Forward() { return m_Orientation * glm::vec3(0, 0, -1); } + +glm::vec3 Camera::Right() +{ + return m_Orientation * glm::vec3(1, 0, 0); +} + // //glm::vec3 Camera::Right() //{ diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index 39bfefd7..ec789f9c 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -13,6 +13,7 @@ void Renderer::Initialize() glfwSwapInterval(m_VSYNC); m_ErrorTexture = ResourceManager::Load("Textures/Core/ErrorTexture.png"); + m_WhiteTexture = ResourceManager::Load("Textures/Core/Blank.png"); InitializeShaders(); ModelsToDraw(); } @@ -65,8 +66,6 @@ void Renderer::InitializeShaders() m_BasicForwardProgram.Link(); } - - void Renderer::ModelsToDraw() { Model *m = ResourceManager::Load("Models/translation_widget.obj"); @@ -102,6 +101,65 @@ void Renderer::EnqueueModel(Model* model) } } +void Renderer::InputUpdate(double dt) +{ + glm::vec3 m_Position = m_Camera->Position(); + if (glfwGetKey(m_Window, GLFW_KEY_O) == GLFW_PRESS) + { + m_Position = glm::vec3(0.f, 0.f, 5.f); + } + if (glfwGetKey(m_Window, GLFW_KEY_W) == GLFW_PRESS) + { + m_Position += m_Camera->Forward() * m_CameraMoveSpeed * (float)dt; + } + if (glfwGetKey(m_Window, GLFW_KEY_S) == GLFW_PRESS) + { + m_Position -= m_Camera->Forward() * m_CameraMoveSpeed * (float)dt; + } + if (glfwGetKey(m_Window, GLFW_KEY_D) == GLFW_PRESS) + { + m_Position += m_Camera->Right() * m_CameraMoveSpeed * (float)dt; + } + if (glfwGetKey(m_Window, GLFW_KEY_A) == GLFW_PRESS) + { + m_Position -= m_Camera->Right() * m_CameraMoveSpeed * (float)dt; + } + if (glfwGetKey(m_Window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) + { + m_CameraMoveSpeed = 5.f; + } + else { + m_CameraMoveSpeed = 0.5f; + } + + if (glfwGetKey(m_Window, GLFW_KEY_SPACE) == GLFW_PRESS) { + static double mousePosX, mousePosY; + + glfwGetCursorPos(m_Window, &mousePosX, &mousePosY); + double deltaX, deltaY; + deltaX = mousePosX - (float)Resolution().Width / 2; + deltaY = mousePosY - (float)Resolution().Height / 2; + + float rotationY = -deltaY / 300.f; + float rotationX = -deltaX / 300.f; + glm::quat orientation = m_Camera->Orientation(); + + + orientation = orientation * glm::angleAxis(rotationY, glm::vec3(1, 0, 0)); + orientation = glm::angleAxis(rotationX, glm::vec3(0, 1, 0)) * orientation; + + m_Camera->SetOrientation(orientation); + + glfwSetCursorPos(m_Window, Resolution().Width / 2, Resolution().Height / 2); + } + m_Camera->SetPosition(m_Position); +} + +void Renderer::Update(double dt) +{ + InputUpdate(dt); +} + void Renderer::Draw(RenderQueueCollection& rq) { //TODO: Render: Clean up draw code @@ -130,7 +188,7 @@ void Renderer::Draw(RenderQueueCollection& rq) glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture->m_Texture); } else { glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, m_ErrorTexture->m_Texture); + glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); } glBindVertexArray(modelJob->Model->VAO); diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index a93e9b8d..5666db3a 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -49,6 +49,7 @@ void Game::Tick() m_EventBroker->Swap(); m_InputManager->Update(dt); + m_Renderer->Update(dt); m_EventBroker->Swap(); //TODO: Render: This is not used, but will be used later when we dont add models to RQ in renderer.