Skip to content

Commit

Permalink
stereoscope rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
ssloy committed Feb 3, 2019
1 parent 8698c64 commit e966911
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Binary file added doc/stereoscope.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 6 additions & 7 deletions tinyraytracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void render(const std::vector<Sphere> &spheres, const std::vector<Light> &lights
}
}

std::vector<unsigned char> pixmap((width-delta)*height*3);
std::vector<unsigned char> pixmap((width-delta)*height*3*2);
for (size_t j = 0; j<height; j++) {
for (size_t i = 0; i<width-delta; i++) {
Vec3f c1 = framebuffer1[i+delta+j*width];
Expand All @@ -154,15 +154,14 @@ void render(const std::vector<Sphere> &spheres, const std::vector<Light> &lights
if (max1>1) c1 = c1*(1./max1);
float max2 = std::max(c2[0], std::max(c2[1], c2[2]));
if (max2>1) c2 = c2*(1./max2);
float avg1 = (c1.x+c1.y+c1.z)/3.;
float avg2 = (c2.x+c2.y+c2.z)/3.;

pixmap[(j*(width-delta) + i)*3 ] = 255*avg1;
pixmap[(j*(width-delta) + i)*3+1] = 0;
pixmap[(j*(width-delta) + i)*3+2] = 255*avg2;
for (size_t d=0; d<3; d++) {
pixmap[(j*(width-delta)*2 + i )*3+d] = 255*c1[d];
pixmap[(j*(width-delta)*2 + i+width-delta)*3+d] = 255*c2[d];
}
}
}
stbi_write_jpg("out.jpg", width-delta, height, 3, pixmap.data(), 100);
stbi_write_jpg("out.jpg", (width-delta)*2, height, 3, pixmap.data(), 100);
}

int main() {
Expand Down

0 comments on commit e966911

Please sign in to comment.