Skip to content

Commit

Permalink
remove albedo from Dielectric
Browse files Browse the repository at this point in the history
  • Loading branch information
gau-nernst committed Nov 26, 2023
1 parent bbf3cf0 commit 5735397
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
5 changes: 2 additions & 3 deletions include/material.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ Material *Metal_new(Texture *albedo, float fuzz);

typedef struct Dielectric {
Material mat;
Texture *albedo;
float eta;
} Dielectric;
void Dielectric_init(Dielectric *self, Texture *albedo, float eta);
Material *Dielectric_new(Texture *albedo, float eta);
void Dielectric_init(Dielectric *self, float eta);
Material *Dielectric_new(float eta);

typedef struct DiffuseLight {
Material mat;
Expand Down
13 changes: 5 additions & 8 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void scene_book1_final(World *world, Camera *camera) {
mat = Lambertian_new(Solid_new(vec3(0.5, 0.5, 0.5)));
HittableList_append(&world->objects, Sphere_new(vec3(0, -1000, -1), 1000, mat));

mat = Dielectric_new(Solid_new(vec3(1, 1, 1)), 1.5);
mat = Dielectric_new(1.5);
HittableList_append(&world->objects, Sphere_new(vec3(0, 1, 0), 1, mat));

mat = Lambertian_new(Solid_new(vec3(0.4, 0.2, 0.1)));
Expand All @@ -55,17 +55,14 @@ void scene_book1_final(World *world, Camera *camera) {
Vec3 center = vec3((float)a + 0.9f * pcg32_f32(&rng), radius, (float)b + 0.9f * pcg32_f32(&rng));

if (vec3_length(vec3_sub(center, ref_point)) > 0.9f) {
Vec3 color;

if (choose_material < 0.8f) {
color = vec3_mul(vec3_rand(&rng), vec3_rand(&rng));
Vec3 color = vec3_mul(vec3_rand(&rng), vec3_rand(&rng));
mat = Lambertian_new(Solid_new(color));
} else if (choose_material < 0.95f) {
color = vec3_rand_between(&rng, 0.5f, 1);
Vec3 color = vec3_rand_between(&rng, 0.5f, 1);
mat = Metal_new(Solid_new(color), pcg32_f32(&rng) * 0.5f);
} else {
color = vec3(1, 1, 1);
mat = Dielectric_new(Solid_new(color), 1.5f);
mat = Dielectric_new(1.5f);
}

HittableList_append(&world->objects, Sphere_new(center, radius, mat));
Expand Down Expand Up @@ -213,7 +210,7 @@ void scene_book2_final(World *world, Camera *camera, bool enable_bvh) {
Material *sphere_mat = Lambertian_new(Solid_new(vec3(0.7, 0.3, 0.1)));
HittableList_append(&world->objects, Sphere_new(center1, 50, sphere_mat));

Material *glass = Dielectric_new(Solid_new(vec3(1, 1, 1)), 1.5);
Material *glass = Dielectric_new(1.5);
HittableList_append(&world->objects, Sphere_new(vec3(260, 150, 45), 50, glass));

Material *metal = Metal_new(Solid_new(vec3(0.8, 0.8, 0.9)), 1.0);
Expand Down
8 changes: 3 additions & 5 deletions src/material.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ static bool Dielectric_scatter(HitRecord *rec, Vec3 incident, PCG32 *rng, Vec3 *
Vec3 r_para = vec3_mul(rec->normal, -sqrtf(fabsf(1.0f - vec3_length2(r_perp))));
*scattered = vec3_add(r_perp, r_para);
}
*color = _Texture_value(mat->albedo, rec);
*color = vec3(1, 1, 1);
return true;
}
void Dielectric_init(Dielectric *self, Texture *albedo, float eta) {
*self = (Dielectric){{Dielectric_scatter, Material_emit}, albedo, eta};
}
Material *Dielectric_new(Texture *albedo, float eta) define_init_new(Dielectric, albedo, eta);
void Dielectric_init(Dielectric *self, float eta) { *self = (Dielectric){{Dielectric_scatter, Material_emit}, eta}; }
Material *Dielectric_new(float eta) define_init_new(Dielectric, eta);

static bool DiffuseLight_scatter(HitRecord *rec, Vec3 incident, PCG32 *rng, Vec3 *scattered, Vec3 *color) {
return false;
Expand Down

0 comments on commit 5735397

Please sign in to comment.