+ | Texture parse

This commit is contained in:
TheRedShip
2025-01-27 16:59:06 +01:00
parent d93a7342a1
commit 1e0ff2d88d
9 changed files with 38 additions and 7 deletions

View File

@ -7,7 +7,7 @@ Pos=1645,8
Size=259,200 Size=259,200
[Window][Material] [Window][Material]
Pos=1646,214 Pos=1648,217
Size=262,299 Size=262,299
[Window][Fog settings] [Window][Fog settings]

View File

@ -23,6 +23,7 @@ typedef struct s_Material
float metallic; float metallic;
float refraction; float refraction;
int type; int type;
int texture_index;
} Material; } Material;
class Object class Object

View File

@ -106,6 +106,7 @@ class Scene
void addObject(Object *object); void addObject(Object *object);
void addMaterial(Material *material); void addMaterial(Material *material);
void addTexture(std::string path);
void updateLightAndObjects(int mat_id); void updateLightAndObjects(int mat_id);
std::set<int> getGPULights(); std::set<int> getGPULights();

View File

@ -24,6 +24,7 @@ class SceneParser
private: private:
void parseMaterial(std::stringstream &line); void parseMaterial(std::stringstream &line);
void parseTexture(std::stringstream &line);
void parseCamera(std::stringstream &line); void parseCamera(std::stringstream &line);
void parseObj(std::stringstream &line); void parseObj(std::stringstream &line);

View File

@ -105,12 +105,12 @@ uniform sampler2D sphereTexture;
void calculateLightColor(GPUMaterial mat, hitInfo hit, inout vec3 color, inout vec3 light, inout uint rng_state) void calculateLightColor(GPUMaterial mat, hitInfo hit, inout vec3 color, inout vec3 light, inout uint rng_state)
{ {
// if (objects[hit.obj_index].type == 0) if (objects[hit.obj_index].type == 0)
// { {
// vec2 uv = getSphereUV(hit.normal); vec2 uv = getSphereUV(hit.normal);
// color *= texture(sphereTexture, uv).rgb; color *= texture(sphereTexture, uv).rgb;
// } }
// else else
color *= mat.color; color *= mat.color;
light += mat.emission * mat.color; light += mat.emission * mat.color;
// light += sampleLights(hit.position, rng_state); // light += sampleLights(hit.position, rng_state);

View File

@ -79,6 +79,11 @@ int main(int argc, char **argv)
glBufferData(GL_SHADER_STORAGE_BUFFER, scene.getGPULights().size() * sizeof(int), nullptr, GL_STATIC_DRAW); glBufferData(GL_SHADER_STORAGE_BUFFER, scene.getGPULights().size() * sizeof(int), nullptr, GL_STATIC_DRAW);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, lightSSBO); 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; GLuint cameraUBO;
glGenBuffers(1, &cameraUBO); glGenBuffers(1, &cameraUBO);

View File

@ -208,6 +208,11 @@ void Scene::addMaterial(Material *material)
_gpu_materials.push_back(gpu_mat); _gpu_materials.push_back(gpu_mat);
} }
void Scene::addTexture(std::string path)
{
}
void Scene::updateLightAndObjects(int mat_id) void Scene::updateLightAndObjects(int mat_id)
{ {
for (unsigned int i = 0; i < _gpu_objects.size(); i++) for (unsigned int i = 0; i < _gpu_objects.size(); i++)

View File

@ -30,6 +30,7 @@ void SceneParser::parseMaterial(std::stringstream &line)
float rough_refrac; float rough_refrac;
float metallic; float metallic;
std::string type; std::string type;
int texture_index;
Material *mat; Material *mat;
@ -39,6 +40,9 @@ void SceneParser::parseMaterial(std::stringstream &line)
if (!(line >> type)) if (!(line >> type))
type = "LAM"; type = "LAM";
if (!(line >> texture_index))
texture_index = -1;
mat = new Material; mat = new Material;
mat->color = glm::vec3(r / 255.0f, g / 255.0f, b / 255.0f); mat->color = glm::vec3(r / 255.0f, g / 255.0f, b / 255.0f);
@ -55,6 +59,8 @@ void SceneParser::parseMaterial(std::stringstream &line)
else if (type == "TRN") else if (type == "TRN")
mat->type = 2; mat->type = 2;
mat->texture_index = texture_index;
_scene->addMaterial(mat); _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); 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) bool SceneParser::parseLine(const std::string &line)
{ {
if (line.empty() || line[0] == '#') if (line.empty() || line[0] == '#')
@ -156,6 +172,8 @@ bool SceneParser::parseLine(const std::string &line)
this->parseCamera(ss); this->parseCamera(ss);
else if (identifier == "OBJ") else if (identifier == "OBJ")
this->parseObj(ss); this->parseObj(ss);
else if (identifier == "TEX")
this->parseTexture(ss);
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {

BIN
texture.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB