Текстуры высот и нормалей
This commit is contained in:
parent
f50d0d13a3
commit
5d15619c96
@ -65,6 +65,8 @@ class Model : public Movable
|
||||
Texture texture_diffuse; // Диффузная текстура
|
||||
Texture texture_ambient; // Текстура фонового освщения
|
||||
Texture texture_specular; // Текстура зеркального отражения
|
||||
Texture texture_heights; // Текстура высот
|
||||
Texture texture_normals; // Текстура нормалей
|
||||
};
|
||||
|
||||
// Класс сгруппированной модели
|
||||
|
@ -10,6 +10,8 @@ enum TexType {
|
||||
TEX_DIFFUSE,
|
||||
TEX_AMBIENT,
|
||||
TEX_SPECULAR,
|
||||
TEX_HEIGHTS,
|
||||
TEX_NORMAL,
|
||||
TEX_AVAILABLE_COUNT
|
||||
};
|
||||
|
||||
|
@ -20,7 +20,8 @@ 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),
|
||||
tangent_vbo(copy.tangent_vbo), bitangent_vbo(copy.bitangent_vbo),
|
||||
texture_diffuse(copy.texture_diffuse), texture_ambient(copy.texture_ambient), texture_specular(copy.texture_specular), material(copy.material)
|
||||
texture_diffuse(copy.texture_diffuse), texture_ambient(copy.texture_ambient), texture_specular(copy.texture_specular),
|
||||
texture_heights(copy.texture_heights), texture_normals(copy.texture_normals), material(copy.material)
|
||||
{
|
||||
|
||||
}
|
||||
@ -55,7 +56,8 @@ void Model::render(ShaderProgram &shaderProgram, UBO &material_buffer, const glm
|
||||
texture_diffuse.use();
|
||||
texture_ambient.use();
|
||||
texture_specular.use();
|
||||
|
||||
texture_heights.use();
|
||||
texture_normals.use();
|
||||
|
||||
// Загружаем данные о материале
|
||||
material_buffer.load(&material, sizeof(material));
|
||||
@ -194,6 +196,12 @@ void Model::set_texture(Texture& texture)
|
||||
case TEX_SPECULAR:
|
||||
texture_specular = texture;
|
||||
break;
|
||||
case TEX_HEIGHTS:
|
||||
texture_heights = texture;
|
||||
break;
|
||||
case TEX_NORMAL:
|
||||
texture_normals = texture;
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
@ -435,6 +443,10 @@ GrouptedModel loadOBJtoGroupted(const char* filename, const char* mtl_directory,
|
||||
s->set_texture(ambient);
|
||||
Texture specular(TEX_SPECULAR, texture_directory + materials[materials_ids[i]].specular_texname);
|
||||
s->set_texture(specular);
|
||||
Texture normal(TEX_NORMAL, texture_directory + materials[materials_ids[i]].normal_texname);
|
||||
s->set_texture(normal);
|
||||
Texture heights(TEX_HEIGHTS, texture_directory + materials[materials_ids[i]].bump_texname);
|
||||
s->set_texture(heights);
|
||||
|
||||
// Материал
|
||||
s->material.ka = pow(glm::vec3(materials[materials_ids[i]].ambient[0], materials[materials_ids[i]].ambient[1], materials[materials_ids[i]].ambient[2]), glm::vec3(1/inv_gamma));
|
||||
|
@ -28,11 +28,34 @@ Texture::Texture(GLuint t, const std::string& filename)
|
||||
// Если изображение успешно считано
|
||||
if (image)
|
||||
{
|
||||
// Загрузка данных с учетом прозрачности
|
||||
if (channels == 3) // RGB
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
|
||||
else if (channels == 4) // RGBA
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB_ALPHA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
|
||||
// Выбор формата с учетом типа текстуры (нормали не sRGB) и числа каналов
|
||||
GLuint internalformat = GL_RGB, format = GL_RGB;
|
||||
switch (channels)
|
||||
{
|
||||
case 1:
|
||||
internalformat = format = GL_RED;
|
||||
break;
|
||||
case 2:
|
||||
internalformat = format = GL_RG;
|
||||
break;
|
||||
case 3:
|
||||
format = GL_RGB;
|
||||
if (type == TEX_NORMAL || type == TEX_HEIGHTS)
|
||||
internalformat = GL_RGB;
|
||||
else
|
||||
internalformat = GL_SRGB;
|
||||
break;
|
||||
case 4:
|
||||
format = GL_RGBA;
|
||||
if (type == TEX_NORMAL || type == TEX_HEIGHTS)
|
||||
internalformat = GL_RGBA;
|
||||
else
|
||||
internalformat = GL_SRGB_ALPHA;
|
||||
break;
|
||||
|
||||
}
|
||||
// Загрузка данных с учетом формата
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalformat, width, height, 0, format, GL_UNSIGNED_BYTE, image);
|
||||
|
||||
glGenerateMipmap(GL_TEXTURE_2D); // Генерация мипмапа для активной текстуры
|
||||
glBindTexture(GL_TEXTURE_2D, 0); // Отвязка активной текстуры
|
||||
@ -239,11 +262,34 @@ TextureCube::TextureCube(GLuint t, const std::string (&filename)[6])
|
||||
// Если изображение успешно считано
|
||||
if (image)
|
||||
{
|
||||
// Загрузка данных с учетом прозрачности
|
||||
if (channels == 3) // RGB
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_SRGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
|
||||
else if (channels == 4) // RGBA
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_SRGB_ALPHA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
|
||||
// Выбор формата с учетом типа текстуры (нормали не sRGB) и числа каналов
|
||||
GLuint internalformat = GL_RGB, format = GL_RGB;
|
||||
switch (channels)
|
||||
{
|
||||
case 1:
|
||||
internalformat = format = GL_RED;
|
||||
break;
|
||||
case 2:
|
||||
internalformat = format = GL_RG;
|
||||
break;
|
||||
case 3:
|
||||
format = GL_RGB;
|
||||
if (type == TEX_NORMAL || type == TEX_HEIGHTS)
|
||||
internalformat = GL_RGB;
|
||||
else
|
||||
internalformat = GL_SRGB;
|
||||
break;
|
||||
case 4:
|
||||
format = GL_RGBA;
|
||||
if (type == TEX_NORMAL || type == TEX_HEIGHTS)
|
||||
internalformat = GL_RGBA;
|
||||
else
|
||||
internalformat = GL_SRGB_ALPHA;
|
||||
break;
|
||||
|
||||
}
|
||||
// Загрузка данных с учетом формата
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internalformat, width, height, 0, format, GL_UNSIGNED_BYTE, image);
|
||||
|
||||
stbi_image_free(image); // Освобождение оперативной памяти
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ int main(void)
|
||||
gShader.load(GL_FRAGMENT_SHADER, "shaders/gshader.frag");
|
||||
gShader.link();
|
||||
// Установим значения текстур
|
||||
const char* textures_base_shader_names[] = {"tex_diffuse", "tex_ambient", "tex_specular"};
|
||||
const char* textures_base_shader_names[] = {"tex_diffuse", "tex_ambient", "tex_specular", "tex_heights", "tex_normal"};
|
||||
gShader.bindTextures(textures_base_shader_names, sizeof(textures_base_shader_names)/sizeof(const char*));
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user