Skip to content
Snippets Groups Projects
Commit f6315bbf authored by Lucas Villaume's avatar Lucas Villaume
Browse files

corps du bonhomme

parent dc631a9a
Branches
Tags
No related merge requests found
......@@ -16,7 +16,6 @@
int envmap_width, envmap_height;
std::vector<Vec3f> envmap;
Model duck("../duck.obj");
struct Light {
Light(const Vec3f &p, const float i) : position(p), intensity(i) {}
......@@ -78,17 +77,6 @@ bool scene_intersect(const Vec3f &orig, const Vec3f &dir, const std::vector<Sphe
}
}
float tnear;
for (size_t i=0; i<duck.nfaces(); ++i) {
if (duck.ray_triangle_intersect(i, orig, dir, tnear)) {
spheres_dist = tnear;
hit = orig + dir*tnear;
N = Vec3f(0,0,1);
material = Material(1.5, Vec4f(0.0, 0.5, 0.1, 0.8), Vec3f(0.6, 0.7, 0.8), 125.);
}
}
float checkerboard_dist = std::numeric_limits<float>::max();
if (fabs(dir.y)>1e-3) {
float d = -(orig.y+4)/dir.y; // the checkerboard plane has equation y = -4
......@@ -97,7 +85,7 @@ bool scene_intersect(const Vec3f &orig, const Vec3f &dir, const std::vector<Sphe
checkerboard_dist = d;
hit = pt;
N = Vec3f(0,1,0);
material.diffuse_color = (int(.5*hit.x+1000) + int(.5*hit.z)) & 1 ? Vec3f(.3, .3, .3) : Vec3f(.3, .2, .1);
material.diffuse_color = Vec3f(.3, .3, .3);
}
}
return std::min(spheres_dist, checkerboard_dist)<1000;
......@@ -162,66 +150,8 @@ void render(const std::vector<Sphere> &spheres, const std::vector<Light> &lights
pixmap[i*3+j] = (unsigned char)(255 * std::max(0.f, std::min(1.f, framebuffer[i][j])));
}
}
int decal = 20;
//Red map
std::vector<unsigned char> redmap(width*height*3);
for (size_t i = 0; i < height*width; ++i) {
Vec3f &c = framebuffer[i];
float max = std::max(c[0], std::max(c[1], c[2]));
if (max>1) c = c*(1./max);
for (size_t j = 0; j<3; j++) {
if (j == 0) { // Red channel
redmap[i*3+j] = (unsigned char)(255 * std::max(0.f, std::min(1.f, framebuffer[i][j])));
} else { // Green and blue channels
redmap[i*3+j] = 0;
}
}
}
std::vector<unsigned char> shifted_redmap(width*height*3);
for (size_t y = 0; y < height; ++y) {
for (size_t x = 0; x < width; ++x) {
if (x >= decal) {
for (size_t j = 0; j < 3; ++j) {
shifted_redmap[(y*width + x - decal)*3 + j] = redmap[(y*width + x)*3 + j];
}
}
}
}
//blue map
std::vector<unsigned char> bluemap(width*height*3);
for (size_t i = 0; i < height*width; ++i) {
Vec3f &c = framebuffer[i];
float max = std::max(c[0], std::max(c[1], c[2]));
if (max>1) c = c*(1./max);
for (size_t j = 0; j<3; j++) {
if (j == 2) { // blue channel
bluemap[i*3+j] = (unsigned char)(255 * std::max(0.f, std::min(1.f, framebuffer[i][j])));
} else { // Green and red channels
bluemap[i*3+j] = 0;
}
}
}
std::vector<unsigned char> shifted_bluemap(width*height*3);
for (size_t y = 0; y < height; ++y) {
for (size_t x = 0; x < width; ++x) {
if (x < width - decal) {
for (size_t j = 0; j < 3; ++j) {
shifted_bluemap[(y*width + x + decal)*3 + j] = bluemap[(y*width + x)*3 + j];
}
}
}
}
//anaglyph
std::vector<unsigned char> anaglyph_image(width*height*3);
for (size_t i = 0; i < height*width; ++i) {
anaglyph_image[i*3] = shifted_redmap[i*3]; // Red channel from red image
anaglyph_image[i*3+1] = shifted_redmap[i*3+1]; // Green channel from blue image
anaglyph_image[i*3+2] = shifted_bluemap[i*3+2]; // Blue channel from blue image
}
stbi_write_jpg("out.jpg", width, height, 3, pixmap.data(), 100);
stbi_write_jpg("red_left.jpg", width, height, 3, shifted_redmap.data(), 100);
stbi_write_jpg("blue_right.jpg", width, height, 3, shifted_bluemap.data(), 100);
stbi_write_jpg("anaglyph.jpg", width, height, 3, anaglyph_image.data(), 100);
stbi_write_jpg("../out.jpg", width, height, 3, pixmap.data(), 100);
}
int main() {
......@@ -245,10 +175,16 @@ int main() {
Material mirror(1.0, Vec4f(0.0, 10.0, 0.8, 0.0), Vec3f(1.0, 1.0, 1.0), 1425.);
std::vector<Sphere> spheres;
spheres.push_back(Sphere(Vec3f(-3, 0, -16), 2, ivory));
spheres.push_back(Sphere(Vec3f(-1.0, -1.5, -12), 2, glass));
spheres.push_back(Sphere(Vec3f( 1.5, -0.5, -18), 3, red_rubber));
spheres.push_back(Sphere(Vec3f( 7, 5, -18), 4, mirror));
//Corps du bonhomme de neige
spheres.push_back(Sphere(Vec3f(0, -1.7, -15), 2.3, ivory));
spheres.push_back(Sphere(Vec3f(0, 1.9, -15), 1.9, ivory));
spheres.push_back(Sphere(Vec3f(0, 4.6, -15), 1.5, ivory));
//spheres.push_back(Sphere(Vec3f(-1.0, -1.5, -12), 2, glass));
//spheres.push_back(Sphere(Vec3f( 1.5, -0.5, -18), 3, red_rubber));
//spheres.push_back(Sphere(Vec3f( 7, 5, -18), 4, mirror));
std::vector<Light> lights;
lights.push_back(Light(Vec3f(-20, 20, 20), 1.5));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment