Esempio n. 1
0
void dofDemo(Raytracer& raytracer, Material& glass, Material& jade, Material& gold, Material& weird, Material& shiny ){
	// Defines a point light source.
	raytracer.setAmbientLight(Colour(0.9, 0.9, 0.9));
	raytracer.addLightSource( new PointLight(Point3D(0, 0, 5), 
				Colour(0.9, 0.9, 0.9)) );
	raytracer.addLightSource( new PointLight(Point3D(0, 5, -5), 
				Colour(0.4, 0.4, 0.4)) );


	// 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* sphere3 = raytracer.addObject( new UnitSphere(), &gold );
	SceneDagNode* sphere4 = raytracer.addObject( new UnitSphere(), &gold );
	SceneDagNode* sphere5 = raytracer.addObject( new UnitSphere(), &gold );

	// Apply some transformations to the unit square.
	raytracer.translate(sphere , Vector3D(-3  , -1  , -5));	
	raytracer.translate(sphere2, Vector3D(-1.5, -0.5, -7));	
	raytracer.translate(sphere3, Vector3D( 0  , -0  , -9));	
	raytracer.translate(sphere4, Vector3D( 1.5,  0.5, -11));	
	raytracer.translate(sphere5, Vector3D( 3  ,  1  , -13));	

}
Esempio n. 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 = 320;
    int height = 240;
    int aa = 2;
    int sceneNum = 0;

    double toRadian = 2*M_PI/360.0;

    fprintf(stderr, "Using options:\n");

#ifdef USE_EXTENDEDLIGHTS
    fprintf(stderr, "\tExtended light sources\n");
#else
    fprintf(stderr, "\tPoint light sources\n");
#endif

#ifdef USE_REFRACTIONS
    fprintf(stderr, "\tRefractions\n");
#else
    fprintf(stderr, "\tNo refractions\n");
#endif

#ifdef USE_REFLECTIONS
    fprintf(stderr, "\tReflections\n");
#else
    fprintf(stderr, "\tNo reflections\n");
#endif

#ifdef IGNORE_SHADOWS
    fprintf(stderr, "\tNo shadows\n");
#else
    {
#ifdef USE_TRANSMISSIONSHADOWS
        fprintf(stderr, "\tTransmission-based shadows\n");
#else
        fprintf(stderr, "\tSimple shadows\n");
#endif
    }
#endif

#ifdef USE_FINERFLUX
    fprintf(stderr, "\tFiner numerical flux intergrations\n");
#else
    fprintf(stderr, "\tCoarser numerical flux intergrations\n");
#endif


    if (argc == 3) {
        width = atoi(argv[1]);
        height = atoi(argv[2]);
    } else if (argc == 4) {
        width = atoi(argv[1]);
        height = atoi(argv[2]);
        aa = atoi(argv[3]);
    } else if (argc == 5) {
        width = atoi(argv[1]);
        height = atoi(argv[2]);
        aa = atoi(argv[3]);
        sceneNum = atoi(argv[4]);
    }
    // SceneNum should not exceed total scenes
    if ((sceneNum > 3)|| (sceneNum <0)) {
        sceneNum = 0;
    }
    // Camera parameters.
    Point3D eye(0, 0, 1);
    Vector3D view(0, 0, -1);
    Vector3D up(0, 1, 0);
    double fov = 60;


    // Defines materials 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, 0.001, 0.0, 1/2.4 );
    Material jade( Colour(0.22, 0.38, 0.33), Colour(0.52, 0.73, 0.57),
                   Colour(0.316228, 0.316228, 0.316228),
                   12.8, 0.2 , 0.0, 0.0 );
    Material polishedGold( Colour(0.24725, 0.2245, 0.0645), Colour(0.34615, 0.3143, 0.0903),
                           Colour(0.797357, 0.723991, 0.208006), 83.2, 0.01,0.0,0.0);

    Material glass( Colour(0.15, 0.15, 0.15), Colour(0.08, 0.08, 0.08),
                    Colour(0.2, 0.2, 0.2), 50.1,0.08,0.9,0.6667 );

    Material glass1( Colour(0.2, 0.2, 0.2), Colour(0.2, 0.2, 0.2),
                     Colour(0.7, 0.7, 0.7), 10.1,0.03,0.9,0.6667 );


    Material steel( Colour(0.1, 0.1, 0.1), Colour(0.1, 0.1, 0.1),
                    Colour(0.8, 0.8, 0.8), 80, 0.03, 0.0, 1.0 );

    Material blueSolid( Colour(0, 0, 1), Colour(0, 0, 1),
                        Colour(0, 0, 0), 0, 0.0, 0.0, 1.0 );

    Material redSolid( Colour(1, 0, 0), Colour(1, 0, 0),
                       Colour(0, 0, 0), 0, 0.0, 0.0, 1.0 );

    Material chrome( Colour(0.25, 0.25, 0.25), Colour(0.4,0.4,0.4),
                     Colour(0.7746, 0.7746, 0.7746), 77, 0.42, 0.0, 1.0);

    Material ruby( Colour(0.1745, 0.01175, 0.01175), Colour(0.61424, 0.04136, 0.04136),
                   Colour(0.727811, 0.626959, 0.626959) , 76.8, 0.01, 0.0, 0.565);

    Material pearl( Colour(0.25, 0.20725, 0.20725), Colour(1, 0.829, 0.829),
                    Colour(0.296648, 0.296648, 0.296648), 11.264, 0.1,0.0,1.0 );

    Material silver(Colour(0.23125, 0.23125, 0.23125), Colour(0.2775, 0.2775, 0.2775),
                    Colour(0.773911, 0.773911, 0.773911), 89.6, 0.4,0.0, 1.0);

    Material emerald(Colour(0.0215, 0.1745, 0.0215),Colour(0.07568, 0.61424, 0.07568),
                     Colour(0.633, 0.727811, 0.633), 76.8, 0.1, 0.25, 0.637);

    Material brass(Colour(0.329412, 0.223529,  0.027451),Colour(0.780392, 0.568627, 0.113725),
                   Colour(0.992157, 0.941176, 0.807843),27.8974, 0.3, 0.0, 1.0 );

    Material bronze(Colour(0.2125, 0.1275, 0.054), Colour(0.714, 0.4284, 0.18144),
                    Colour(0.393548, 0.271906, 0.166721), 25.6, 0.1, 0.0, 1.0 );

    Material bronzeShiny(Colour(0.25, 0.148, 0.06475), Colour(0.4, 0.2368, 0.1036),
                         Colour(0.774597, 0.458561, 0.200621), 76.86, 0.15, 0.0, 1.0 );

    Material turquoise(Colour(0.1, 0.18725, 0.1745), Colour(0.396, 0.74151, 0.69102),
                       Colour(0.297254, 0.30829, 0.306678), 12.8, 0.01, 0.2, 0.9);

    Material obsidian(Colour(0.05375, 0.05, 0.06625), Colour(0.18275, 0.17, 0.22525),
                      Colour(0.332741, 0.328634, 0.346435), 38.4, 0.05, 0.18, 0.413);

    Material copper(Colour(0.19125, 0.0735, 0.0225), Colour(0.7038, 0.27048, 0.0828),
                    Colour(0.256777, 0.137622, 0.086014), 12.8, 0.1, 0.0, 1.0 );

    Material copperPolished(Colour(0.2295, 0.08825, 0.0275), Colour(0.5508, 0.2118, 0.066),
                            Colour(0.580594, 0.223257, 0.0695701), 51.2, 0.15, 0.0, 1.0 );

    Material pewter(Colour(0.105882, 0.058824, 0.113725), Colour(0.427451, 0.470588, 0.541176),
                    Colour(0.333333, 0.333333, 0.521569), 9.84615, 0.0, 0.0, 1.0 );


    // Light Sources
    //=====================
    //raytracer.addLightSource( new PointLight(Point3D(1, 1, 2),Colour(0.5, 0.5, 0.5)) );

#ifdef USE_EXTENDEDLIGHTS
    // Defines a ball light source
    raytracer.addLightSource( new BallLight(Point3D(-1, 1, 1),
                                            2.0, Colour(0.9, 0.9, 0.9), 4) );
#else
    // Defines a point light source.
    raytracer.addLightSource( new PointLight(Point3D(0, 0, 5),
                              Colour(0.9, 0.9,0.9) ) );
#endif


    if (sceneNum==0) {

        // Defines a point light source.
        //raytracer.addLightSource( new PointLight(Point3D(0, 0, 5),
        //			Colour(0.9, 0.9, 0.9) ) );

        // Add a unit square into the scene with material mat.
        SceneDagNode* sphere = raytracer.addObject( new UnitSphere(), &gold);
        SceneDagNode* plane = raytracer.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, 1.0 };
        double factor3[3] = { 4.0, 4.0, 4.0 };
        double factor4[3] = { 3.7, 3.7, 3.7 };
        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);
        /*
        SceneDagNode* bigSphere = raytracer.addObject( new UnitSphere(), &glass1);
        raytracer.scale(bigSphere, Point3D(0, 0, 0), factor3);
        raytracer.translate(bigSphere, Vector3D(0, 0, -7));

        SceneDagNode* bigSphere2 = raytracer.addObject( new UnitSphere(), &glass1);
        raytracer.scale(bigSphere2, Point3D(0, 0, 0), factor4);
        raytracer.translate(bigSphere2, Vector3D(0, 0, -7));
        */

    }// end of scene 0

    if (sceneNum==1) {
        /*
        raytracer.addLightSource( new BallLight(Point3D(-1, 1, 1),
        	5.0, Colour(0.9, 0.9, 0.9), 0.888) );
        raytracer.addLightSource( new PointLight(Point3D(0, 0, 2),Colour(0.5, 0.5, 0.5)) );
        */

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


        // Apply some transformations to the unit square.
        double factor1[3] = { 1.0, 2.0, 1.0 };
        double factor2[3] = { 6.0, 6.0, 1.0 };
        double factor3[3] = { 0.5, 0.5, 2.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(sphere1, Vector3D(-2.5, 0, -5));

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


        raytracer.translate(cylinder, Vector3D(3, 0, -5));
        //raytracer.rotate(cylinder, 'y', -20);
        raytracer.rotate(cylinder, 'z', 45);
        raytracer.rotate(cylinder, 'x', -75);
        raytracer.scale(cylinder, Point3D(0, 0, 0), factor3);

    }// end of scene1


    //=============== Scene 2 ==============================
    //=====================================================

    if(sceneNum == 2) {
        /*
        raytracer.addLightSource( new BallLight(Point3D(-1, 1, 1),
        	5.0, Colour(0.9, 0.9, 0.9), 0.888) );*/
        //raytracer.addLightSource( new PointLight(Point3D(0, 0, 2),Colour(0.5, 0.5, 0.5)) );

        //Set up walls
        //========================================================

        SceneDagNode* planeBack = raytracer.addObject( new UnitSquare(), &brass);
        SceneDagNode* planeBottom = raytracer.addObject( new UnitSquare(), &chrome);
        SceneDagNode* planeTop = raytracer.addObject( new UnitSquare(), &copperPolished);
        SceneDagNode* planeLeft = raytracer.addObject( new UnitSquare(), &bronzeShiny);
        SceneDagNode* planeRight = raytracer.addObject( new UnitSquare(), &brass);
        SceneDagNode* planeRear = raytracer.addObject( new UnitSquare(), &brass);

        double scaleFactor[3] = {8.0,8.0,1.0};
        double scaleFactor1[3] = {20.01,20.01,1.0};

        raytracer.translate(planeBottom, Vector3D(0, -10, 0));
        raytracer.translate(planeTop, Vector3D(0, 10, 0));
        raytracer.translate(planeLeft, Vector3D(-10, 0, 0));

        raytracer.translate(planeRight, Vector3D(10, 0, 0));

        raytracer.translate(planeBack, Vector3D(0, 0, -19.9));
        raytracer.translate(planeBottom, Vector3D(0, 0, -10));
        raytracer.translate(planeTop, Vector3D(0, 0, -10));
        raytracer.translate(planeLeft, Vector3D(0, 0, -10));
        raytracer.translate(planeRight, Vector3D(0, 0, -10));
        raytracer.translate(planeRear, Vector3D(0, 0, 20));

        raytracer.rotate(planeTop, 'x', 90);
        raytracer.rotate(planeBottom, 'x',-90);
        raytracer.rotate(planeLeft, 'y', -90);
        raytracer.rotate(planeRight, 'y', 90);
        raytracer.rotate(planeRear, 'x', 180);

        raytracer.scale(planeBack, Point3D(0, 0, 0), scaleFactor1);
        raytracer.scale(planeBottom, Point3D(0, 0, 0), scaleFactor1);
        raytracer.scale(planeTop, Point3D(0, 0, 0), scaleFactor1);
        raytracer.scale(planeLeft, Point3D(0, 0, 0), scaleFactor1);
        raytracer.scale(planeRight, Point3D(0, 0, 0), scaleFactor1);
        raytracer.scale(planeRear, Point3D(0, 0, 0), scaleFactor1);
        //===========================================================

        double scaleEgg[3] = { 1.0, 1.5, 1.0 };
        double scaleBall[3] = {2,2,2};
        SceneDagNode* sphere = raytracer.addObject( new UnitSphere(), &glass1);
        SceneDagNode* sphere1 = raytracer.addObject( new UnitSphere(), &ruby);
        SceneDagNode* sphere2 = raytracer.addObject( new UnitSphere(), &chrome);

        //SceneDagNode* cone = raytracer.addObject(sphere, new UnitCone(), &emerald);

        //raytracer.translate(cone, Vector3D(0,0,-2));
        raytracer.translate(sphere, Vector3D(-1,-1,-11));
        raytracer.scale(sphere, Point3D(0,0,0), scaleBall);

        raytracer.translate(sphere1, Vector3D(2.5,-1,-11));
        raytracer.translate(sphere2, Vector3D(2,3,-11));
        //raytracer.translate(cone, Vector3D(-1,-1,-12));
        raytracer.rotate(sphere1, 'z', -45);
        raytracer.scale(sphere1, Point3D(0,0,0), scaleEgg);
        //raytracer.rotate(cone, 'x', 90);

    }//end of scene 2


    //==================== Scene 3 =================
    //===============================================


    if(sceneNum == 3) {

#ifdef USE_EXTENDEDLIGHTS
        raytracer.addLightSource( new BallLight(Point3D(-5, 5, -3),
                                                2.0, Colour(0.4, 0.4, 0.4), 2) );
        raytracer.addLightSource( new BallLight(Point3D(5, 5, -3),
                                                2.0, Colour(0.4, 0.4, 0.4), 2) );
#else
        raytracer.addLightSource( new PointLight(Point3D(-5, 5, 0),
                                  Colour(0.5, 0.0, 0.0) ) );
        raytracer.addLightSource( new PointLight(Point3D(5, 5, 0),
                                  Colour(0.0, 0.5, 0.0) ) );
        raytracer.addLightSource( new PointLight(Point3D(0, -5, 0),
                                  Colour(0.0, 0.0, 0.5) ) );
#endif

        double planeScale[3] = {10.0, 10.0, 1.0};
        double sphereScale[3]= {1.5,1.5,1.5};
        double coneScale[3] = {1.5,1.5,5};

        SceneDagNode* plane = raytracer.addObject( new UnitSquare(), &pearl);
        SceneDagNode* sphere1 = raytracer.addObject( new UnitSphere(), &chrome);
        SceneDagNode* sphere2 = raytracer.addObject( new UnitSphere(), &brass);
        //SceneDagNode* cone = raytracer.addObject( new UnitCone(), &turquoise);

        raytracer.translate(sphere1, Vector3D(1, 1.5, -6.5));
        raytracer.translate(sphere2, Vector3D(-1, -1.5, -6.5));
        raytracer.scale(sphere2, Point3D(0,0,0), sphereScale);
        raytracer.scale(sphere1, Point3D(0,0,0), sphereScale);

        raytracer.rotate(plane, 'z', 45);
        raytracer.scale(plane, Point3D(0,0,0), planeScale);
        raytracer.translate(plane, Vector3D(0, 0, -8));
        /*
        		raytracer.translate(cone, Vector3D(2.0,-1.0,-3));
        		raytracer.rotate(cone, 'x', 180);
        		raytracer.scale(cone, Point3D(0,0,0), coneScale); */
    }

    // Render the scene, feel free to make the image smaller for
    // testing purposes.

    raytracer.render(width, height, eye, view, up, fov, aa,  "sig1.bmp", 's');
    //raytracer.render(width, height, eye, view, up, fov, aa, "diffuse1.bmp",'d');
    //raytracer.render(width, height, eye, view, up, fov, aa, "view1.bmp",'p');





    // Render it from a different point of view.
    Point3D eye2(4, 2, 1);
    Vector3D view2(-4, -2, -6);

    raytracer.render(width, height, eye2, view2, up, fov, aa, "sig2.bmp", 's');
    //raytracer.render(width, height, eye2, view2, up, fov, aa, "diffuse2.bmp",'d');
    //raytracer.render(width, height, eye2, view2, up, fov, aa, "view2.bmp",'p');



    Point3D eye3(-4, -2, 1);
    Vector3D view3(4, 2, -6);

    raytracer.render(width, height, eye3, view3, up, fov, aa, "sig3.bmp", 's');
    //raytracer.render(width, height, eye3, view3, up, fov, aa, "diffuse3.bmp",'d');
    raytracer.render(width, height, eye3, view3, up, fov, aa, "view3.bmp",'p');




    return 0;
}
Esempio n. 3
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 = 320; 
	int height = 240; 

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

	// Camera parameters.
	Point3D eye(0., 0., 1.);
	Vector3D view(0., 0., -1.);
	Vector3D up(0., 1., 0.);
	double fov = 60;

	// Defines a material for shading.
    Material::Ptr gold = std::make_shared<Material>( Colour(0.3, 0.3, 0.3), Colour(0.75164, 0.60648, 0.22648), 
			Colour(0.628281, 0.555802, 0.366065), 
			51.2 );
    Material::Ptr jade = std::make_shared<Material>( Colour(0, 0, 0), Colour(0.54, 0.89, 0.63), 
			Colour(0.316228, 0.316228, 0.316228), 
			12.8 );

	// Defines a point light source.
	raytracer.addLightSource( std::make_shared<PointLight>(Point3D(0., 0., 5.), 
				Colour(0.9, 0.9, 0.9) ) );

	// Add a unit square into the scene with material mat.
    SceneDagNode::Ptr sphere = raytracer.addObject( std::make_shared<UnitSphere>(), gold );
    SceneDagNode::Ptr plane = raytracer.addObject( std::make_shared<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 };
	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);

	// Render the scene, feel free to make the image smaller for
	// testing purposes.	
	raytracer.render(width, height, eye, view, up, fov, "view1.bmp");
	
	// Render it from a different point of view.
	Point3D eye2(4., 2., 1.);
	Vector3D view2(-4., -2., -6.);
	raytracer.render(width, height, eye2, view2, up, fov, "view2.bmp");
	
	return 0;
}
Esempio n. 4
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;

	//_render_mode = MODE_SIGNATURE;
	//_render_mode = MODE_SPECULAR;
	_render_mode = MODE_FULL_PHONG;
	//_render_mode = (mode)(MODE_AMBIENT | MODE_DIFFUSE);
	int width = 320; 
	int height = 240; 

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

	// Camera parameters.
	Point3D eye(0, 0, 1);
	Vector3D view(0, 0, -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 );
	Material jade( Colour(0, 0, 0), Colour(0.54, 0.89, 0.63), 
			Colour(0.316228, 0.316228, 0.316228), 
			12.8 );

	// Defines a point light source.
	raytracer.addLightSource( new PointLight(Point3D(0, 0, 5), 
				Colour(0.9, 0.9, 0.9) ) );

	// Add a unit square into the scene with material mat.
	SceneDagNode* sphere = raytracer.addObject( new UnitSphere(), &gold );
	SceneDagNode* plane = raytracer.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 };
	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);

	// Render the scene, feel free to make the image smaller for
	// testing purposes.	
	raytracer.render(width, height, eye, view, up, fov, "phong1.bmp");
	
	// Render it from a different point of view.
	Point3D eye2(4, 2, 1);
	Vector3D view2(-4, -2, -6);
	raytracer.render(width, height, eye2, view2, up, fov, "phong2.bmp");
	
	return 0;
}
Esempio n. 5
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 = 320; 
	int height = 240; 

	if (argc == 3) {
		width = atoi(argv[1]);
		height = atoi(argv[2]);
	}
    
/***********************************************************Testing ********************************
    // Camera parameters.
    Point3D eye(0, 0, 1);
    Vector3D view(0, 0, -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,0.3,0,NULL );
    Material jade( Colour(0, 0, 0), Colour(0.54, 0.89, 0.63),
                  Colour(0.316228, 0.316228, 0.316228),
                  12.8,0.3,0,NULL);
    
    // Defines a point light source.
    raytracer.addLightSource( new PointLight(Point3D(0.0, 0, 5),
                                             Colour(0.9, 0.9, 0.9) ) );
    
    // Add a unit square into the scene with material mat.
    SceneDagNode* sphere = raytracer.addObject( new UnitSphere(), &gold );
    SceneDagNode* plane = raytracer.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 };
    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);
    
    
    // Render the scene, feel free to make the image smaller for
    // testing purposes.
    raytracer.render(width, height, eye, view, up, fov, "view4.bmp");
    
    // Render it from a different point of view.
    Point3D eye2(4, 2, 1);
    Vector3D view2(-4, -2, -6);
    raytracer.render(width, height, eye2, view2, up, fov, "view5.bmp");
***********************************************************Testing ********************************/
/***********************************************************Final Scene********************************/
    // Camera parameters.
//	Point3D eye(0, 8, -3);
//	Vector3D view(0, -1,0);
    Point3D eye(0, 0, 1);
    Vector3D view(0, 0, -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,0.2,NULL);
//	Material jade( Colour(0, 0, 0), Colour(0.54, 0.89, 0.63), 
//			Colour(0.316228, 0.316228, 0.316228), 
//			12.8,0.5,NULL);
    Material jade( Colour(0, 0, 0), Colour(0.47, 0.576, 0.859),
                  Colour(0.316228, 0.316228, 0.316228),
                  12.8,0.5,NULL);
    Material red( Colour(0.3, 0.3, 0.3), Colour(1, 0, 0),
                 Colour(0.628281, 0.555802, 0.366065),
                 51.2,0.2,NULL);
    
    Material white( Colour(0.3, 0.3, 0.3), Colour(1, 0.8549, 0.7255),
                 Colour(0.628281, 0.555802, 0.366065),
                 51.2,0.2,NULL);
    Material pink( Colour(0.3, 0.3, 0.3), Colour(0.9412, 0.502, 0.502),
                   Colour(0.628281, 0.555802, 0.366065),
                   51.2,0.2,NULL);
    
    Material mirror( Colour(0.0, 0.0, 0.0), Colour(0.0, 0.0, 0.0),
                 Colour(0.0, 0.0, 0.0),
                 51.2,1,NULL);
    
    Material glass( Colour(0.3, 0.3, 0.3), Colour(1, 1, 1),
                    Colour(0.628281, 0.555802, 0.366065),
                    51.2,0,1,NULL);
    glass.R_index = 1.3;
    glass.transparency_coef=1;
	// Defines a point light source.
	raytracer.addLightSource( new PointLight(Point3D(0, 0, 5),
				Colour(0.9, 0.9, 0.9) ) );

    raytracer.addLightSource( new PointLight(Point3D(0, 6, -1),
                                             Colour(0.9, 0.3, 0.1) ) );
    
    Material test( Colour(0.3, 0.3, 0.3), Colour(0.3, 0.60648, 0.22648),
                  Colour(0.628281, 0.555802, 0.366065),
                  51.2 ,0.1,NULL);
    
    Material test3( Colour(0.3, 0.3, 0.3), Colour(0.3, 0.5, 0.22648),
                  Colour(0.628281, 0.555802, 0.366065),
                  51.2,1,NULL );
    
    Material test2( Colour(0, 0, 0), Colour(0.3, 0.3, 0.3),
                   Colour(1.0, 1.0, 1.0),
                   51.2,0,NULL );
    Texture sky("/Users/bingxu/Documents/graphics/COMP3271_assignment_4_template/raytracerMacOS/sky.bmp");
    Texture board("/Users/bingxu/Documents/graphics/COMP3271_assignment_4_template/raytracerMacOS/board.bmp");
    Material starrysky(Colour(0, 0, 0),Colour(0, 0, 0),
                       Colour(0.1, 0.1, 0.1), 11.264, 0, &sky);
    
    Material board_mat(Colour(0, 0, 0),Colour(0, 0, 0),
                       Colour(0.1, 0.1, 0.1), 11.264, 1, &board);
    
   
    SceneDagNode* plane = raytracer.addObject( new UnitSquare(), &jade );
    SceneDagNode* plane1 = raytracer.addObject( new UnitSquare(), &jade );
    SceneDagNode* plane2 = raytracer.addObject( new UnitSquare(), &board_mat );//the bottom
   
    
    SceneDagNode* sphere = raytracer.addObject( new UnitSphere(), &mirror);
    SceneDagNode* sphere1 = raytracer.addObject( new UnitSphere(), &white );
    SceneDagNode* mars = raytracer.addObject( new UnitSphere(), &glass );
    SceneDagNode* earth = raytracer.addObject( new UnitSphere(), &pink );
    
    SceneDagNode* cylinder1 = raytracer.addObject( new UnitFiniteCylinder(), &gold );
    SceneDagNode* cylinder2 = raytracer.addObject( new UnitFiniteCylinder(), &gold );
    SceneDagNode* cylinder3 = raytracer.addObject( new UnitFiniteCylinder(), &gold );
    SceneDagNode* cone = raytracer.addObject( new UnitFiniteCone(), &red );


        double factor1[3] = { 2.0, 2.0, 2.0 };
        double factor2[3] = {50,50,50};
        double factor3[3] = { 1.0, 1.0, 1.0};
        double factor4[3] = { 1.0, 2, 1.0};
        double factor5[3] = {0.5,0.5,0.5};
        double factor6[3] = {0.5,1.5,0.5};
        double factor7[3] = {1.0,4.0,1.0};
    //3 squares
    	raytracer.translate(plane, Vector3D(0, 0, -15));
    	raytracer.scale(plane, Point3D(0, 0, 0), factor2);
    
        raytracer.translate(plane1, Vector3D(-15, 0, 0));
        raytracer.rotate(plane1, 'y', 90);
        raytracer.scale(plane1, Point3D(0, 0, 0), factor2);
   
        raytracer.translate(plane2, Vector3D(0, -8, 0));
        raytracer.rotate(plane2, 'x', -90);
        raytracer.scale(plane2, Point3D(0, 0, 0), factor2);

    //four balls
    raytracer.translate(sphere, Vector3D(-1, -6, -2));
    raytracer.scale(sphere, Point3D(0, 0, 0), factor3);
    
    
    raytracer.translate(sphere1,Vector3D(-4.5, -6, 1));
    raytracer.scale(sphere1, Point3D(0, 0, 0), factor3);
    
    raytracer.translate(mars, Vector3D(3, -3, -1));
    raytracer.scale(mars, Point3D(0, 0, 0), factor3);

   
    raytracer.translate(earth, Vector3D(-8, -6, -2));
    raytracer.scale(earth, Point3D(0, 0, 0), factor3);
    
    
    raytracer.rotate(cylinder1, 'z', -30);
    //raytracer.rotate(cylinder1, 'x', -15);
    raytracer.translate(cylinder1, Vector3D(0, -4, -2));
    raytracer.scale(cylinder1, Point3D(0, 0, 0), factor7);
   
    raytracer.rotate(cylinder2, 'z', -30);
    raytracer.translate(cylinder2, Vector3D(1.5, -3, -2));
    raytracer.scale(cylinder2, Point3D(0, 0, 0), factor6);
    
    raytracer.rotate(cylinder3, 'z', -30);
    raytracer.translate(cylinder3, Vector3D(-1.5, -3, -2));
    raytracer.scale(cylinder3, Point3D(0, 0, 0), factor6);
    
     raytracer.rotate(cone, 'z', -30);
     raytracer.translate(cone, Vector3D(0, 2, -2));
     raytracer.scale(cone, Point3D(0, 0, 0), factor4);
    
    std::clock_t start;
    double duration;
    
    start = std::clock();
   // raytracer.render(width, height, eye, view, up, fov, "view4.bmp");
    duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
    
    //std::cout<<"The rendering duration 1 is .......: "<< duration <<'\n';
    // Render it from a different point of view.
    
    Point3D eye2(3, 1, 5);
    Vector3D view2(-10, -8, -15);

    
    std::clock_t start1;
    double duration1;
    
    start1 = std::clock();
    raytracer.render(width, height, eye2, view2, up, fov, "view5.bmp");
    duration1 = ( std::clock() - start1 ) / (double) CLOCKS_PER_SEC;
    
   // std::cout<<"The rendering duration 2 is .......: "<< duration1 <<'\n';
    
    
    /***********************************************************Final Scene********************************/

        return 0;
}
Esempio n. 6
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 = 160; 
	int height = 120; 

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

	// Camera parameters.
	Point3D eye(0, 0, 1);
	Vector3D view(0, 0, -1);
	Vector3D up(0, 1, 0);
	double fov = 60;

	// Defines a material for shading.
	Material chrome( Colour(0.25, 0.25, 0.25), Colour(0.4, 0.4, 0.4),
            Colour(0.774597, 0.774597, 0.774597),
            51.2 );
	Material jade( Colour(0, 0, 0), Colour(0.54, 0.89, 0.63), 
			Colour(0.316228, 0.316228, 0.316228), 
			12.8 );

	// Defines a point light source.
	raytracer.addLightSource( new PointLight(Point3D(0, 3, 2), 
				Colour(0.9, 0.9, 0.9) ) );

	// Add a unit square into the scene with material mat.
	SceneDagNode* sphere = raytracer.addObject( new UnitSphere(), &chrome );
	SceneDagNode* plane = raytracer.addObject( new UnitSquare(), &jade );
	//SceneDagNode* sphere2 = raytracer.addObject( new UnitSphere(), &chrome );
	
	// 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(sphere2, Vector3D(0, 0, -2));	
	//raytracer.rotate(sphere2, 'x', -45); 
	//raytracer.rotate(sphere2, 'z', 45);

	raytracer.translate(plane, Vector3D(0, -3, -5));	
	raytracer.rotate(plane, 'x', -80); 
	raytracer.scale(plane, Point3D(0, 0, 0), factor2);

	// Render the scene, feel free to make the image smaller for
	// testing purposes.	
	raytracer.render(width, height, eye, view, up, fov, "view1.bmp", 3, 5, true);
	
	// Render it from a different point of view.
	Point3D eye2(4, 2, 1);
	Vector3D view2(-4, -2, -6);
	//raytracer.render(width, height, eye2, view2, up, fov, "view2.bmp", 3, 15, false);


	//std::cin.get();


	return 0;
}
Esempio n. 7
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;
}
Esempio n. 8
0
/**
 * Wooden Monkey Scene 1
 */
void wmonkey_scene_1()
{
    printf("WOODEN MONKEY 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, 0.8 );
    Material jade( Colour(0, 0, 0), Colour(0.54, 0.89, 0.63),
                   Colour(0.316228, 0.316228, 0.316228),
                   12.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 );
    SceneDagNode* plane = 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.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);

    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 : 1 :: Rendering...\n");
    rt.render(width, height, eye2, view2, up, fov, "wmonkey_1.bmp");
    printf("WOODEN MONKEY SCENE : 1 :: Done!\n");
}
Esempio n. 9
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");
}
Esempio n. 10
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");
}