mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
~ | Fixing emissive texture
This commit is contained in:
@ -333,6 +333,7 @@ void ObjParser::parseMtl(std::stringstream &input_line, Scene &scene)
|
||||
throw std::runtime_error("OBJ: syntax error while getting material texture");
|
||||
|
||||
mat->emission_texture_index = scene.getEmissionTextures().size();
|
||||
std::cout << "path " << mat->emission_texture_index << " : " << getFilePath(_filename) + path << std::endl;
|
||||
scene.addEmissionTexture(getFilePath(_filename) + path);
|
||||
}
|
||||
else
|
||||
|
@ -228,7 +228,7 @@ void Scene::addTexture(std::string path)
|
||||
|
||||
void Scene::addEmissionTexture(std::string path)
|
||||
{
|
||||
_emission_textures.push_back(path);
|
||||
_emissive_textures.push_back(path);
|
||||
}
|
||||
|
||||
bool Scene::loadTextures()
|
||||
@ -263,6 +263,35 @@ bool Scene::loadTextures()
|
||||
stbi_image_free(image);
|
||||
}
|
||||
|
||||
for (std::string &path : _emissive_textures)
|
||||
{
|
||||
int width, height, channels;
|
||||
unsigned char* image = stbi_load(path.c_str(), &width, &height, &channels, STBI_rgb_alpha);
|
||||
|
||||
if (!image)
|
||||
{
|
||||
std::cout << "Failed to load texture " << path << std::endl;
|
||||
return (false);
|
||||
}
|
||||
|
||||
std::cout << "Loaded emissive texture: " << path << " (" << width << "x" << height << ")" << std::endl;
|
||||
|
||||
GLuint textureID;
|
||||
glGenTextures(1, &textureID);
|
||||
glBindTexture(GL_TEXTURE_2D, textureID);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
_gpu_emissive_textures.push_back(textureID);
|
||||
|
||||
stbi_image_free(image);
|
||||
}
|
||||
|
||||
return (true);
|
||||
}
|
||||
|
||||
@ -309,7 +338,7 @@ std::vector<GLuint> &Scene::getTextureIDs()
|
||||
|
||||
std::vector<GLuint> &Scene::getEmissionTextureIDs()
|
||||
{
|
||||
return (_gpu_emission_textures);
|
||||
return (_gpu_emissive_textures);
|
||||
}
|
||||
|
||||
std::vector<std::string> &Scene::getTextures()
|
||||
@ -319,7 +348,7 @@ std::vector<std::string> &Scene::getTextures()
|
||||
|
||||
std::vector<std::string> &Scene::getEmissionTextures()
|
||||
{
|
||||
return (_emission_textures);
|
||||
return (_emissive_textures);
|
||||
}
|
||||
|
||||
GPUVolume &Scene::getVolume()
|
||||
|
@ -62,6 +62,7 @@ void SceneParser::parseMaterial(std::stringstream &line)
|
||||
mat->type = 0;
|
||||
|
||||
mat->texture_index = texture_index;
|
||||
mat->emission_texture_index = -1;
|
||||
_scene->addMaterial(mat);
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ Shader::Shader(std::string vertexPath, std::string fragmentPath, std::string com
|
||||
const char *fragmentCode = loadFileWithIncludes(fragmentPath);
|
||||
const char *computeCode = loadFileWithIncludes(computePath);
|
||||
|
||||
printWithLineNumbers(computeCode);
|
||||
// printWithLineNumbers(computeCode);
|
||||
|
||||
_vertex = glCreateShader(GL_VERTEX_SHADER);
|
||||
|
||||
@ -208,30 +208,31 @@ void Shader::set_mat4(const std::string &name, const glm::mat4 &value) const
|
||||
glUniformMatrix4fv(glGetUniformLocation(_program_compute, name.c_str()), 1, GL_FALSE, glm::value_ptr(value));
|
||||
}
|
||||
|
||||
void Shader::set_textures(std::vector<GLuint> textureIDs)
|
||||
void Shader::set_textures(std::vector<GLuint> texture_ids, std::vector<GLuint> emissive_texture_ids)
|
||||
{
|
||||
for (size_t i = 0; i < textureIDs.size(); i++)
|
||||
for (size_t i = 0; i < texture_ids.size(); i++)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
glBindTexture(GL_TEXTURE_2D, textureIDs[i]);
|
||||
glBindTexture(GL_TEXTURE_2D, texture_ids[i]);
|
||||
|
||||
std::string uniform_name = "textures[" + std::to_string(i) + "]";
|
||||
glUniform1i(glGetUniformLocation(_program_compute, uniform_name.c_str()), i);
|
||||
}
|
||||
}
|
||||
|
||||
void Shader::set_emission_textures(std::vector<GLuint> textureIDs)
|
||||
{
|
||||
for (size_t i = 0; i < textureIDs.size(); i++)
|
||||
size_t start_texture = texture_ids.size() + 1;
|
||||
|
||||
for (size_t i = 0; i < emissive_texture_ids.size(); i++)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
glBindTexture(GL_TEXTURE_2D, textureIDs[i]);
|
||||
GLuint currentUnit = start_texture + i;
|
||||
|
||||
std::string uniform_name = "emission_textures[" + std::to_string(i) + "]";
|
||||
glUniform1i(glGetUniformLocation(_program_compute, uniform_name.c_str()), i);
|
||||
glActiveTexture(GL_TEXTURE0 + currentUnit);
|
||||
glBindTexture(GL_TEXTURE_2D, emissive_texture_ids[i]);
|
||||
std::string uniform_name = "emissive_textures[" + std::to_string(i) + "]";
|
||||
glUniform1i(glGetUniformLocation(_program_compute, uniform_name.c_str()), currentUnit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GLuint Shader::getProgram(void) const
|
||||
{
|
||||
return (_program);
|
||||
|
Reference in New Issue
Block a user