From 7f2ff589ac043235eaeb9f8872a2921e74135977 Mon Sep 17 00:00:00 2001 From: SeanOMik Date: Tue, 27 Sep 2022 16:22:04 -0400 Subject: [PATCH] Remove tex_id from Vertexes --- include/simpleengine/vertex.h | 7 +++---- resources/shaders/core/3d/fragment_core.glsl | 9 +++++---- src/gfx/model.cpp | 1 - src/gfx/renderer.cpp | 1 - 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/include/simpleengine/vertex.h b/include/simpleengine/vertex.h index ccbccd7..e43b2ac 100644 --- a/include/simpleengine/vertex.h +++ b/include/simpleengine/vertex.h @@ -26,22 +26,21 @@ namespace simpleengine { glm::vec3 color; glm::vec2 tex_coord; glm::vec3 normal; - float texture_id = -1.f; LitVertex() = default; LitVertex(simpleengine::Vectorf position, glm::vec3 color, glm::vec2 tex_coord, int texture_id = -1.f) : - position(position), color(color), tex_coord(tex_coord), normal(glm::vec3(0.f)), texture_id((float) texture_id) { + position(position), color(color), tex_coord(tex_coord), normal(glm::vec3(0.f)) { } LitVertex(simpleengine::Vectorf position, glm::vec3 color, glm::vec2 tex_coord, glm::vec3 normal, int texture_id = -1.f) : - position(position), color(color), tex_coord(tex_coord), normal(normal), texture_id((float) texture_id) { + position(position), color(color), tex_coord(tex_coord), normal(normal) { } LitVertex(simpleengine::Vectorf position, glm::vec2 tex_coord, glm::vec3 normal, int texture_id = -1.f) : - position(position), color(glm::vec3(1.f)), tex_coord(tex_coord), normal(normal), texture_id((float) texture_id) { + position(position), color(glm::vec3(1.f)), tex_coord(tex_coord), normal(normal) { } }; diff --git a/resources/shaders/core/3d/fragment_core.glsl b/resources/shaders/core/3d/fragment_core.glsl index a00c4b5..e696f2b 100644 --- a/resources/shaders/core/3d/fragment_core.glsl +++ b/resources/shaders/core/3d/fragment_core.glsl @@ -9,7 +9,8 @@ in mat4 vs_transform; in vec3 vs_to_light; in vec3 vs_to_camera; -uniform sampler2D u_textures[16]; +const int SAMP_DIFFUSE = 0; +uniform sampler2D u_samplers[16]; uniform float u_texture_shine[16]; uniform float u_texture_reflectivity[16]; @@ -29,12 +30,12 @@ void main() { vec3 diffuse = brightness * light_color; // Calculate the specular - float shine_damper = u_texture_shine[0]; - float reflectivity = u_texture_reflectivity[0]; + float shine_damper = u_texture_shine[SAMP_DIFFUSE]; + float reflectivity = u_texture_reflectivity[SAMP_DIFFUSE]; vec3 final_specular = calculate_specular(unit_normal, shine_damper, reflectivity); // Combine diffuse lighting, specular, and the texture into one color. - fs_color = vec4(diffuse, 1.f) * texture(u_textures[0], vs_texcoord) + vec4(final_specular, 1.f); + fs_color = vec4(diffuse, 1.f) * texture(u_samplers[SAMP_DIFFUSE], vs_texcoord) + vec4(final_specular, 1.f); } vec3 calculate_specular(vec3 unit_normal, float shine_damper, float reflectivity) { diff --git a/src/gfx/model.cpp b/src/gfx/model.cpp index d82f968..346828a 100644 --- a/src/gfx/model.cpp +++ b/src/gfx/model.cpp @@ -68,7 +68,6 @@ namespace simpleengine::gfx { for (unsigned int i = 0; i < mesh->mNumVertices; i++) { LitVertex vertex; vertex.color = glm::vec3(1.f); - vertex.texture_id = 0; // TODO simpleengine::Vectorf position(mesh->mVertices[i].x, mesh->mVertices[i].y, mesh->mVertices[i].z); vertex.position = position; diff --git a/src/gfx/renderer.cpp b/src/gfx/renderer.cpp index 11f18a5..7368ff9 100644 --- a/src/gfx/renderer.cpp +++ b/src/gfx/renderer.cpp @@ -59,7 +59,6 @@ namespace simpleengine::gfx { vao.enable_attrib(vbo, 1, 3, GL_FLOAT, sizeof(LitVertex), offsetof(LitVertex, color), false); vao.enable_attrib(vbo, 2, 3, GL_FLOAT, sizeof(LitVertex), offsetof(LitVertex, normal), false); vao.enable_attrib(vbo, 3, 2, GL_FLOAT, sizeof(LitVertex), offsetof(LitVertex, tex_coord), false); - vao.enable_attrib(vbo, 4, 1, GL_FLOAT, sizeof(LitVertex), offsetof(LitVertex, texture_id), false); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0);