Slide 15
Slide 15 text
Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 14
jgs
Create a texture using a noise function
// calculate texture pixel by pixel
texture (i, j)=
colorMap(
scale(
PerlinNoise (i * 5, j * 5) // -2 to 2
)
);
// scale [-2,2] range to [0,1]
float scale(float x) {
return (x + 2) / 4;
}
// interpolates two colors
Vec3f colorMap(float a) {
Vec3f white = Vec3f(1, 1, 1);
Vec3f color = Vec3f(1, 0, 0);
return ((1 - a) * white + a * color);
}