diff --git a/Apps/CellSim/CellSimApp.cpp b/Apps/CellSim/CellSimApp.cpp index d9666c4e..31e415f6 100644 --- a/Apps/CellSim/CellSimApp.cpp +++ b/Apps/CellSim/CellSimApp.cpp @@ -46,7 +46,7 @@ namespace CS //Create cell manager and add cell renderer _cellManager = Engine::MakeScope(); - _cellManager->AddCellRenderer(1.0f, "CellShader", glm::vec3(482.0f, 2.0f, 482.0f)); + _cellManager->AddCellRenderer("CellShader", glm::vec3(482.0f, 2.0f, 482.0f)); //Create UI _interface = Engine::MakeScope(); diff --git a/Engine/Rendering/Renderer/CellManager.cpp b/Engine/Rendering/Renderer/CellManager.cpp index b2ab09a2..abbabf03 100644 --- a/Engine/Rendering/Renderer/CellManager.cpp +++ b/Engine/Rendering/Renderer/CellManager.cpp @@ -26,11 +26,11 @@ namespace Engine _cellSpawnerStorage.reserve(5); } - void CellManager::AddCellRenderer(float cellSize, const std::string& shader, const glm::vec3& worldSpawnPos) + void CellManager::AddCellRenderer(const std::string& shader, const glm::vec3& worldSpawnPos) { if(RenderManager::GetInitStatus()) { - _cellRenderer = Engine::RenderManager::AddCellRenderer(cellSize, shader, worldSpawnPos); + _cellRenderer = Engine::RenderManager::AddCellRenderer(shader, worldSpawnPos); } else { diff --git a/Engine/Rendering/Renderer/CellManager.hpp b/Engine/Rendering/Renderer/CellManager.hpp index 18906b29..01288619 100644 --- a/Engine/Rendering/Renderer/CellManager.hpp +++ b/Engine/Rendering/Renderer/CellManager.hpp @@ -17,7 +17,7 @@ namespace Engine public: CellManager(); - void AddCellRenderer(float cellSize, const std::string& shader, const glm::vec3& worldSpawnPos); + void AddCellRenderer(const std::string& shader, const glm::vec3& worldSpawnPos); void AddCell(const CellParams& cellParams); void AddCellSpawner(const CellParams& cellParams); void DeleteCells(); diff --git a/Engine/Rendering/Renderer/CellRenderer.cpp b/Engine/Rendering/Renderer/CellRenderer.cpp index 97262126..542b8319 100644 --- a/Engine/Rendering/Renderer/CellRenderer.cpp +++ b/Engine/Rendering/Renderer/CellRenderer.cpp @@ -4,8 +4,8 @@ namespace Engine { // ----- Private ----- - CellRenderer::CellRenderer(float cellSize, Shader* shader, const glm::vec3& worldSpawnPos) - : _cellSize(cellSize), _verticeCount(36), _shader(shader), _worldSpawnPos(worldSpawnPos), _modelViewStorage{glm::mat4(0.0f)} + CellRenderer::CellRenderer(Shader* shader, const glm::vec3& worldSpawnPos) + : _verticeCount(36), _shader(shader), _worldSpawnPos(worldSpawnPos), _positionStorage{glm::vec3(0.0f)} { Logger::Info("Created", "Renderer",__func__); InitGpuStorage(); @@ -21,29 +21,23 @@ namespace Engine _vboVert = MakeScope(CUBE_VERTICES, sizeof(CUBE_VERTICES), GL_STATIC_DRAW); _vao->DefineAttributes(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), nullptr); - _vboModel = MakeScope(&_modelViewStorage[0], _modelViewStorage.size() * 16 * sizeof(float), GL_DYNAMIC_DRAW); - _vao->DefineAttributes(1, 4, GL_FLOAT, GL_FALSE, 16 * sizeof(float), nullptr); - _vao->DefineAttributes(2, 4, GL_FLOAT, GL_FALSE, 16 * sizeof(float), (void*)(4 * sizeof(float))); - _vao->DefineAttributes(3, 4, GL_FLOAT, GL_FALSE, 16 * sizeof(float), (void*)(8 * sizeof(float))); - _vao->DefineAttributes(4, 4, GL_FLOAT, GL_FALSE, 16 * sizeof(float), (void*)(12 * sizeof(float))); + _vboPos = MakeScope(&_positionStorage[0], _positionStorage.size() * 3 * sizeof(float), GL_DYNAMIC_DRAW); + _vao->DefineAttributes(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), nullptr); //Set attribute divisors for per instance data _vao->AttributeDivisor(1, 1); - _vao->AttributeDivisor(2, 1); - _vao->AttributeDivisor(3, 1); - _vao->AttributeDivisor(4, 1); //Unbind everything _vao->Unbind(); _vboVert->Unbind(); - _vboModel->Unbind(); + _vboPos->Unbind(); } void CellRenderer::UpdateGpuStorage() { - _vboModel->Bind(); - _vboModel->Update(&_modelViewStorage[0], _modelViewStorage.size() * 16 * sizeof(float)); - _vboModel->Unbind(); + _vboPos->Bind(); + _vboPos->Update(&_positionStorage[0], _positionStorage.size() * 3 * sizeof(float)); + _vboPos->Unbind(); } // ----- Public ----- @@ -60,9 +54,10 @@ namespace Engine //Bind vao and vbo's _vao->Bind(); _vboVert->Bind(); - _vboModel->Bind(); + _vboPos->Bind(); //Set uniforms + _shader->SetUniformMat4f("model", glm::mat4(1.0f)); _shader->SetUniformMat4f("view", Camera3D::GetViewMatrix()); _shader->SetUniformMat4f("projection", ((SceneRenderer*)sceneRenderer)->GetProjMatrix()); @@ -73,7 +68,7 @@ namespace Engine GLCall(glDrawArraysInstanced(GL_TRIANGLES, 0, _verticeCount, cellCount)) //Unbind vao and vbo's - _vboModel->Unbind(); + _vboPos->Unbind(); _vboVert->Unbind(); _vao->Unbind(); @@ -89,9 +84,6 @@ namespace Engine void CellRenderer::UpdateModelViewStorage(uint32 index, const glm::u32vec3& cellPos) { - glm::mat4 model(1.0f); - model = glm::translate(model, _worldSpawnPos + glm::vec3(cellPos)); - model = glm::scale(model, glm::vec3(_cellSize)); - _modelViewStorage.at(index) = model; + _positionStorage.at(index) = _worldSpawnPos + glm::vec3(cellPos); } } \ No newline at end of file diff --git a/Engine/Rendering/Renderer/CellRenderer.hpp b/Engine/Rendering/Renderer/CellRenderer.hpp index ac5d136e..923761d2 100644 --- a/Engine/Rendering/Renderer/CellRenderer.hpp +++ b/Engine/Rendering/Renderer/CellRenderer.hpp @@ -21,16 +21,15 @@ namespace Engine private: Scope _vao; - Scope _vboVert, _vboModel; + Scope _vboVert, _vboPos; - float _cellSize; uint32 _verticeCount; Shader* _shader; glm::vec3 _worldSpawnPos; - std::array _modelViewStorage; + std::array _positionStorage; - CellRenderer(float cellSize, Shader* shader, const glm::vec3& worldSpawnPos); + CellRenderer(Shader* shader, const glm::vec3& worldSpawnPos); ~CellRenderer() final = default; void InitGpuStorage(); diff --git a/Engine/Rendering/Renderer/RenderManager.cpp b/Engine/Rendering/Renderer/RenderManager.cpp index 62de9d9b..5092545c 100644 --- a/Engine/Rendering/Renderer/RenderManager.cpp +++ b/Engine/Rendering/Renderer/RenderManager.cpp @@ -94,9 +94,9 @@ namespace Engine return _particleRenderer; } - CellRenderer* RenderManager::AddCellRenderer(float cellSize, const std::string& shader, const glm::vec3& worldSpawnPos) + CellRenderer* RenderManager::AddCellRenderer(const std::string& shader, const glm::vec3& worldSpawnPos) { - _cellRenderer = new CellRenderer(cellSize, ResourceManager::GetShader(shader), worldSpawnPos); + _cellRenderer = new CellRenderer(ResourceManager::GetShader(shader), worldSpawnPos); _rendererStorage.push_back(_cellRenderer); return _cellRenderer; diff --git a/Engine/Rendering/Renderer/RenderManager.hpp b/Engine/Rendering/Renderer/RenderManager.hpp index 9e1fbfe5..987b9452 100644 --- a/Engine/Rendering/Renderer/RenderManager.hpp +++ b/Engine/Rendering/Renderer/RenderManager.hpp @@ -43,7 +43,7 @@ namespace Engine uint32 count, float size, float speed, float gravityCompliance, float lifeLength, float respawnThreshold, const std::string& textureAtlas, const std::string& shader, const glm::vec3& position ); - static CellRenderer* AddCellRenderer(float cellSize, const std::string& shader, const glm::vec3& worldSpawnPos); + static CellRenderer* AddCellRenderer(const std::string& shader, const glm::vec3& worldSpawnPos); static void RenderScene(); static void RenderShadows(); diff --git a/README.md b/README.md index 6ed26e40..daa50ac0 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ Nature scene with water rendering, normal mapped objects, and a particle system Cellular automata system with 3D cells/cubes. The plan is to simulate and render >1M cells/cubes at a good framerate. The system should include physics (multithreaded) and pretty graphics (lighting, shadows). -![CellSim](Res/Screenshots/CellSim/Screenshot_CS_008.png) +![CellSim](Res/Screenshots/CellSim/Screenshot_CS_009.png) ## Building and compiling diff --git a/Res/Screenshots/CellSim/Screenshot_CS_009.png b/Res/Screenshots/CellSim/Screenshot_CS_009.png new file mode 100644 index 00000000..7fa3ecbc Binary files /dev/null and b/Res/Screenshots/CellSim/Screenshot_CS_009.png differ diff --git a/Res/Shader/CellSim/Cell_VS.glsl b/Res/Shader/CellSim/Cell_VS.glsl index 306ddf8e..2d7795a5 100644 --- a/Res/Shader/CellSim/Cell_VS.glsl +++ b/Res/Shader/CellSim/Cell_VS.glsl @@ -1,12 +1,13 @@ #version 450 core layout(location = 0) in vec3 vertexIn; -layout(location = 1) in mat4 modelIn; +layout(location = 1) in vec3 posIn; +uniform mat4 model; uniform mat4 view; uniform mat4 projection; void main() { - gl_Position = projection * view * modelIn * vec4(vertexIn, 1.0f); + gl_Position = projection * view * model * vec4(vertexIn + posIn, 1.0f); } \ No newline at end of file