From cf0ed6f13f36227a8b745f476425f0a62954a323 Mon Sep 17 00:00:00 2001 From: jbb01 <32650546+jbb01@users.noreply.github.com> Date: Sat, 3 Aug 2024 03:00:11 +0200 Subject: [PATCH] apply gamma correction --- .../java/eu/jonahbauer/raytracing/render/Camera.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/jonahbauer/raytracing/render/Camera.java b/src/main/java/eu/jonahbauer/raytracing/render/Camera.java index 27d4653..beca859 100644 --- a/src/main/java/eu/jonahbauer/raytracing/render/Camera.java +++ b/src/main/java/eu/jonahbauer/raytracing/render/Camera.java @@ -21,9 +21,10 @@ public final class Camera { private final @NotNull Vec3 origin; private final @NotNull Vec3 direction; - // antialiasing + // rendering private final int samplesPerPixel = 100; private final int maxDepth = 10; + private final double gamma = 2.0; // internal properties private final @NotNull Vec3 pixelU; @@ -103,7 +104,11 @@ public final class Camera { b += color.b(); } - image.set(x, y, new Color(r / samplesPerPixel, g / samplesPerPixel, b / samplesPerPixel)); + image.set(x, y, new Color( + Math.pow(r / samplesPerPixel, 1 / gamma), + Math.pow(g / samplesPerPixel, 1 / gamma), + Math.pow(b / samplesPerPixel, 1 / gamma) + )); } }