add inital anti-aliasing
This commit is contained in:
parent
5bbfb17684
commit
cefd653d4e
|
@ -4,6 +4,7 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "hittable.h"
|
#include "hittable.h"
|
||||||
|
|
||||||
|
|
||||||
class Camera {
|
class Camera {
|
||||||
public:
|
public:
|
||||||
double aspect_ratio = 1.0; // Ratio of image width over height
|
double aspect_ratio = 1.0; // Ratio of image width over height
|
||||||
|
|
10
src/canvas.h
10
src/canvas.h
|
@ -1,6 +1,7 @@
|
||||||
#ifndef CANVAS_H
|
#ifndef CANVAS_H
|
||||||
#define CANVAS_H
|
#define CANVAS_H
|
||||||
|
|
||||||
|
#include "interval.h"
|
||||||
#include "vec3.h"
|
#include "vec3.h"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
@ -13,11 +14,10 @@ struct Rgb {
|
||||||
};
|
};
|
||||||
|
|
||||||
inline Rgb to_rgb(const Color &c) {
|
inline Rgb to_rgb(const Color &c) {
|
||||||
auto clamp = [](double x) { return x < 0.0 ? 0.0 : (x > 1.0 ? 1.0 : x); };
|
static const interval intensity(0.000, 0.999);
|
||||||
|
return {static_cast<uint8_t>(256 * intensity.clamp(c.x())),
|
||||||
return {static_cast<uint8_t>(255.999 * clamp(c.x())),
|
static_cast<uint8_t>(256 * intensity.clamp(c.y())),
|
||||||
static_cast<uint8_t>(255.999 * clamp(c.y())),
|
static_cast<uint8_t>(256 * intensity.clamp(c.z()))};
|
||||||
static_cast<uint8_t>(255.999 * clamp(c.z()))};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Canvas {
|
struct Canvas {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef INTERVAL_H
|
#ifndef INTERVAL_H
|
||||||
#define INTERVAL_H
|
#define INTERVAL_H
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
class interval {
|
class interval {
|
||||||
public:
|
public:
|
||||||
double min, max;
|
double min, max;
|
||||||
|
@ -14,6 +16,14 @@ public:
|
||||||
bool contains(double x) const { return min <= x && x <= max; }
|
bool contains(double x) const { return min <= x && x <= max; }
|
||||||
|
|
||||||
bool surrounds(double x) const { return min < x && x < max; }
|
bool surrounds(double x) const { return min < x && x < max; }
|
||||||
|
|
||||||
|
double clamp(double x) const {
|
||||||
|
if (x < min)
|
||||||
|
return min;
|
||||||
|
if (x > max)
|
||||||
|
return max;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline const interval empty = interval(+infinity, -infinity);
|
static inline const interval empty = interval(+infinity, -infinity);
|
||||||
|
|
Loading…
Reference in New Issue