mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 10:48:34 +02:00
+ | Material system
This commit is contained in:
@ -25,15 +25,15 @@ typedef struct s_Material
|
||||
class Object
|
||||
{
|
||||
protected:
|
||||
glm::vec3 _position;
|
||||
Material _material;
|
||||
glm::vec3 _position;
|
||||
const Material *_material;
|
||||
|
||||
public:
|
||||
Object(const glm::vec3& position, const Material& material) : _position(position), _material(material) {}
|
||||
Object(const glm::vec3& position, const Material *material) : _position(position), _material(material) {}
|
||||
virtual ~Object() = default;
|
||||
|
||||
const glm::vec3& getPosition() const { return (_position); }
|
||||
const Material& getMaterial() const { return (_material); }
|
||||
const glm::vec3 &getPosition() const { return (_position); }
|
||||
const Material *getMaterial() const { return (_material); }
|
||||
|
||||
enum class Type {
|
||||
SPHERE,
|
||||
|
@ -37,13 +37,13 @@ class Scene
|
||||
~Scene();
|
||||
|
||||
Camera *getCamera(void) const;
|
||||
void addObject(std::unique_ptr<Object> object);
|
||||
void addObject(Object *object);
|
||||
|
||||
void updateGPUData();
|
||||
const std::vector<GPUObject>& getGPUData() const;
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<Object>> _objects;
|
||||
std::vector<Object *> _objects;
|
||||
std::vector<GPUObject> _gpuObjects;
|
||||
|
||||
Camera *_camera;
|
||||
|
@ -18,7 +18,7 @@
|
||||
class Sphere : public Object
|
||||
{
|
||||
public:
|
||||
Sphere(const glm::vec3& position, float radius, const Material& material)
|
||||
Sphere(const glm::vec3& position, float radius, const Material *material)
|
||||
: Object(position, material), _radius(radius) {}
|
||||
|
||||
float getRadius() const { return (_radius); }
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user