summaryrefslogtreecommitdiff
path: root/src/libs/ray/ray_render.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2017-08-08 10:40:14 -0700
committerVito Caputo <vcaputo@pengaru.com>2019-11-13 02:17:54 -0800
commit8acb27a788f24f85f38cf4ca45f2c3124128fa26 (patch)
tree7b747bb9a50bf3f804ac11e03149dd347839f6fc /src/libs/ray/ray_render.c
parent448362dcd54c1275ec80d16bcb4d88732f6912f2 (diff)
ray: add rudimentary gamma correction
color banding has been quite visible, and somewhat expected with a direct conversion from the linear float color space to the 8-bit integral rgb color components. A simple lookup table is used here to non-linearly map the values, table generation is taken from Greg Ward's REAL PIXELS gem in Graphics Gems II.
Diffstat (limited to 'src/libs/ray/ray_render.c')
-rw-r--r--src/libs/ray/ray_render.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/libs/ray/ray_render.c b/src/libs/ray/ray_render.c
index e551d8c..1c7c79c 100644
--- a/src/libs/ray/ray_render.c
+++ b/src/libs/ray/ray_render.c
@@ -5,6 +5,7 @@
#include "ray_camera.h"
#include "ray_color.h"
+#include "ray_gamma.h"
#include "ray_render_object.h"
#include "ray_ray.h"
#include "ray_scene.h"
@@ -18,6 +19,7 @@ typedef struct ray_render_t {
ray_color_t ambient_light;
ray_camera_frame_t frame;
+ ray_gamma_t gamma;
ray_render_object_t objects[];
} ray_render_t;
@@ -207,7 +209,7 @@ void ray_render_trace_fragment(ray_render_t *render, fb_fragment_t *fb_fragment)
ray_camera_fragment_begin(&render->frame, fb_fragment, &ray, &fragment);
do {
do {
- *buf = ray_color_to_uint32_rgb(trace_ray(render, &ray));
+ *buf = ray_gamma_color_to_uint32_rgb(&render->gamma, trace_ray(render, &ray));
buf++;
} while (ray_camera_fragment_x_step(&fragment));
@@ -236,6 +238,7 @@ ray_render_t * ray_render_new(const ray_scene_t *scene, const ray_camera_t *came
render->camera = camera;
render->ambient_light = ray_3f_mult_scalar(&scene->ambient_color, scene->ambient_brightness);
+ ray_gamma_prepare(scene->gamma, &render->gamma);
ray_camera_frame_prepare(camera, &render->frame);
for (i = 0, object = scene->objects; object->type; object++)
© All Rights Reserved