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*));