Add area light material

This commit is contained in:
Camden Dixie O'Brien
2025-09-23 15:35:26 +01:00
parent 42976ef40b
commit 139ff40f12
2 changed files with 30 additions and 0 deletions

View File

@@ -22,6 +22,14 @@
.params = { .dielectric = { .eta = e } }, \
}
#define AREA_LIGHT(r, g, b, l) \
{ \
.scatter = scatter_area_light, \
.params = { \
.area_light = { .colour = { r, g, b }, .luminosity = l }, \
}, \
}
typedef struct {
vec3_t point, normal;
double t;
@@ -41,10 +49,16 @@ typedef struct {
double eta;
} dielectric_params_t;
typedef struct {
vec3_t colour;
double luminosity;
} area_light_params_t;
typedef union {
lambertian_params_t lambertian;
reflective_params_t reflective;
dielectric_params_t dielectric;
area_light_params_t area_light;
} material_params_t;
typedef bool scatter_fn_t(
@@ -65,5 +79,8 @@ bool scatter_reflective(
bool scatter_dielectric(
material_params_t params, hit_t hit, rng_t *rng, ray_t *ray,
vec3_t *atten_out);
bool scatter_area_light(
material_params_t params, hit_t hit, rng_t *rng, ray_t *ray,
vec3_t *atten_out);
#endif

View File

@@ -68,3 +68,16 @@ bool scatter_dielectric(
return true;
}
bool scatter_area_light(
material_params_t params, hit_t hit, rng_t *rng, ray_t *ray,
vec3_t *atten_out)
{
(void)hit;
(void)rng;
(void)ray;
*atten_out
= vec3_scale(params.area_light.colour, params.area_light.luminosity);
return false;
}