Gamma correct pixels before writing out
This commit is contained in:
16
src/camera.c
16
src/camera.c
@@ -4,6 +4,7 @@
|
||||
#include "rng.h"
|
||||
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <threads.h>
|
||||
|
||||
#define MAX_ITER 10
|
||||
@@ -13,6 +14,8 @@
|
||||
#define SAMPLE_WEIGHT (1.0 / (double)NSAMPLES)
|
||||
#define SAMPLE_STDDEV 0.333
|
||||
|
||||
#define GAMMA 2.2
|
||||
|
||||
#define NTHREADS 40
|
||||
|
||||
typedef struct {
|
||||
@@ -52,17 +55,22 @@ trace(ray_t ray, const obj_t *scene, unsigned scene_count, rng_t *rng)
|
||||
}
|
||||
|
||||
ray = scatter(hit, rng);
|
||||
coeff *= 0.5;
|
||||
coeff *= 0.3;
|
||||
}
|
||||
|
||||
return black;
|
||||
}
|
||||
|
||||
static double linear_to_gamma(double channel)
|
||||
{
|
||||
return pow(fmin(channel, 1.0), 1.0 / GAMMA);
|
||||
}
|
||||
|
||||
static void setpix(vec3_t col, pix_t *out)
|
||||
{
|
||||
out->r = UINT16_MAX * col.x;
|
||||
out->g = UINT16_MAX * col.y;
|
||||
out->b = UINT16_MAX * col.z;
|
||||
out->r = UINT16_MAX * linear_to_gamma(col.x);
|
||||
out->g = UINT16_MAX * linear_to_gamma(col.y);
|
||||
out->b = UINT16_MAX * linear_to_gamma(col.z);
|
||||
out->a = UINT16_MAX;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user