Beispiel #1
0
void wmonkey_scene_2()
{
    printf("WOODEN MONKEY SCENE : 2 (path tracing) ----------------------------------\n\n");
    Raytracer rt;
    int width = 16 * 20 * 2;
    int height = 12 * 20 * 2;

    // room dimensions
    double wDiameter = 20;
    double wRadius = wDiameter / 2;
    double wallSize[] = {wDiameter + DBL_EPSILON, wDiameter + DBL_EPSILON, wDiameter + DBL_EPSILON};

    // Camera parameters.
    Point3D camera_pos(0, 0, 1);
    Vector3D camera_target(0, 0, -1);
    Vector3D up(0, 1, 0);
    double fov = 65;

    double l0c = .9;
    PointLight * light0 = new PointLight(
        //			Point3D(-wDiameter - roomRad + (roomRad / 2), 50 * 2, 50 * 2),
        Point3D(0, wRadius - 5, 0),
        Colour(l0c, l0c, l0c),
        0.2);
    rt.addLightSource(light0);

    // http://en.wikipedia.org/wiki/Cornell_Box
    // http://www.kevinbeason.com/smallpt/#moreinfo
    Material matLight(
        Colour(1, 1, 1) 			// ambient
        , Colour(1, 1, 1)			// diffuse
        , Colour(1, 1, 1)			// spec
        , 0, 0, 0, 0
    );

    Material matMirror(
        Colour(0.3, 0.3, 0.3) 			// ambient
        , Colour(0.1, 0.1, 0.1)		// diffuse
        , Colour(0.628281, 0.555802, 0.366065)		// spec
        , 51.2, 1.0
    );

    Material matGlass(
        Colour(0, 0, 0) 			// ambient
        , Colour(0.1, 0.1, 0.1)			// diffuse
        , Colour(1.0, 1.0, 1.0)		// spec
        , 100, 0.0, 1.01, 0.9
    );

    Material matBeige(
        Colour(0.607843, 0.549019, 0.372549) 			// ambient
        , Colour(0.741176, 0.686274, 0.525490)		// diffuse
        , Colour(0.933333, 0.901960, 0.807843)		// spec
        , 12.8
    );

    Material matReddishWall(
        Colour(.25, .25, .25) 			// ambient
        , Colour(.75, .25, .25)		// diffuse
        , Colour(.3, .3, .3)		// spec
        , 2, 0, 0, 0
    );

    Material matBluishWall(
        Colour(.25, .25, .25) 			// ambient
        , Colour(.25, .25, .75)		// diffuse
        , Colour(.3, .3, .3)		// spec
        , 2, 0, 0, 0
    );

    Material matGreenishWall(
        Colour(.25, .25, .25) 			// ambient
        , Colour(.25, .75, .25)		// diffuse
        , Colour(.3, .3, .3)		// spec
        , 2, 0, 0, 0
    );

    Material matBaseWall(
        Colour(.25, .25, .25) 			// ambient
        , Colour(.25, .25, .25)		// diffuse
        , Colour(.6, .6, .6)		// spec
        , 2, 0, 0, 0
    );

    // create and position the box
    SceneDagNode* wallLeft = rt.addObject( new UnitSquare(), &matReddishWall );
    SceneDagNode* wallRight = rt.addObject( new UnitSquare(), &matBluishWall );
    SceneDagNode* wallFront = rt.addObject( new UnitSquare(), &matBaseWall );
    SceneDagNode* wallTop = rt.addObject( new UnitSquare(), &matLight );
    SceneDagNode* wallBot = rt.addObject( new UnitSquare(), &matGreenishWall );

    rt.translate(wallFront, Vector3D(0, 0, -wDiameter - wRadius + DBL_EPSILON));
    rt.scale(wallFront, Point3D(0, 0, 0), wallSize);

    rt.translate(wallRight, Vector3D(wRadius, 0, -wDiameter + DBL_EPSILON));
    rt.rotate(wallRight, 'y', -90);
    rt.scale(wallRight, Point3D(0, 0, 0), wallSize);

    rt.translate(wallLeft, Vector3D(-wRadius, 0, -wDiameter + DBL_EPSILON));
    rt.rotate(wallLeft, 'y', 90);
    rt.scale(wallLeft, Point3D(0, 0, 0), wallSize);

    rt.translate(wallTop, Vector3D(0, wRadius, -wDiameter + DBL_EPSILON));
    rt.rotate(wallTop, 'x', 90);
    rt.scale(wallTop, Point3D(0, 0, 0), wallSize);

    rt.translate(wallBot, Vector3D(0, -wRadius, -wDiameter + DBL_EPSILON));
    rt.rotate(wallBot, 'x', -90);
    rt.scale(wallBot, Point3D(0, 0, 0), wallSize);

    // create some objects within the box...
    SceneDagNode* sphere_chrome = rt.addObject( new UnitSphere(), &matGlass );
    double _sChrome_size = 2;
    double _sChrome[] = {_sChrome_size, _sChrome_size, _sChrome_size};
    rt.translate(sphere_chrome,
                 Vector3D(wRadius / 3 * 2,
                          -wRadius + (_sChrome_size),
                          -wDiameter + (wRadius / 3)));
    rt.scale(sphere_chrome, Point3D(0, 0, 0), _sChrome);

    SceneDagNode* sphere_glass = rt.addObject( new UnitSphere(), &matMirror );
    double _sGlass_size = 2.5;
    double _sGlass[] = {_sGlass_size, _sGlass_size, _sGlass_size};
    rt.translate(sphere_glass,
                 Vector3D(-wRadius / 3 * 2,
                          -wRadius + (_sGlass_size),
                          -wDiameter - (wRadius / 3)));
    rt.scale(sphere_glass, Point3D(0, 0, 0), _sGlass);

    SceneDagNode* sphere_beige = rt.addObject( new UnitSphere(), &matBeige );
    double _sBeige_size = 3.5;
    double _sBeige[] = {_sBeige_size, _sBeige_size, _sBeige_size};
    rt.translate(sphere_beige,
                 Vector3D(wRadius / 3 * 2,
                          -wRadius + (_sGlass_size * 2),
                          -wDiameter - (wRadius / 3)));
    rt.scale(sphere_beige, Point3D(0, 0, 0), _sBeige);

    rt.setAAMode(Raytracer::AA_SUPER_SAMPLING);
    rt.setAAMode(Raytracer::NONE);
    rt.setShadingMode(Raytracer::SCENE_MODE_DIFFUSE);
    rt.setShadows(Raytracer::SHADOW_CAST);
    rt.setEnvMapMode(Raytracer::ENV_MAP_CUBE_SKYBOX);
    //	rt.setColorSpaceMode(Raytracer::COLOR_ENC_SRGB_GAMMA_CORRECT);
    rt.setReflDepth(4);

    // refraction if it's turned on
    if (REFRACTION_FLAG) {
        rt.setRefractionMode(REFRACTION_FLAG);
    }

    if ( rt.getEnvMapMode() != Raytracer::NONE ) {
        // load images
        EnvMap env;
        if ( _DEBUG ) {
            env = EnvMap(
                      "EnvMaps/DebugMaps/posx.bmp",
                      "EnvMaps/DebugMaps/posy.bmp",
                      "EnvMaps/DebugMaps/posz.bmp",
                      "EnvMaps/DebugMaps/negx.bmp",
                      "EnvMaps/DebugMaps/negy.bmp",
                      "EnvMaps/DebugMaps/negz.bmp"
                  );
        } else {
            env = EnvMap(
                      "EnvMaps/SaintLazarusChurch/posx.bmp",
                      "EnvMaps/SaintLazarusChurch/posy.bmp",
                      "EnvMaps/SaintLazarusChurch/posz.bmp",
                      "EnvMaps/SaintLazarusChurch/negx.bmp",
                      "EnvMaps/SaintLazarusChurch/negy.bmp",
                      "EnvMaps/SaintLazarusChurch/negz.bmp"
                  );
        }

        rt.setEnvMap(env);
    }

    printf("WOODEN MONKEY SCENE : 2 :: Rendering...\n");
    rt.render(width, height, camera_pos, camera_target, up, fov, "wmonkey_2.bmp");
    printf("WOODEN MONKEY SCENE : 2 :: Done!\n");
}
Beispiel #2
0
int main(int argc, char* argv[])
{
    // Build your scene and setup your camera here, by calling
    // functions from Raytracer.  The code here sets up an example
    // scene and renders it from two different view points, DO NOT
    // change this if you're just implementing part one of the
    // assignment.
    Raytracer raytracer;
    int width = 16 * 20 * 2;
    int height = 12 * 20 * 2;

    if (argc == 3) {
        width = atoi(argv[1]);
        height = atoi(argv[2]);
    }

    // Camera parameters.
    Point3D eye1(0, 0, 1), eye2(4, 2, 1);
    Vector3D view1(0, 0, -1), view2(-4, -2, -6);
//	Point3D eye1(0, 0, 1), eye2(4, 2, -6);
//	Vector3D view1(0, 0, -1), view2(-4, -2, 1);
    Vector3D up(0, 1, 0);
    double fov = 60;

    // Defines a material for shading.
    Material gold( Colour(0.3, 0.3, 0.3), Colour(0.75164, 0.60648, 0.22648),
                   Colour(0.628281, 0.555802, 0.366065),
                   51.2, LARGE_SPH_REFLECT, LARGE_SPH_REFRAC_INDX, LARGE_SPH_REFRACT);
    Material jade( Colour(0, 0, 0), Colour(0.54, 0.89, 0.63),
                   Colour(0.316228, 0.316228, 0.316228),
                   12.8);

    Material red( Colour(0, 0, 0), Colour(0.9, 0.05, 0.05),
                  Colour(0.4, 0.2, 0.2),
                  12.8);

    // Defines a point light source.
    Point3D light_pos;
    if (LIGHT_DEFAULT) {
        light_pos = Point3D(0, 0, 5);
    } else {
        light_pos = LIGHT_POS_TEST;
    }

    PointLight * light0 = new PointLight(
        light_pos,
        Colour(0.9, 0.9, 0.9),
        0.1);
    raytracer.addLightSource(light0);

    // Add a unit square into the scene with material mat.
    SceneDagNode* sphere = raytracer.addObject( new UnitSphere(), &gold );
    SceneDagNode* sphere2 = raytracer.addObject( new UnitSphere(), &gold );
    SceneDagNode* plane = raytracer.addObject( new UnitSquare(), &jade );

    //set the texture map for the objects of interest in the scene if texture map flag is ON
    if (TEXTURE_MAP_FLAG) {
        // load texture image
        TextureMap txtmp;
        txtmp = TextureMap(TEXTURE_IMG);
        raytracer.setTextureMap(txtmp);

        //for now, we are only using texture map for sphere
        sphere->useTextureMapping = true;
        sphere->obj->setTextureMap(txtmp);
    }


    // Apply some transformations to the unit square.
    double factor1[3] = { 1.0, 2.0, 1.0 };
    double factor2[3] = { 6.0, 6.0, 6.0 };
    raytracer.translate(sphere, Vector3D(0, 0, -5));
    raytracer.rotate(sphere, 'x', -45);
    raytracer.rotate(sphere, 'z', 45);
    raytracer.scale(sphere, Point3D(0, 0, 0), factor1);

    raytracer.translate(plane, Vector3D(0, 0, -7));
    raytracer.rotate(plane, 'z', 45);
    raytracer.scale(plane, Point3D(0, 0, 0), factor2);

    double f[3] = { 0.5, 0.5, 0.5 };
    raytracer.translate(sphere2, Vector3D(0, 0, -8));
    raytracer.scale(sphere2, Point3D(0, 0, 0), f);


    bool DO_SIGNATURE 				= false;
    bool DO_SIGNATURE_SS 			= false;
    bool DO_DIFFUSE 				= false;
    bool DO_PHONG 					= false;
    bool DO_PHONG_SS 				= false;
    bool DO_FULL_FEATURED 			= false;
    bool DO_WOODEN_MONKEY_SCENES 	= true;
    bool DO_REFRACTION_SCENE 		= false;

    bool RENDER_FIRST_VIEW = true;
    bool RENDER_SECOND_VIEW = true;


    raytracer.setReflDepth(0);
    raytracer.setEnvMapMode(Raytracer::NONE);

    // render signature
    if ( DO_SIGNATURE ) {
        raytracer.setAAMode(Raytracer::NONE);
        raytracer.setShadingMode(Raytracer::SCENE_MODE_SIGNATURE);

        if ( RENDER_FIRST_VIEW )
            raytracer.render(width, height, eye1, view1, up, fov, "sig1.bmp");
        if ( RENDER_SECOND_VIEW )
            raytracer.render(width, height, eye2, view2, up, fov, "sig2.bmp");
    }

    // render signature with SS AA
    if ( DO_SIGNATURE_SS ) {
        raytracer.setAAMode(Raytracer::AA_SUPER_SAMPLING);
        raytracer.setShadingMode(Raytracer::SCENE_MODE_SIGNATURE);

        if ( RENDER_FIRST_VIEW )
            raytracer.render(width, height, eye1, view1, up, fov, "sigSS1.bmp");
        if ( RENDER_SECOND_VIEW )
            raytracer.render(width, height, eye2, view2, up, fov, "sigSS2.bmp");
    }

    // render diffuse
    if ( DO_DIFFUSE ) {
        raytracer.setAAMode(Raytracer::NONE);
        raytracer.setShadingMode(Raytracer::SCENE_MODE_DIFFUSE);

        if ( RENDER_FIRST_VIEW )
            raytracer.render(width, height, eye1, view1, up, fov, "diffuse1.bmp");
        if ( RENDER_SECOND_VIEW )
            raytracer.render(width, height, eye2, view2, up, fov, "diffuse2.bmp");
    }

    // render phong
    if ( DO_PHONG ) {
        raytracer.setAAMode(Raytracer::NONE);
        raytracer.setShadingMode(Raytracer::SCENE_MODE_PHONG);

        if ( RENDER_FIRST_VIEW )
            raytracer.render(width, height, eye1, view1, up, fov, "phong1.bmp");
        if ( RENDER_SECOND_VIEW )
            raytracer.render(width, height, eye2, view2, up, fov, "phong2.bmp");
    }

    // phong with super sampling AA
    if ( DO_PHONG_SS ) {
        raytracer.setAAMode(Raytracer::AA_SUPER_SAMPLING);
        raytracer.setShadingMode(Raytracer::SCENE_MODE_PHONG);

        if ( RENDER_FIRST_VIEW )
            raytracer.render(width, height, eye1, view1, up, fov, "phongSS1.bmp");
        if ( RENDER_SECOND_VIEW )
            raytracer.render(width, height, eye2, view2, up, fov, "phongSS2.bmp");
    }

    // refraction if it's turned on
    if (REFRACTION_FLAG) {
        raytracer.setRefractionMode(REFRACTION_FLAG);
    }

    // all features enabled or turned to max
    if ( DO_FULL_FEATURED ) {
        raytracer.setAAMode(Raytracer::NONE);
        raytracer.setAAMode(Raytracer::AA_SUPER_SAMPLING);
        raytracer.setShadingMode(Raytracer::SCENE_MODE_PHONG);
        raytracer.setShadows(Raytracer::SHADOW_CAST);
//		raytracer.setShadows(Raytracer::NONE);
        raytracer.setEnvMapMode(Raytracer::ENV_MAP_CUBE_SKYBOX);
//		raytracer.setEnvMapMode(Raytracer::NONE);
        raytracer.setReflDepth(4);

        if ( raytracer.getEnvMapMode() != Raytracer::NONE ) {
            // load images

            EnvMap env;
            if ( _DEBUG ) {
                env = EnvMap(
                          "EnvMaps/DebugMaps/posx.bmp",
                          "EnvMaps/DebugMaps/posy.bmp",
                          "EnvMaps/DebugMaps/posz.bmp",
                          "EnvMaps/DebugMaps/negx.bmp",
                          "EnvMaps/DebugMaps/negy.bmp",
                          "EnvMaps/DebugMaps/negz.bmp"
                      );
            } else {
                env = EnvMap(
                          "EnvMaps/SaintLazarusChurch/posx.bmp",
                          "EnvMaps/SaintLazarusChurch/posy.bmp",
                          "EnvMaps/SaintLazarusChurch/posz.bmp",
                          "EnvMaps/SaintLazarusChurch/negx.bmp",
                          "EnvMaps/SaintLazarusChurch/negy.bmp",
                          "EnvMaps/SaintLazarusChurch/negz.bmp"
                      );
            }

            raytracer.setEnvMap(env);
        }

        // adjust lighting?
        if ( raytracer.getReflDepth() > 0 ) {
            double l0i = 0.5;
            light0->setAmbient(Colour(l0i, l0i, l0i));
        }

        if ( RENDER_FIRST_VIEW )
            raytracer.render(width, height, eye1, view1, up, fov, "all1.bmp");
        if ( RENDER_SECOND_VIEW )
            raytracer.render(width, height, eye2, view2, up, fov, "all2.bmp");
    }

    // different scenes just for the wooden monkey thing
    if ( DO_WOODEN_MONKEY_SCENES ) {
//		wmonkey_scene_1();
        wmonkey_scene_2();
        // TODO add more scenes here as required...
    }

    //render the 2nd refraction scene
    if ( REFRACTION_FLAG && DO_REFRACTION_SCENE ) {
        refraction_scene_1();
    }

    printf("Press enter to terminate...\n");
    std::string s;
    std::getline(std::cin, s);

    return 0;
}
Beispiel #3
0
/**
 * Wooden Monkey Scene 1
 */
void refraction_scene_1()
{
    printf("REFRACTION SCENE : 1 ----------------------------------\n\n");
    Raytracer rt;
    int width = 16 * 20 * 2;
    int height = 12 * 20 * 2;

    // Camera parameters.
    Point3D eye1(0, 0, 1), eye2(4, 2, 1);
    Vector3D view1(0, 0, -1), view2(-4, -2, -6);
    Vector3D up(0, 1, 0);
    double fov = 60;

    // Defines a material for shading.
    Material gold( Colour(0.3, 0.3, 0.3), Colour(0.75164, 0.60648, 0.22648),
                   Colour(0.628281, 0.555802, 0.366065),
                   51.2, LARGE_SPH_REFLECT, LARGE_SPH_REFRAC_INDX, LARGE_SPH_REFRACT);
    Material jade( Colour(0, 0, 0), Colour(0.54, 0.89, 0.63),
                   Colour(0.316228, 0.316228, 0.316228),
                   12.8);
    // Defines a material for shading.
    Material gold_nonRefract( Colour(0.3, 0.3, 0.3), Colour(0.75164, 0.60648, 0.22648),
                              Colour(0.628281, 0.555802, 0.366065),
                              51.2, 0.8 );

    // Defines a point light source.
    double l0c = 0.5;
    PointLight * light0 = new PointLight(
        Point3D(-2, 2, 5),
        Colour(l0c, l0c, l0c),
        0.2);
    rt.addLightSource(light0);

    // Add a unit square into the scene with material mat.
    SceneDagNode* sphere = rt.addObject( new UnitSphere(), &gold );
    SceneDagNode* sphere2 = rt.addObject( new UnitSphere(), &gold_nonRefract );
    SceneDagNode* plane = rt.addObject( new UnitSquare(), &jade );
    SceneDagNode* sphere3 = rt.addObject( new UnitSphere(), &RED);
    SceneDagNode* sphere4 = rt.addObject( new UnitSphere(), &GREEN_TRANSP);
    SceneDagNode* plane2 = rt.addObject( new UnitSquare(), &jade );
//    SceneDagNode* plane3 = rt.addObject( new UnitSquare(), &jade );
//    SceneDagNode* plane4 = rt.addObject( new UnitSquare(), &jade );

    // Apply some transformations to the unit square.
    double factor1[3] = { 1.0, 2.0, 1.0 };
    double factor2[3] = { 6.0, 6.0, 6.0 };
    rt.translate(sphere, Vector3D(0, 0, -5));
    rt.rotate(sphere, 'x', -45);
    rt.rotate(sphere, 'z', 45);
    rt.scale(sphere, Point3D(0, 0, 0), factor1);

    rt.translate(plane, Vector3D(0, 0, -7));
    rt.rotate(plane, 'z', 45);
    rt.scale(plane, Point3D(0, 0, 0), factor2);

    double f[3] = { 0.5, 0.5, 0.5 };
    rt.translate(sphere2, Vector3D(3, 0, -5));
    rt.scale(sphere2, Point3D(0, 0, 0), f);

    rt.translate(sphere3, Vector3D(0, 2, -5));
    rt.scale(sphere3, Point3D(0, 0, 0), f);

    double f2[3] = { 0.6, 0.6, 0.6 };
    rt.translate(sphere4, Vector3D(-2, 1, -3));
    rt.scale(sphere4, Point3D(0, 0, 0), f2);

    double fp2[3] = { 3.0, 3.0, 3.0 };
    rt.translate(plane2,Vector3D(-4,1,-5));
    rt.rotate(plane2, 'z', 45);
    rt.rotate(plane2, 'y', 45);
    rt.scale(plane2, Point3D(0, 0, 0), fp2);

//    rt.translate(plane3,Vector3D(-2,0,-5));
//    rt.rotate(plane2, 'z', 45);
//    rt.rotate(plane3, 'x', 90);
//	rt.scale(plane3, Point3D(0, 0, 0), fp2);
//
//    rt.translate(plane4,Vector3D(-2,1,-5));
//    rt.rotate(plane2, 'z', 45);
//    rt.rotate(plane4, 'y', 90);
//	rt.scale(plane4, Point3D(0, 0, 0), fp2);

    rt.setAAMode(Raytracer::AA_SUPER_SAMPLING);
    rt.setShadingMode(Raytracer::SCENE_MODE_PHONG);
    rt.setShadows(Raytracer::SHADOW_CAST);
    rt.setEnvMapMode(Raytracer::ENV_MAP_CUBE_SKYBOX);
    rt.setColorSpaceMode(Raytracer::COLOR_ENC_SRGB_GAMMA_CORRECT);
    rt.setReflDepth(4);

    //set the texture map for the objects of interest in the scene if texture map flag is ON
    if (TEXTURE_MAP_FLAG) {
        // load texture image
        TextureMap txtmp;
        txtmp = TextureMap(TEXTURE_IMG);
        TextureMap txtmp2 = TextureMap(TEXTURE_IMG2);
        TextureMap txtmp3 = TextureMap(TEXTURE_IMG3);

        //for now, we are only using texture map for sphere
        sphere->useTextureMapping = true;
        sphere->obj->setTextureMap(txtmp);

        sphere2->useTextureMapping = false;

        sphere4->useTextureMapping = true;
        sphere4->setTextMapOfObject(txtmp2);

        plane2->useTextureMapping = true;
        plane2->setTextMapOfObject(txtmp3);

//        plane3->useTextureMapping = true;
//        plane3->setTextMapOfObject(txtmp3);
//
//        plane4->useTextureMapping = true;
//        plane4->setTextMapOfObject(txtmp3);
    }
    // refraction if it's turned on
    if (REFRACTION_FLAG) {
        rt.setRefractionMode(REFRACTION_FLAG);
    }

    if ( rt.getEnvMapMode() != Raytracer::NONE ) {
        // load images
        EnvMap env;
        if ( _DEBUG ) {
            env = EnvMap(
                      "EnvMaps/DebugMaps/posx.bmp",
                      "EnvMaps/DebugMaps/posy.bmp",
                      "EnvMaps/DebugMaps/posz.bmp",
                      "EnvMaps/DebugMaps/negx.bmp",
                      "EnvMaps/DebugMaps/negy.bmp",
                      "EnvMaps/DebugMaps/negz.bmp"
                  );
        } else {
            env = EnvMap(
                      "EnvMaps/SaintLazarusChurch/posx.bmp",
                      "EnvMaps/SaintLazarusChurch/posy.bmp",
                      "EnvMaps/SaintLazarusChurch/posz.bmp",
                      "EnvMaps/SaintLazarusChurch/negx.bmp",
                      "EnvMaps/SaintLazarusChurch/negy.bmp",
                      "EnvMaps/SaintLazarusChurch/negz.bmp"
                  );
        }

        rt.setEnvMap(env);
    }

    printf("REFRACTION SCENE : 1 :: Rendering...\n");
    rt.render(width, height, eye2, view2, up, fov, "refraction_2.bmp");
    Point3D eye3(0, 0, 1);
    Vector3D view3(0, 0, -1);
    printf("REFRACTION SCENE : 2 :: Rendering...\n");
    rt.render(width, height, eye3, view3, up, fov, "refraction_1.bmp");

    printf("REFRACTION SCENE : 1 :: Done!\n");
}