diff --git a/include/Core/Engine.h b/include/Core/Engine.h index 1b05bf8..d3deed6 100755 --- a/include/Core/Engine.h +++ b/include/Core/Engine.h @@ -33,6 +33,7 @@ #include "Rendering/CModel.h" #include "Rendering/CSprite.h" #include "CTemplate.h" +#include "Rendering/CPointLight.h" #include "Transform/TransformSystem.h" namespace dd @@ -61,8 +62,30 @@ public: m_World->ComponentFactory.Register(); m_World->ComponentFactory.Register(); m_World->ComponentFactory.Register(); + m_World->ComponentFactory.Register(); m_World->Initialize(); + + //TODO: Remove tobias light-test code. + { + auto t_BrickWall = m_World->CreateEntity(); + auto transform = m_World->AddComponent(t_BrickWall); + transform->Position = glm::vec3(-2.f, 0.f, -10.f); + auto sprite = m_World->AddComponent(t_BrickWall); + //TODO: Rename SpriteFile to DiffuseTexture or similar. + sprite->SpriteFile = "Textures/Test/Brick_Diffuse.png"; + sprite->NormalTexture = "Textures/Test/Brick_Normal.png"; + sprite->SpecularTexture = "Textures/Test/Brick_Specular.png"; + } + + { + auto t_Light = m_World->CreateEntity(); + auto transform = m_World->AddComponent(t_Light); + transform->Position = glm::vec3(-1.f, 0.f, -9.f); + auto plight = m_World->AddComponent(t_Light); + plight->Radius = 10.f; + } + { auto ent = m_World->CreateEntity(); std::shared_ptr transform = m_World->AddComponent(ent); @@ -145,19 +168,21 @@ public: } } + //TODO: Add LightLoadShit + auto spriteComponent = m_World->GetComponent(entity); if (spriteComponent) { - auto textureAsset = ResourceManager::Load(spriteComponent->SpriteFile); - if (textureAsset) - { - Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity); - glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(absoluteTransform.Orientation).z, glm::vec3(0, 0, -1)); - glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position) - * glm::toMat4(orientation2D) - * glm::scale(absoluteTransform.Scale); - EnqueueSprite(textureAsset, modelMatrix, spriteComponent->Color); - } + auto texturediff = ResourceManager::Load(spriteComponent->SpriteFile); + auto texturenorm = ResourceManager::Load(spriteComponent->NormalTexture); + auto texturespec = ResourceManager::Load(spriteComponent->SpecularTexture); + + Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity); + glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(absoluteTransform.Orientation).z, glm::vec3(0, 0, -1)); + glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position) + * glm::toMat4(orientation2D) + * glm::scale(absoluteTransform.Scale); + EnqueueSprite(texturediff, texturenorm, texturespec, modelMatrix, spriteComponent->Color); } } @@ -186,17 +211,26 @@ public: } // TODO: Get this out of engine.h - void EnqueueSprite(Texture* texture, glm::mat4 modelMatrix, glm::vec4 color) + void EnqueueSprite(Texture* texture, Texture* normalTexture, Texture* specularTexture, glm::mat4 modelMatrix, glm::vec4 color) { SpriteJob job; job.TextureID = texture->ResourceID; - job.Texture = *texture; + job.DiffuseTexture = *texture; + job.NormalTexture = *normalTexture; + job.SpecularTexture = *specularTexture; job.ModelMatrix = modelMatrix; job.Color = color; m_RendererQueue.Forward.Add(job); } + void EnQueuePointLight(glm::vec3* position) + { + PointLightJob job; + job.Position = *position; + + } + private: std::shared_ptr m_ResourceManager; std::shared_ptr m_EventBroker; diff --git a/include/Core/RenderQueue.h b/include/Core/RenderQueue.h old mode 100644 new mode 100755 index 13c50a9..ccf1a3a --- a/include/Core/RenderQueue.h +++ b/include/Core/RenderQueue.h @@ -89,7 +89,9 @@ struct SpriteJob : RenderJob unsigned int TextureID; glm::mat4 ModelMatrix; - GLuint Texture; + GLuint DiffuseTexture; + GLuint NormalTexture; + GLuint SpecularTexture; glm::vec4 Color; void CalculateHash() override diff --git a/include/Rendering/CSprite.h b/include/Rendering/CSprite.h old mode 100644 new mode 100755 index 6e55d7e..9c39068 --- a/include/Rendering/CSprite.h +++ b/include/Rendering/CSprite.h @@ -34,6 +34,8 @@ struct Sprite : Component Sprite() : Color(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)) { } std::string SpriteFile; + std::string NormalTexture; + std::string SpecularTexture; glm::vec4 Color; }; diff --git a/src/game/Core/Renderer.cpp b/src/game/Core/Renderer.cpp index c22530a..fa8e88e 100755 --- a/src/game/Core/Renderer.cpp +++ b/src/game/Core/Renderer.cpp @@ -306,6 +306,7 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program) glUniform1f(glGetUniformLocation(shaderProgramHandle, "MaterialShininess"), modelJob->Shininess); + //TODO: Make sure that a normal/specular is loaded in. glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture); if (modelJob->NormalTexture != 0) { @@ -335,7 +336,11 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program) glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix)); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, spriteJob->Texture); + glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture); + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, spriteJob->NormalTexture); + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, spriteJob->SpecularTexture); glBindVertexArray(m_ScreenQuad); glDrawArrays(GL_TRIANGLES, 0, 6); diff --git a/src/game/Core/Shaders/Deferred/1/Vertex.glsl b/src/game/Core/Shaders/Deferred/1/Vertex.glsl old mode 100644 new mode 100755 index 4b4e649..8c8f058 --- a/src/game/Core/Shaders/Deferred/1/Vertex.glsl +++ b/src/game/Core/Shaders/Deferred/1/Vertex.glsl @@ -65,7 +65,7 @@ void main() + BoneWeights2[3] * Bones[int(BoneIndices2[3])]; } - gl_Position = MVP * boneTransform * vec4(Position, 1.0); + gl_Position = MVP * vec4(Position, 1.0); Output.Position = (V * M * boneTransform * vec4(Position, 1.0)).xyz; Output.Normal = (inverse(transpose(V * M)) * boneTransform * vec4(Normal, 0.0)).xyz; diff --git a/src/game/Core/Shaders/Forward/Fragment.glsl b/src/game/Core/Shaders/Forward/Fragment.glsl old mode 100644 new mode 100755 index 83279c0..144062f --- a/src/game/Core/Shaders/Forward/Fragment.glsl +++ b/src/game/Core/Shaders/Forward/Fragment.glsl @@ -84,6 +84,6 @@ void main() vec4 diffuseTexel = texture(DiffuseTexture, Input.TextureCoord); - //FragmentColor = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a); - FragmentColor = diffuseTexel; + FragmentColor = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a); + //FragmentColor = diffuseTexel; } \ No newline at end of file diff --git a/src/game/Core/Texture.cpp b/src/game/Core/Texture.cpp index 6e1b7c7..f9ba46e 100755 --- a/src/game/Core/Texture.cpp +++ b/src/game/Core/Texture.cpp @@ -24,7 +24,7 @@ dd::Texture::Texture(std::string path) std::unique_ptr image = std::make_unique(path); if (image->Width == 0 && image->Height == 0 || image->Format == Image::ImageFormat::Unknown) { - image = std::make_unique("Textures/ErrorTexture.png"); + image = std::make_unique("Textures/Core/ErrorTexture.png"); if (image->Width == 0 && image->Height == 0 || image->Format == Image::ImageFormat::Unknown) { LOG_ERROR("Couldn't even load the error texture. This is a dark day indeed."); return;