Skip to content

Commit

Permalink
fire color palette
Browse files Browse the repository at this point in the history
  • Loading branch information
ssloy committed Jan 27, 2019
1 parent 6ac4658 commit 585c779
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Binary file modified out.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 19 additions & 1 deletion tinykaboom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ float fractal_brownian_motion(const Vec3f &x) {
return f/0.9375;
}

Vec3f palette_fire(const float d) {
const Vec3f yellow(1.7, 1.3, 1.0); // note that the color is "hot", i.e. has components >1
const Vec3f orange(1.0, 0.6, 0.0);
const Vec3f red(1.0, 0.0, 0.0);
const Vec3f darkgray(0.2, 0.2, 0.2);
const Vec3f gray(0.4, 0.4, 0.4);

float x = std::max(0.f, std::min(1.f, d));
if (x<.25f)
return lerp(gray, darkgray, x*4.f);
else if (x<.5f)
return lerp(darkgray, red, x*4.f-1.f);
else if (x<.75f)
return lerp(red, orange, x*4.f-2.f);
return lerp(orange, yellow, x*4.f-3.f);
}

float signed_distance(const Vec3f &p) {
float displacement = -fractal_brownian_motion(p*3.4)*noise_amplitude;
return p.norm() - (sphere_radius + displacement);
Expand Down Expand Up @@ -86,9 +103,10 @@ int main() {
float dir_z = -height/(2.*tan(fov/2.));
Vec3f hit;
if (sphere_trace(Vec3f(0, 0, 3), Vec3f(dir_x, dir_y, dir_z).normalize(), hit)) { // the camera is placed to (0,0,3) and it looks along the -z axis
float noise_level = (sphere_radius-hit.norm())/noise_amplitude;
Vec3f light_dir = (Vec3f(10, 10, 10) - hit).normalize(); // one light is placed to (10,10,10)
float light_intensity = std::max(0.4f, light_dir*distance_field_normal(hit));
framebuffer[i+j*width] = Vec3f(1, 1, 1)*light_intensity;
framebuffer[i+j*width] = palette_fire((-.2 + noise_level)*2)*light_intensity;
} else {
framebuffer[i+j*width] = Vec3f(0.2, 0.7, 0.8); // background color
}
Expand Down

0 comments on commit 585c779

Please sign in to comment.