Allow negative sky colour to be specified
This commit is contained in:
6
demo.c
6
demo.c
@@ -16,7 +16,8 @@
|
|||||||
static const vec3_t camera_pos = { 80.0, 30.0, 60.0 };
|
static const vec3_t camera_pos = { 80.0, 30.0, 60.0 };
|
||||||
static const vec3_t target = { 0.0, 0.0, 10.0 };
|
static const vec3_t target = { 0.0, 0.0, 10.0 };
|
||||||
|
|
||||||
static const vec3_t sky = { 0.6, 0.8, 1.0 };
|
static const vec3_t sky_pos = { 0.6, 0.8, 1.0 };
|
||||||
|
static const vec3_t sky_neg = { 1.0, 1.0, 1.0 };
|
||||||
|
|
||||||
static const material_t floor = LAMBERTIAN(1.0, 0.94, 0.80);
|
static const material_t floor = LAMBERTIAN(1.0, 0.94, 0.80);
|
||||||
static const material_t light = AREA_LIGHT(1.0, 0.8, 0.5, 4.0);
|
static const material_t light = AREA_LIGHT(1.0, 0.8, 0.5, 4.0);
|
||||||
@@ -43,7 +44,8 @@ int main()
|
|||||||
= camera_init(camera_pos, target, FOV, W, H, APERTURE, FOCAL_LEN);
|
= camera_init(camera_pos, target, FOV, W, H, APERTURE, FOCAL_LEN);
|
||||||
|
|
||||||
const scene_t scene = {
|
const scene_t scene = {
|
||||||
.sky_colour = sky,
|
.sky_pos = sky_pos,
|
||||||
|
.sky_neg = sky_neg,
|
||||||
.objs = objs,
|
.objs = objs,
|
||||||
.obj_count = NELEMS(objs),
|
.obj_count = NELEMS(objs),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "obj.h"
|
#include "obj.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
vec3_t sky_colour;
|
vec3_t sky_pos, sky_neg;
|
||||||
obj_t *objs;
|
obj_t *objs;
|
||||||
unsigned obj_count;
|
unsigned obj_count;
|
||||||
} scene_t;
|
} scene_t;
|
||||||
|
|||||||
6
rand.c
6
rand.c
@@ -22,7 +22,8 @@
|
|||||||
static const vec3_t camera_pos = { -100.0, 30.0, -100.0 };
|
static const vec3_t camera_pos = { -100.0, 30.0, -100.0 };
|
||||||
static const vec3_t target = { 0.0, 0.0, 0.0 };
|
static const vec3_t target = { 0.0, 0.0, 0.0 };
|
||||||
|
|
||||||
static const vec3_t sky = { 0.6, 0.8, 1.0 };
|
static const vec3_t sky_pos = { 0.6, 0.8, 1.0 };
|
||||||
|
static const vec3_t sky_neg = { 1.0, 1.0, 1.0 };
|
||||||
|
|
||||||
static const material_t floor = LAMBERTIAN(1.0, 0.94, 0.80);
|
static const material_t floor = LAMBERTIAN(1.0, 0.94, 0.80);
|
||||||
static const material_t light = AREA_LIGHT(1.0, 0.8, 0.1, 4.0);
|
static const material_t light = AREA_LIGHT(1.0, 0.8, 0.1, 4.0);
|
||||||
@@ -72,7 +73,8 @@ int main()
|
|||||||
= camera_init(camera_pos, target, FOV, W, H, APERTURE, FOCAL_LEN);
|
= camera_init(camera_pos, target, FOV, W, H, APERTURE, FOCAL_LEN);
|
||||||
|
|
||||||
const scene_t scene = {
|
const scene_t scene = {
|
||||||
.sky_colour = sky,
|
.sky_pos = sky_pos,
|
||||||
|
.sky_neg = sky_neg,
|
||||||
.objs = objs,
|
.objs = objs,
|
||||||
.obj_count = OBJ_COUNT,
|
.obj_count = OBJ_COUNT,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -45,7 +45,8 @@ static vec3_t trace(ray_t ray, const scene_t *scene, rng_t *rng)
|
|||||||
if (hit.t == DBL_MAX) {
|
if (hit.t == DBL_MAX) {
|
||||||
const double a = (ray.dir.y + 1.0) / 2.0;
|
const double a = (ray.dir.y + 1.0) / 2.0;
|
||||||
const vec3_t bg = vec3_add(
|
const vec3_t bg = vec3_add(
|
||||||
vec3_scale(scene->sky_colour, a), vec3_scale(white, 1 - a));
|
vec3_scale(scene->sky_pos, a),
|
||||||
|
vec3_scale(scene->sky_neg, 1 - a));
|
||||||
return vec3_hadamard(colour, bg);
|
return vec3_hadamard(colour, bg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user