diff --git a/include/Model.h b/include/Model.h index 62c9137..f2bc1ec 100644 --- a/include/Model.h +++ b/include/Model.h @@ -57,6 +57,8 @@ class Model : public Movable GLuint verteces_count; // Количество вершин GLuint first_index, indices_count; // Первый и количество индексов Texture texture_diffuse; // Диффузная текстура + Texture texture_ambient; // Текстура фонового освщения + Texture texture_specular; // Текстура зеркального отражения }; // Класс сгруппированной модели 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 4070a35..0b3c5ce 100644 --- a/src/Model.cpp +++ b/src/Model.cpp @@ -18,7 +18,7 @@ Model::Model(const Model& copy) : vao(copy.vao), verteces_count(copy.verteces_count), first_index(copy.first_index), 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), material(copy.material) +texture_diffuse(copy.texture_diffuse), texture_ambient(copy.texture_ambient), texture_specular(copy.texture_specular), material(copy.material) { } @@ -37,6 +37,9 @@ void Model::render(const GLuint &model_uniform, UBO &material_buffer, const glm: // Подключаем текстуры texture_diffuse.use(); + texture_ambient.use(); + texture_specular.use(); + // Загружаем данные о материале material_buffer.load(&material, sizeof(material)); @@ -176,6 +179,12 @@ 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; }; } @@ -304,6 +313,10 @@ GrouptedModel loadOBJtoGroupted(const char* filename, const char* mtl_directory, // Текстуры 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 0ba9351..8347d69 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -93,7 +93,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*)); // camera.move({0,0,-20});