Загрузка карт фоновой и зеркальной составляющих

This commit is contained in:
parent e9dddd4dbb
commit 93f8ab2653
6 changed files with 23 additions and 2 deletions

View File

@ -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

View File

@ -8,6 +8,8 @@
enum TexType {
TEX_DIFFUSE,
TEX_AMBIENT,
TEX_SPECULAR,
TEX_AVAILABLE_COUNT
};

View File

@ -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;

View File

@ -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;
};
}

View File

@ -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]);

View File

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