diff --git a/includes/RT/Camera.hpp b/includes/RT/Camera.hpp index 4d420a8..150e016 100644 --- a/includes/RT/Camera.hpp +++ b/includes/RT/Camera.hpp @@ -42,6 +42,8 @@ class Camera glm::vec2 getDOV(); glm::mat4 getViewMatrix(); + float getVelocity(); + GPUCamera getGPUData(); void setPosition(glm::vec3 position); diff --git a/includes/RT/Window.hpp b/includes/RT/Window.hpp index ea1891c..6944be7 100644 --- a/includes/RT/Window.hpp +++ b/includes/RT/Window.hpp @@ -36,6 +36,7 @@ class Window GLFWwindow *getWindow(void) const; float getFps(void) const; int getFrameCount(void) const; + int getPixelisation(void); private: GLFWwindow *_window; diff --git a/scenes/test.rt b/scenes/test.rt index d04c69a..ac12ad2 100644 --- a/scenes/test.rt +++ b/scenes/test.rt @@ -2,7 +2,7 @@ CAM -0.0970577 1.63916 1.69444 -13.6 -84 0 4 MAT 200 200 200 0.0 0.0 0.0 //white -MAT 255 50 50 0.0 1.0 1.0 //red +MAT 255 50 50 0.0 1.0 0.0 //red MAT 50 255 50 0.0 0.0 0.0 //green MAT 100 100 255 0.0 0.0 0.0 //blue MAT 255 100 255 0.0 0.0 0.0 //purple diff --git a/shaders/compute.glsl b/shaders/compute.glsl index 3d176bb..f99683d 100644 --- a/shaders/compute.glsl +++ b/shaders/compute.glsl @@ -38,23 +38,24 @@ struct GPUCamera float focus_distance; }; -layout(std430, binding = 0) buffer ObjectBuffer +layout(std430, binding = 1) buffer ObjectBuffer { GPUObject objects[]; }; -layout(std430, binding = 1) buffer MaterialBuffer +layout(std430, binding = 2) buffer MaterialBuffer { GPUMaterial materials[]; }; -layout(std140, binding = 0) uniform CameraData +layout(std140) uniform CameraData { GPUCamera camera; }; uniform int u_objectsNum; uniform vec2 u_resolution; +uniform int u_pixelisation; uniform int u_frameCount; uniform float u_time; @@ -203,7 +204,10 @@ void main() if (pixel_coords.x >= int(u_resolution.x) || pixel_coords.y >= int(u_resolution.y)) return; - uint rng_state = uint(u_resolution.x) * uint(pixel_coords.y) + pixel_coords.x; + if (u_pixelisation != 1 && (uint(pixel_coords.x) % u_pixelisation != 0 || uint(pixel_coords.y) % u_pixelisation != 0)) + return; + + uint rng_state = uint(u_resolution.x) * uint(pixel_coords.y) + uint(pixel_coords.x); rng_state = rng_state + u_frameCount * 719393; vec2 jitter = randomPointInCircle(rng_state) * 1; @@ -222,6 +226,9 @@ void main() imageStore(accumulation_image, pixel_coords, accum); vec4 final_color = vec4(sqrt(accum.r), sqrt(accum.g), sqrt(accum.b), accum.a); - imageStore(output_image, pixel_coords, final_color); + + for (int y = 0; y < u_pixelisation; y++) + for (int x = 0; x < u_pixelisation; x++) + imageStore(output_image, pixel_coords + ivec2(x, y), final_color); } diff --git a/srcs/RT.cpp b/srcs/RT.cpp index 89b0725..f21935c 100644 --- a/srcs/RT.cpp +++ b/srcs/RT.cpp @@ -19,7 +19,7 @@ int main(int argc, char **argv) if (argc <= 1 || !scene.parseScene(argv[1])) return (1); - Window window(&scene, WIDTH, HEIGHT, "RT_GPU", 0); + Window window(&scene, WIDTH, HEIGHT, "RT_GPU", 5); Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/compute.glsl"); GLint max_gpu_size; @@ -72,6 +72,7 @@ int main(int argc, char **argv) shader.set_int("u_frameCount", window.getFrameCount()); shader.set_int("u_objectsNum", object_data.size()); + shader.set_int("u_pixelisation", window.getPixelisation() * 10 + 1); shader.set_float("u_time", (float)(glfwGetTime())); shader.set_vec2("u_resolution", glm::vec2(WIDTH, HEIGHT)); diff --git a/srcs/class/Camera.cpp b/srcs/class/Camera.cpp index 8dc05bc..2487e02 100644 --- a/srcs/class/Camera.cpp +++ b/srcs/class/Camera.cpp @@ -117,6 +117,11 @@ GPUCamera Camera::getGPUData() return (data); } +float Camera::getVelocity() +{ + return (glm::length(_velocity)); +} + void Camera::setPosition(glm::vec3 position) { _position = position; diff --git a/srcs/class/Window.cpp b/srcs/class/Window.cpp index c9ff5f0..e491026 100644 --- a/srcs/class/Window.cpp +++ b/srcs/class/Window.cpp @@ -162,3 +162,13 @@ int Window::getFrameCount(void) const { return (_frameCount); } + +int Window::getPixelisation(void) +{ + bool mouse = glfwGetMouseButton(_window, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS; + bool movement = _scene->getCamera()->getVelocity() > 0.0f; + + if (mouse || movement) + return (1); + return (0); +} \ No newline at end of file