diff --git a/out.jpg b/out.jpg index 13e8723..38071cb 100644 Binary files a/out.jpg and b/out.jpg differ diff --git a/tinykaboom.cpp b/tinykaboom.cpp index 1eed975..a1ee1ca 100644 --- a/tinykaboom.cpp +++ b/tinykaboom.cpp @@ -8,9 +8,12 @@ #include "geometry.h" const float sphere_radius = 1.5; +const float noise_amplitude = 0.2; float signed_distance(const Vec3f &p) { - return p.norm() - sphere_radius; + Vec3f s = Vec3f(p).normalize(sphere_radius); + float displacement = sin(16*s.x)*sin(16*s.y)*sin(16*s.z)*noise_amplitude; + return p.norm() - (sphere_radius + displacement); } bool sphere_trace(const Vec3f &orig, const Vec3f &dir, Vec3f &pos) { @@ -48,8 +51,7 @@ int main() { 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 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)); - float displacement = (sin(16*hit.x)*sin(16*hit.y)*sin(16*hit.z) + 1.)/2.; - framebuffer[i+j*width] = Vec3f(1, 1, 1)*displacement*light_intensity; + framebuffer[i+j*width] = Vec3f(1, 1, 1)*light_intensity; } else { framebuffer[i+j*width] = Vec3f(0.2, 0.7, 0.8); // background color }