From 93f8ab26538d9b1fd97152241d69e8d9a4298168 Mon Sep 17 00:00:00 2001 From: "re.kovalev" Date: Wed, 23 Nov 2022 14:11:49 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BA=D0=B0=D1=80=D1=82=20=D1=84=D0=BE=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D0=BE=D0=B9=20=D0=B8=20=D0=B7=D0=B5=D1=80=D0=BA=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D0=BE=D0=B9=20=D1=81=D0=BE=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D1=8F=D1=8E=D1=89=D0=B8=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/Model.h | 2 ++ include/Texture.h | 2 ++ shaders/shader.frag | 2 ++ src/Model.cpp | 13 ++++++++++++- src/Scene.cpp | 4 ++++ src/main.cpp | 2 +- 6 files changed, 23 insertions(+), 2 deletions(-) diff --git a/include/Model.h b/include/Model.h index a63627e..e89218e 100644 --- a/include/Model.h +++ b/include/Model.h @@ -88,6 +88,8 @@ class Model : public Node GLuint verteces_count; // Количество вершин size_t first_index_byteOffset, indices_count; // Сдвиг в байтах для первого и количество индексов Texture texture_diffuse; // Диффузная текстура + Texture texture_ambient; // Текстура фонового освщения + Texture texture_specular; // Текстура зеркального отражения }; #endif // MODEL_H diff --git a/include/Texture.h b/include/Texture.h index 207116f..e76b15f 100644 --- a/include/Texture.h +++ b/include/Texture.h @@ -8,6 +8,8 @@ enum TexType { TEX_DIFFUSE, + TEX_AMBIENT, + TEX_SPECULAR, TEX_AVAILABLE_COUNT }; diff --git a/shaders/shader.frag b/shaders/shader.frag index ec3724e..08d00ca 100644 --- a/shaders/shader.frag +++ b/shaders/shader.frag @@ -11,6 +11,8 @@ layout(std140, binding = 1) uniform Material }; uniform sampler2D tex_diffuse; +uniform sampler2D tex_ambient; +uniform sampler2D tex_specular; out vec4 color; diff --git a/src/Model.cpp b/src/Model.cpp index 7e4c9ec..79af549 100644 --- a/src/Model.cpp +++ b/src/Model.cpp @@ -212,7 +212,7 @@ Model::Model(const Model& copy) : Node(copy), vao(copy.vao), verteces_count(copy.verteces_count), first_index_byteOffset(copy.first_index_byteOffset), indices_count(copy.indices_count), vertex_vbo(copy.vertex_vbo), index_vbo(copy.index_vbo), normals_vbo(copy.normals_vbo), texCoords_vbo(copy.texCoords_vbo), -texture_diffuse(copy.texture_diffuse), +texture_diffuse(copy.texture_diffuse), texture_ambient(copy.texture_ambient), texture_specular(copy.texture_specular), material(copy.material) { @@ -233,6 +233,8 @@ Model& Model::operator=(const Model& other) texCoords_vbo = other.texCoords_vbo; texture_diffuse = other.texture_diffuse; + texture_ambient = other.texture_ambient; + texture_specular = other.texture_specular; material = other.material; @@ -252,6 +254,9 @@ void Model::render(const GLuint &model_uniform, UBO &material_buffer) // Подключаем текстуры texture_diffuse.use(); + texture_ambient.use(); + texture_specular.use(); + // Загружаем данные о материале material_buffer.load(&material, sizeof(material)); @@ -383,5 +388,11 @@ void Model::set_texture(Texture& texture) case TEX_DIFFUSE: texture_diffuse = texture; break; + case TEX_AMBIENT: + texture_ambient = texture; + break; + case TEX_SPECULAR: + texture_specular = texture; + break; }; } diff --git a/src/Scene.cpp b/src/Scene.cpp index 9219315..875dad3 100644 --- a/src/Scene.cpp +++ b/src/Scene.cpp @@ -208,6 +208,10 @@ Scene loadOBJtoScene(const char* filename, const char* mtl_directory, const char // Текстуры Texture diffuse(TEX_DIFFUSE, texture_directory + materials[materials_ids[i]].diffuse_texname); s->set_texture(diffuse); + Texture ambient(TEX_AMBIENT, texture_directory + materials[materials_ids[i]].ambient_texname); + s->set_texture(ambient); + Texture specular(TEX_SPECULAR, texture_directory + materials[materials_ids[i]].specular_texname); + s->set_texture(specular); // Материал s->material.ka = glm::vec3(materials[materials_ids[i]].ambient[0], materials[materials_ids[i]].ambient[1], materials[materials_ids[i]].ambient[2]); diff --git a/src/main.cpp b/src/main.cpp index bc775c7..db8fab1 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -90,7 +90,7 @@ int main(void) base.load(GL_FRAGMENT_SHADER, "shaders/shader.frag"); base.link(); // Установим значения текстур - const char* textures_base_shader_names[] = {"tex_diffuse"}; + const char* textures_base_shader_names[] = {"tex_diffuse", "tex_ambient", "tex_specular"}; base.bindTextures(textures_base_shader_names, sizeof(textures_base_shader_names)/sizeof(const char*));