+ | Material system

This commit is contained in:
TheRedShip
2024-12-24 12:02:52 +01:00
parent 216e9a684a
commit 2f217b50e9
5 changed files with 18 additions and 16 deletions

View File

@ -30,7 +30,7 @@ int main(void)
glm::vec3 position(x, y, z);
float sphereSize = 0.8f + 0.4f * sin(angle * 2.0f);
window.getScene()->addObject(std::make_unique<Sphere>(position, sphereSize, redMaterial));
window.getScene()->addObject(new Sphere(position, sphereSize, &redMaterial));
}
GLuint objectSSBO;
@ -48,7 +48,9 @@ int main(void)
glUseProgram(shader.getProgramCompute());
const std::vector<GPUObject> &gpu_data = window.getScene()->getGPUData();
window.getScene()->updateGPUData();
// Update SSBO with latest object data
glBindBuffer(GL_SHADER_STORAGE_BUFFER, objectSSBO);
glBufferData(GL_SHADER_STORAGE_BUFFER, gpu_data.size() * sizeof(GPUObject), gpu_data.data(), GL_DYNAMIC_DRAW);

View File

@ -27,9 +27,9 @@ Camera *Scene::getCamera(void) const
return (_camera);
}
void Scene::addObject(std::unique_ptr<Object> object)
void Scene::addObject(Object *object)
{
_objects.push_back(std::move(object));
_objects.push_back(object);
this->updateGPUData();
}
@ -41,13 +41,13 @@ void Scene::updateGPUData()
{
GPUObject gpuObj;
gpuObj.position = obj->getPosition();
gpuObj.color = obj->getMaterial().color;
gpuObj.roughness = obj->getMaterial().roughness;
gpuObj.specular = obj->getMaterial().specular;
gpuObj.color = obj->getMaterial()->color;
gpuObj.roughness = obj->getMaterial()->roughness;
gpuObj.specular = obj->getMaterial()->specular;
gpuObj.type = static_cast<int>(obj->getType());
if (obj->getType() == Object::Type::SPHERE) {
auto sphere = static_cast<const Sphere*>(obj.get());
auto sphere = static_cast<const Sphere*>(obj);
gpuObj.radius = sphere->getRadius();
}