From 08337925fe048d2e8b746bbc82493f4c2b8603d6 Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Mon, 28 Jun 2021 21:31:26 +0500 Subject: Compacted vertices format --- cwd/assets/altcraft/shaders/vert/face.vs | 8 ++++---- src/RendererSection.cpp | 13 +++++-------- src/RendererSectionData.cpp | 2 +- src/RendererSectionData.hpp | 5 +++-- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/cwd/assets/altcraft/shaders/vert/face.vs b/cwd/assets/altcraft/shaders/vert/face.vs index e1f01fc..bea9228 100644 --- a/cwd/assets/altcraft/shaders/vert/face.vs +++ b/cwd/assets/altcraft/shaders/vert/face.vs @@ -1,9 +1,9 @@ #version 330 core -layout (location = 0) in vec4 position[4]; +layout (location = 0) in vec3 position[4]; layout (location = 4) in vec2 uv[4]; layout (location = 8) in float uvLayer; -layout (location = 9) in vec2 animation; +layout (location = 9) in float animation; layout (location = 10) in vec3 color; layout (location = 11) in vec2 light; @@ -17,9 +17,9 @@ uniform float GlobalTime; uniform mat4 projView; void main() { - gl_Position = projView * position[gl_VertexID]; + gl_Position = projView * vec4(position[gl_VertexID], 1.0f); vs_out.Color = color; vs_out.Light = light; vs_out.Texture = vec3(uv[gl_VertexID], uvLayer); - vs_out.Texture.y -= animation.x * trunc(mod(GlobalTime * 4.0f, animation.y)); + vs_out.Texture.y -= (uv[2].y - uv[0].y) * trunc(mod(GlobalTime * 4.0f, animation)); } diff --git a/src/RendererSection.cpp b/src/RendererSection.cpp index 397a660..cc58676 100644 --- a/src/RendererSection.cpp +++ b/src/RendererSection.cpp @@ -21,19 +21,19 @@ RendererSection::RendererSection(const RendererSectionData &data) { { //Cube vertices GLuint VertAttribPos = 0; - glVertexAttribPointer(VertAttribPos, 4, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)offsetof(VertexData, positions[0])); + glVertexAttribPointer(VertAttribPos, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)offsetof(VertexData, positions[0])); glEnableVertexAttribArray(VertAttribPos); glVertexAttribDivisor(VertAttribPos, 1); - glVertexAttribPointer(VertAttribPos + 1, 4, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)offsetof(VertexData, positions[1])); + glVertexAttribPointer(VertAttribPos + 1, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)offsetof(VertexData, positions[1])); glEnableVertexAttribArray(VertAttribPos + 1); glVertexAttribDivisor(VertAttribPos + 1, 1); - glVertexAttribPointer(VertAttribPos + 2, 4, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)offsetof(VertexData, positions[2])); + glVertexAttribPointer(VertAttribPos + 2, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)offsetof(VertexData, positions[2])); glEnableVertexAttribArray(VertAttribPos + 2); glVertexAttribDivisor(VertAttribPos + 2, 1); - glVertexAttribPointer(VertAttribPos + 3, 4, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)offsetof(VertexData, positions[3])); + glVertexAttribPointer(VertAttribPos + 3, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)offsetof(VertexData, positions[3])); glEnableVertexAttribArray(VertAttribPos + 3); glVertexAttribDivisor(VertAttribPos + 3, 1); glCheckError(); @@ -64,7 +64,7 @@ RendererSection::RendererSection(const RendererSectionData &data) { //Animation GLuint animationAttribPos = 9; - glVertexAttribPointer(animationAttribPos, 2, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)offsetof(VertexData, animations)); + glVertexAttribPointer(animationAttribPos, 1, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)offsetof(VertexData, animations)); glEnableVertexAttribArray(animationAttribPos); glVertexAttribDivisor(animationAttribPos, 1); @@ -74,9 +74,6 @@ RendererSection::RendererSection(const RendererSectionData &data) { glEnableVertexAttribArray(colorAttribPos); glVertexAttribDivisor(colorAttribPos, 1); - size_t m = sizeof(VertexData); - size_t d = offsetof(VertexData, lights); - //Light GLuint lightAttribPos = 11; glVertexAttribPointer(lightAttribPos, 2, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)offsetof(VertexData, lights)); diff --git a/src/RendererSectionData.cpp b/src/RendererSectionData.cpp index e74590a..2588fd6 100644 --- a/src/RendererSectionData.cpp +++ b/src/RendererSectionData.cpp @@ -62,7 +62,7 @@ void AddFacesByBlockModel(RendererSectionData &data, const BlockFaces &model, co vertexData.uvs[3] = TransformTextureCoord(face.texture, glm::vec2(0, 1), face.frames); vertexData.uvLayers = face.layer; - vertexData.animations = glm::vec2(face.texture.w / face.frames, face.frames); + vertexData.animations = face.frames; vertexData.colors = face.color; vertexData.lights = lightness; } diff --git a/src/RendererSectionData.hpp b/src/RendererSectionData.hpp index e2fd190..edd2992 100644 --- a/src/RendererSectionData.hpp +++ b/src/RendererSectionData.hpp @@ -31,12 +31,13 @@ struct SectionsData { }; struct VertexData { - glm::vec4 positions[4]; + glm::vec3 positions[4]; glm::vec2 uvs[4]; float uvLayers; - glm::vec2 animations; + float animations; glm::vec3 colors; glm::vec2 lights; + uint8_t padding[20]; }; struct RendererSectionData { -- cgit v1.2.3