+ | Pixelisation when moving

This commit is contained in:
TheRedShip
2025-01-10 23:44:17 +01:00
parent bd2a371b50
commit e46f41a4b4
7 changed files with 33 additions and 7 deletions

View File

@ -42,6 +42,8 @@ class Camera
glm::vec2 getDOV(); glm::vec2 getDOV();
glm::mat4 getViewMatrix(); glm::mat4 getViewMatrix();
float getVelocity();
GPUCamera getGPUData(); GPUCamera getGPUData();
void setPosition(glm::vec3 position); void setPosition(glm::vec3 position);

View File

@ -36,6 +36,7 @@ class Window
GLFWwindow *getWindow(void) const; GLFWwindow *getWindow(void) const;
float getFps(void) const; float getFps(void) const;
int getFrameCount(void) const; int getFrameCount(void) const;
int getPixelisation(void);
private: private:
GLFWwindow *_window; GLFWwindow *_window;

View File

@ -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 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 50 255 50 0.0 0.0 0.0 //green
MAT 100 100 255 0.0 0.0 0.0 //blue MAT 100 100 255 0.0 0.0 0.0 //blue
MAT 255 100 255 0.0 0.0 0.0 //purple MAT 255 100 255 0.0 0.0 0.0 //purple

View File

@ -38,23 +38,24 @@ struct GPUCamera
float focus_distance; float focus_distance;
}; };
layout(std430, binding = 0) buffer ObjectBuffer layout(std430, binding = 1) buffer ObjectBuffer
{ {
GPUObject objects[]; GPUObject objects[];
}; };
layout(std430, binding = 1) buffer MaterialBuffer layout(std430, binding = 2) buffer MaterialBuffer
{ {
GPUMaterial materials[]; GPUMaterial materials[];
}; };
layout(std140, binding = 0) uniform CameraData layout(std140) uniform CameraData
{ {
GPUCamera camera; GPUCamera camera;
}; };
uniform int u_objectsNum; uniform int u_objectsNum;
uniform vec2 u_resolution; uniform vec2 u_resolution;
uniform int u_pixelisation;
uniform int u_frameCount; uniform int u_frameCount;
uniform float u_time; 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)) if (pixel_coords.x >= int(u_resolution.x) || pixel_coords.y >= int(u_resolution.y))
return; 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; rng_state = rng_state + u_frameCount * 719393;
vec2 jitter = randomPointInCircle(rng_state) * 1; vec2 jitter = randomPointInCircle(rng_state) * 1;
@ -222,6 +226,9 @@ void main()
imageStore(accumulation_image, pixel_coords, accum); imageStore(accumulation_image, pixel_coords, accum);
vec4 final_color = vec4(sqrt(accum.r), sqrt(accum.g), sqrt(accum.b), accum.a); 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);
} }

View File

@ -19,7 +19,7 @@ int main(int argc, char **argv)
if (argc <= 1 || !scene.parseScene(argv[1])) if (argc <= 1 || !scene.parseScene(argv[1]))
return (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"); Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/compute.glsl");
GLint max_gpu_size; 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_frameCount", window.getFrameCount());
shader.set_int("u_objectsNum", object_data.size()); 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_float("u_time", (float)(glfwGetTime()));
shader.set_vec2("u_resolution", glm::vec2(WIDTH, HEIGHT)); shader.set_vec2("u_resolution", glm::vec2(WIDTH, HEIGHT));

View File

@ -117,6 +117,11 @@ GPUCamera Camera::getGPUData()
return (data); return (data);
} }
float Camera::getVelocity()
{
return (glm::length(_velocity));
}
void Camera::setPosition(glm::vec3 position) void Camera::setPosition(glm::vec3 position)
{ {
_position = position; _position = position;

View File

@ -162,3 +162,13 @@ int Window::getFrameCount(void) const
{ {
return (_frameCount); 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);
}