diff --git a/imgui.ini b/imgui.ini index 1ae7577..9a7500e 100644 --- a/imgui.ini +++ b/imgui.ini @@ -7,7 +7,7 @@ Pos=1645,8 Size=259,200 [Window][Material] -Pos=1646,214 +Pos=1648,217 Size=262,299 [Window][Fog settings] diff --git a/includes/RT/Object.hpp b/includes/RT/Object.hpp index 0bff2ac..583b126 100644 --- a/includes/RT/Object.hpp +++ b/includes/RT/Object.hpp @@ -23,6 +23,7 @@ typedef struct s_Material float metallic; float refraction; int type; + int texture_index; } Material; class Object diff --git a/includes/RT/Scene.hpp b/includes/RT/Scene.hpp index 9a8d2df..49b93fc 100644 --- a/includes/RT/Scene.hpp +++ b/includes/RT/Scene.hpp @@ -106,6 +106,7 @@ class Scene void addObject(Object *object); void addMaterial(Material *material); + void addTexture(std::string path); void updateLightAndObjects(int mat_id); std::set getGPULights(); diff --git a/includes/RT/SceneParser.hpp b/includes/RT/SceneParser.hpp index 142803a..59cdc0a 100644 --- a/includes/RT/SceneParser.hpp +++ b/includes/RT/SceneParser.hpp @@ -24,6 +24,7 @@ class SceneParser private: void parseMaterial(std::stringstream &line); + void parseTexture(std::stringstream &line); void parseCamera(std::stringstream &line); void parseObj(std::stringstream &line); diff --git a/shaders/light.glsl b/shaders/light.glsl index 9eb603b..e59ab7d 100644 --- a/shaders/light.glsl +++ b/shaders/light.glsl @@ -105,12 +105,12 @@ uniform sampler2D sphereTexture; void calculateLightColor(GPUMaterial mat, hitInfo hit, inout vec3 color, inout vec3 light, inout uint rng_state) { - // if (objects[hit.obj_index].type == 0) - // { - // vec2 uv = getSphereUV(hit.normal); - // color *= texture(sphereTexture, uv).rgb; - // } - // else + if (objects[hit.obj_index].type == 0) + { + vec2 uv = getSphereUV(hit.normal); + color *= texture(sphereTexture, uv).rgb; + } + else color *= mat.color; light += mat.emission * mat.color; // light += sampleLights(hit.position, rng_state); diff --git a/srcs/RT.cpp b/srcs/RT.cpp index 5b26318..3fc59b1 100644 --- a/srcs/RT.cpp +++ b/srcs/RT.cpp @@ -79,6 +79,11 @@ int main(int argc, char **argv) glBufferData(GL_SHADER_STORAGE_BUFFER, scene.getGPULights().size() * sizeof(int), nullptr, GL_STATIC_DRAW); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, lightSSBO); + GLuint textureSSBO; + glGenBuffers(1, &textureSSBO); + glBindBuffer(GL_SHADER_STORAGE_BUFFER, textureSSBO); + glBufferData(GL_SHADER_STORAGE_BUFFER, 1 * sizeof(int), nullptr, GL_STATIC_DRAW); + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, textureSSBO); GLuint cameraUBO; glGenBuffers(1, &cameraUBO); diff --git a/srcs/class/Scene.cpp b/srcs/class/Scene.cpp index 701dbb1..22d4383 100644 --- a/srcs/class/Scene.cpp +++ b/srcs/class/Scene.cpp @@ -208,6 +208,11 @@ void Scene::addMaterial(Material *material) _gpu_materials.push_back(gpu_mat); } +void Scene::addTexture(std::string path) +{ + +} + void Scene::updateLightAndObjects(int mat_id) { for (unsigned int i = 0; i < _gpu_objects.size(); i++) diff --git a/srcs/class/SceneParser.cpp b/srcs/class/SceneParser.cpp index f68aab6..50fe81d 100644 --- a/srcs/class/SceneParser.cpp +++ b/srcs/class/SceneParser.cpp @@ -30,6 +30,7 @@ void SceneParser::parseMaterial(std::stringstream &line) float rough_refrac; float metallic; std::string type; + int texture_index; Material *mat; @@ -39,6 +40,9 @@ void SceneParser::parseMaterial(std::stringstream &line) if (!(line >> type)) type = "LAM"; + if (!(line >> texture_index)) + texture_index = -1; + mat = new Material; mat->color = glm::vec3(r / 255.0f, g / 255.0f, b / 255.0f); @@ -54,6 +58,8 @@ void SceneParser::parseMaterial(std::stringstream &line) mat->type = 1; else if (type == "TRN") mat->type = 2; + + mat->texture_index = texture_index; _scene->addMaterial(mat); } @@ -122,6 +128,16 @@ void SceneParser::parseObj(std::stringstream &line) obj.parse(*_scene, glm::vec3(x, y, z), (1.0 / scale), transform); } +void SceneParser::parseTexture(std::stringstream &line) +{ + std::string path; + + if (!(line >> path)) + throw std::runtime_error("Texture: Missing texture's path"); + + _scene->addTexture(path); +} + bool SceneParser::parseLine(const std::string &line) { if (line.empty() || line[0] == '#') @@ -156,6 +172,8 @@ bool SceneParser::parseLine(const std::string &line) this->parseCamera(ss); else if (identifier == "OBJ") this->parseObj(ss); + else if (identifier == "TEX") + this->parseTexture(ss); } catch (const std::exception& e) { diff --git a/texture.jpg b/texture.jpg new file mode 100644 index 0000000..65e61c8 Binary files /dev/null and b/texture.jpg differ