Basic diffuse mapping and gamma correction
This commit is contained in:
parent
2756d676f1
commit
4497cc7f68
4 changed files with 41 additions and 10 deletions
28
vec3.hpp
28
vec3.hpp
|
|
@ -1,8 +1,7 @@
|
|||
#ifndef VEC3_H
|
||||
#define VEC3_H
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include "rtweekend.hpp"
|
||||
|
||||
struct vec3 {
|
||||
/* Members */
|
||||
|
|
@ -65,6 +64,18 @@ struct vec3 {
|
|||
{
|
||||
return x*x + y*y + z*z;
|
||||
}
|
||||
|
||||
// Get a vec3 with random components in the range [0,1)
|
||||
inline static vec3 random()
|
||||
{
|
||||
return vec3(random_double(), random_double(), random_double());
|
||||
}
|
||||
|
||||
// Get a vec3 with random components in the range [min, max)
|
||||
inline static vec3 random(double min, double max)
|
||||
{
|
||||
return vec3(random_double(min, max), random_double(min, max), random_double(min, max));
|
||||
}
|
||||
};
|
||||
|
||||
/* Type aliases */
|
||||
|
|
@ -135,4 +146,17 @@ inline vec3 normalize(const vec3 v)
|
|||
return v / v.length();
|
||||
}
|
||||
|
||||
// Returns a vec3 of random components between [-1,1) that is inside a unit sphere
|
||||
vec3 random_in_unit_sphere()
|
||||
{
|
||||
// Iterate until we find a vector with length < 1
|
||||
while (true)
|
||||
{
|
||||
vec3 p = vec3::random(-1,1);
|
||||
if (p.length_squared() >= 1)
|
||||
continue;
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue