Create material abstraction
This commit is contained in:
40
include/material.h
Normal file
40
include/material.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef MATERIAL_H
|
||||
#define MATERIAL_H
|
||||
|
||||
#include "ray.h"
|
||||
#include "rng.h"
|
||||
|
||||
#define LAMBERTIAN(r, g, b) \
|
||||
{ \
|
||||
.scatter = scatter_lambertian, \
|
||||
.params = { .lambertian = { .albedo = { r, g, b } } }, \
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
vec3_t point, normal;
|
||||
double t;
|
||||
bool front;
|
||||
} hit_t;
|
||||
|
||||
typedef struct {
|
||||
vec3_t albedo;
|
||||
} lambertian_params_t;
|
||||
|
||||
typedef union {
|
||||
lambertian_params_t lambertian;
|
||||
} material_params_t;
|
||||
|
||||
typedef bool scatter_fn_t(
|
||||
material_params_t params, hit_t hit, rng_t *rng, ray_t *ray,
|
||||
vec3_t *atten_out);
|
||||
|
||||
typedef struct {
|
||||
scatter_fn_t *scatter;
|
||||
material_params_t params;
|
||||
} material_t;
|
||||
|
||||
bool scatter_lambertian(
|
||||
material_params_t params, hit_t hit, rng_t *rng, ray_t *ray,
|
||||
vec3_t *atten_out);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user