-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- fix the issue with sphere.h - add a Chapter 7 HD photo before gamma correction for fun
- Loading branch information
Showing
9 changed files
with
20,084 additions
and
21 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#ifndef MATERIALH | ||
#define MATERIALH | ||
|
||
#include "sphere.h" | ||
|
||
|
||
float drand() { | ||
return (float)rand()/(RAND_MAX+1.0); | ||
} | ||
vec3 random_in_unit_sphere(){ | ||
vec3 p; | ||
do { | ||
p = 2.0*vec3(drand(),drand(),drand()) - vec3(1,1,1); | ||
} while (p.squared_length() >= 1.0); | ||
return p; | ||
} | ||
class material { | ||
public: | ||
virtual bool scatter(const ray& r_in, const hit_record& rec, vec3& attenuation, ray& scattered) const = 0; | ||
}; | ||
|
||
vec3 reflect(const vec3& v, const vec3& n) { | ||
return v - 2*dot(v,n)*n; | ||
} | ||
|
||
class lambertian : public material { | ||
public: | ||
lambertian(const vec3& a) : albedo(a) {} | ||
virtual bool scatter(const ray& r_in, const hit_record& rec, vec3& attenuation, ray& scattered) const { | ||
vec3 target = rec.normal + random_in_unit_sphere(); | ||
scattered = ray(rec.p, target); | ||
attenuation = albedo; | ||
return true; | ||
} | ||
vec3 albedo; | ||
}; | ||
|
||
class metal : public material { | ||
public: | ||
metal(const vec3& a, float f) : albedo(a) {if (f<1) fuzz=f; else fuzz=1;} | ||
virtual bool scatter(const ray& r_in, const hit_record& rec, vec3& attenuation, ray& scattered) const { | ||
vec3 reflected = reflect(unit_vector(r_in.direction()), rec.normal); | ||
scattered = ray(rec.p,reflected+fuzz*random_in_unit_sphere()); | ||
attenuation = albedo; | ||
return (dot(scattered.direction(), rec.normal)>0); | ||
} | ||
|
||
vec3 albedo; | ||
float fuzz; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.