Add enviromental samples per pixel
This commit is contained in:
parent
1eeb328b60
commit
f622a55c5c
4 changed files with 93 additions and 20 deletions
23
color.hpp
23
color.hpp
|
|
@ -1,18 +1,27 @@
|
|||
#ifndef COLOR_H
|
||||
#define COLOR_H
|
||||
|
||||
#include "vec3.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "rtweekend.hpp"
|
||||
|
||||
/* Writes color components as a space-delimited string of numbers in the range [0,255] */
|
||||
void write_color(FILE *fp, color c)
|
||||
void write_color(FILE *fp, color c, uint32_t samples_per_pixel)
|
||||
{
|
||||
fprintf(fp, "%d %d %d\n",
|
||||
(uint8_t) (255 * c.x),
|
||||
(uint8_t) (255 * c.y),
|
||||
(uint8_t) (255 * c.z));
|
||||
double scale = 1.0 / samples_per_pixel;
|
||||
|
||||
// Divide the color by the number of samples
|
||||
double r = c.x * scale;
|
||||
double g = c.y * scale;
|
||||
double b = c.z * scale;
|
||||
|
||||
/* Write output */
|
||||
fprintf(fp,
|
||||
"%d %d %d\n",
|
||||
(uint8_t) (255 * clamp(r, 0, 1)),
|
||||
(uint8_t) (255 * clamp(g, 0, 1)),
|
||||
(uint8_t) (255 * clamp(b, 0, 1)));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue