Пример #1
0
bulb_row2(int x, int y){ //displays header top and bottom borders

	gray(0+x,0+y);
	light2(0+x,0+y,BLUE);

	gray(31+x,0+y);
	light2(31+x,0+y,YELLOW);

	gray(62+x,0+y);
	light2(62+x,0+y,BLUE);

	gray(93+x,0+y);
	light2(93+x,0+y,YELLOW);

	gray(124+x,0+y);
	light2(124+x,0+y,BLUE);

	gray(155+x,0+y);
	light2(155+x,0+y,YELLOW);

	gray(186+x,0+y);
	light2(186+x,0+y,BLUE);

	gray(217+x,0+y);
	light2(217+x,0+y,YELLOW);

	gray(248+x,0+y);
	light2(248+x,0+y,BLUE);

	gray(279+x,0+y);
	light2(279+x,0+y,YELLOW);


}
Пример #2
0
bulb_pair2(int x, int y){

	gray(0+x,0+y);
	light2(0+x,0+y,BLUE);

	gray(279+x,0+y);
	light2(279+x,0+y,YELLOW);
}
Пример #3
0
void setup_plastic(void)
{
    boost::shared_ptr<shade::GLSLTexture> texture(new shade::GLSLTexture(GL_TEXTURE_2D, GL_TEXTURE_2D_ARRAY_EXT));
    texture->bind();
    glTexParameterf(GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameterf(GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    Texture texture_data("examples/patterns.dds", 4);
    texture_data.upload();

    boost::shared_ptr<ArrayPlastic> specular(new ArrayPlastic(0.7, .3));
    specular->texture_unit.set(texture);
    boost::shared_ptr<shade::shaders::ObjectSpace> object_space(new shade::shaders::ObjectSpace);
    specular->coordinate_system = object_space;
    boost::shared_ptr<shade::shaders::UVCoord> uvcoord(new shade::shaders::UVCoord);
    specular->uv = uvcoord;
    shader->material = specular;
    {
        shaders::IlluminatedMaterial::LightList::Accessor accessor(specular->lights);

        boost::shared_ptr<shaders::PointLight> light(new shaders::PointLight);
        light->position.set_value(shade::vec3<>(30., 15., 10.));
        light->color.set_value(shade::vec3<>(1., 1., 1.));
        accessor->push_back(light);

        boost::shared_ptr<shaders::PointLight> light2(new shaders::PointLight);
        light2->position.set_value(shade::vec3<>(-15., -3, 0.));
        light2->color.set_value(shade::vec3<>(1., 1., 1.));
        accessor->push_back(light2);
    }
}
Пример #4
0
void setup_plastic_with_texture(void)
{
  boost::shared_ptr<shade::shaders::Plastic> specular(new shade::shaders::Plastic(0.7, .3));
  boost::shared_ptr<shade::shaders::ObjectSpace> object_space(new shade::shaders::ObjectSpace);
  boost::shared_ptr<shade::shaders::Texture2D> tex(new shade::shaders::Texture2D);
  tex->texture_unit.set(example::make_texture("examples/pattern.dds"));
  boost::shared_ptr<shade::shaders::UVCoord> uvcoord(new shade::shaders::UVCoord);
  tex->uv = uvcoord;
  specular->color = tex;
  specular->coordinate_system = object_space;
  shader->material = specular;
  {
    shaders::IlluminatedMaterial::LightList::Accessor accessor(specular->lights);

    boost::shared_ptr<shaders::PointLight> light(new shaders::PointLight);
    light->position.set_value(shade::vec3<>(30., 15., 10.));
    light->color.set_value(shade::vec3<>(1., 1., 1.));
    accessor->push_back(light);

    boost::shared_ptr<shaders::PointLight> light2(new shaders::PointLight);
    light2->position.set_value(shade::vec3<>(-15., -3, 0.));
    light2->color.set_value(shade::vec3<>(1., 1., 1.));
    accessor->push_back(light2);
  }
}
Пример #5
0
boost::shared_ptr<shade::Program> setup_shading(boost::shared_ptr<shade::GLSLWrapper> state)
{
    boost::shared_ptr<shade::shaders::Surface> shader(new shade::shaders::Surface);
    boost::shared_ptr<shade::Program> program(new shade::Program(shader, state));

    boost::shared_ptr<shade::shaders::Plastic> specular(new shade::shaders::Plastic(0.4, .6));
    boost::shared_ptr<shade::shaders::ObjectSpace> object_space(new shade::shaders::ObjectSpace);
    specular->color.set_value(shade::vec4<>(1., 0.4, 0.4, 1.));
    specular->coordinate_system = object_space;
    shader->material = specular;
    {
        shade::shaders::IlluminatedMaterial::LightList::Accessor accessor(specular->lights);

        boost::shared_ptr<shade::shaders::PointLight> light(new shade::shaders::PointLight);
        boost::shared_ptr<shade::shaders::GLLightPosition> gl_light_pos(new shade::shaders::GLLightPosition);
        boost::shared_ptr<shade::shaders::Vec4ToVec3> light_pos(new shade::shaders::Vec4ToVec3);
        gl_light_pos->index.set(1);
        light_pos->value = gl_light_pos;
        light->position = light_pos;
        light->color.set_value(shade::vec3<>(1., 1., 1.));
        accessor->push_back(light);

        boost::shared_ptr<shade::shaders::DirectionalLight> light2(new shade::shaders::DirectionalLight);
        light2->direction.set_value(shade::vec3<>(0., 1., 0.));
        light2->color.set_value(shade::vec3<>(1., 0., 0.));
        accessor->push_back(light2);
    }

    return program;
}
Пример #6
0
void buildAndRenderScene(Scene &scene, Camera &camera, RenderTarget &renderTarget)
{
    // Build scene
    AmbientLight        ambientLight(Color::white);
    PointLight          light1(Vector3D(50.0, 70.0, 0.0));
    PointLight          light2(Vector3D(50.0, 70.0, 200.0));

    Torus               sphere1(10, 4, Vector3D(0.0, 20.0, 100.0));
    PhongMaterial       material1(Color::red);

    Sphere              sphere2(10, Vector3D(0.0, 45.0, 100.0));
    PhongMaterial       material2(Color::green);

    Sphere              sphere3(10, Vector3D(35.0, 20.0, 100.0));
    PhongMaterial       material3(Color::blue);

    Plane               plane1(Vector3D(0, 0, 0), Vector3D(0.0, 1.0, 0.0));
    PhongMaterial       material4(Color(0.0, 1.0, 1.0));

    Plane               plane2(Vector3D(-100, 0, 0), Vector3D(1.0, 0.0, 0.0));
    PhongMaterial       material5(Color(1.0, 0.0, 1.0));

    Plane               plane3(Vector3D(0, 0, 500), Vector3D(0.0, 0.0, -1.0));
    PhongMaterial       material6(Color(1.0, 1.0, 0.0));

    sphere1.setMaterial(&material1);
    sphere2.setMaterial(&material2);
    sphere3.setMaterial(&material3);
    plane1.setMaterial(&material4);
    plane2.setMaterial(&material5);
    plane3.setMaterial(&material6);
    
    scene.addObject(&sphere1);
    scene.addObject(&sphere2);
    scene.addObject(&sphere3);
    scene.addObject(&plane1);
    scene.addObject(&plane2);
    scene.addObject(&plane3);

    scene.addLight(&light1);
    scene.addLight(&light2);
    scene.setAmbientLight(&ambientLight);

    // Render scene
    camera.computeFrame();
    camera.renderScene(scene, renderTarget);
    renderTarget.update();
}
Пример #7
0
void init(void)
{
  shader = boost::shared_ptr<shaders::Surface>(new shaders::Surface);

  boost::shared_ptr<shade::shaders::Plastic> specular(new shade::shaders::Plastic(0.4, 0.6));
  boost::shared_ptr<shade::shaders::TangentSpace> coordinate_system(new shade::shaders::TangentSpace);
  boost::shared_ptr<shade::shaders::Texture2D> tex_access(new shade::shaders::Texture2D);
  boost::shared_ptr<shade::GLSLTexture> texture(example::make_texture("examples/heightbump.dds"));
  tex_access->texture_unit.set(texture);
  boost::shared_ptr<shade::shaders::UVCoord> uvcoord(new shade::shaders::UVCoord);
  tex_access->uv = uvcoord;
  specular->color.set_value(shade::vec4<>(1., 0.4, 0.4, 1.));
  specular->coordinate_system = coordinate_system;
  coordinate_system->normal_map = tex_access;
  shader->material = specular;
  {
    shaders::IlluminatedMaterial::LightList::Accessor accessor(specular->lights);

    boost::shared_ptr<shaders::PointLight> light(new shaders::PointLight);
    light->position.set_value(shade::vec3<>(30., 15., 10.));
    light->color.set_value(shade::vec3<>(1., 1., 1.));
    accessor->push_back(light);

    boost::shared_ptr<shaders::PointLight> light2(new shaders::PointLight);
    light2->position.set_value(shade::vec3<>(-15., -3, 0.));
    light2->color.set_value(shade::vec3<>(1., 1., 1.));
    accessor->push_back(light2);
  }

  boost::shared_ptr<Displacement> displacement = boost::shared_ptr<Displacement>(new Displacement);
  shader->geometry = displacement;
  displacement->coordinate_system = coordinate_system.get();
  displacement->texture_unit.set(texture);

  state = shade::create_GLSL_wrapper();
  state->init();
  state->set_geometry_paramters(GL_TRIANGLES, GL_TRIANGLE_STRIP, 64);
  program = boost::shared_ptr<shade::Program>(new shade::Program(shader, state));

  if (std::getenv("DISPLACE_WIREFRAME"))
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
Пример #8
0
Raytracer::Raytracer(): texture(0)
{
    prepareTargetBuffer(128,128);

    std::shared_ptr<Clump3d> clump(new Clump3d);

    //
    // Cube
    //

    std::shared_ptr<MeshGeometry3d> geom1(new MeshGeometry3d());
    cube(geom1->getMesh());
    geom1->meshChanged();
    geom1->setColor(GAL::P4d(1.0, 0.0, 0.0, 1.0));

    std::shared_ptr<MeshGeometry3d> geom5(new MeshGeometry3d());
    cube(geom5->getMesh());
    geom5->meshChanged();
    geom5->setColor(GAL::P4d(0.0, 0.7, 1.0, 1.0));

    //
    // Manifold
    //

    std::shared_ptr<MeshGeometry<Vertex3d> > geom3(new MeshGeometry<Vertex3d>());
    manifold(geom3->getMesh());
    geom3->meshChanged();
    geom3->setColor(GAL::P4d(1.0, 1.0, 0.0, 1.0));

    //
    // Sphere
    //

    std::shared_ptr<SphereGeometry3d> geom2(new SphereGeometry3d(0.5));
    geom2->setColor(GAL::P4d(0.0, 1.0, 1.0, 1.0));

    std::shared_ptr<SphereGeometry3d> geom4(new SphereGeometry3d(0.25));
    geom4->setColor(GAL::P4d(1.0, 0.8, 0.0, 1.0));

    clump->addGeometry(geom1);
    clump->addGeometry(geom2);
    clump->addGeometry(geom3);
    clump->addGeometry(geom4);
    clump->addGeometry(geom5);

    geom1->setTranslation(GAL::P3d(-1,-1,0));
    geom2->setTranslation(GAL::P3d(0,1,0));

    geom3->setTranslation(GAL::P3d(1,0.5,0));
    geom3->setLocalTransform(GAL::EulerRotationX(90.0), 0);

    geom4->setTranslation(GAL::P3d(1.2,1,0.8));

    geom5->setTranslation(GAL::P3d(0,1,-3));
    geom5->setLocalTransform(GAL::EulerRotationY(10.0), 0);

    scene.addClump(clump);

    std::shared_ptr<Light3d> light1(new Light3d());
    light1->setPosition(GAL::P3d(1,4,-1));
    light1->setDiffuseColor(GAL::P3d(0.7, 0.7, 0.7));
    light1->setSpecularColor(GAL::P3d(1.0, 1.0, 1.0));
    light1->setShadow(true);
    light1->setSoftShadowWidth(0.05);
    scene.addLight(light1);

    std::shared_ptr<Light3d> light2(new Light3d());
    light2->setPosition(GAL::P3d(-1,4,3));
    light2->setDiffuseColor(GAL::P3d(0.7, 0.7, 0.7));
    light2->setSpecularColor(GAL::P3d(1.0, 1.0, 1.0));
    light2->setShadow(true);
    light2->setSoftShadowWidth(0.05);
    scene.addLight(light2);

    camera.setFrustum(-1, 1, -1, 1, -1, -100);

    camera.setTranslation(GAL::P3d(1,2,3));
    camera.setLocalTransform(GAL::EulerRotationX(30.0) * GAL::EulerRotationY(15.0), 0);
    camera.setFSAA(true);
    camera.setRecursionDepth(3);
}
Пример #9
0
void buildSceneSphere(Camera* &cam, Film* &film,
                      std::vector<Shape*>* &objectsList,
                      std::vector<PointLightSource>* &lightSourceList)
{
    /* **************************** */
    /* Declare and place the camera */
    /* **************************** */
    // By default, this gives an ID transform
    //  which means that the camera is located at (0, 0, 0)
    //  and looking at the "+z" direction
    Matrix4x4 cameraToWorld;
    double fovDegrees = 60;
    double fovRadians = Utils::degreesToRadians(fovDegrees);
    cam = new PerspectiveCamera(cameraToWorld, fovRadians, *film);

    /* ************************** */
    /* DEFINE YOUR MATERIALS HERE */
    /* ************************** */
    // (...)
    //  EXAMPLE:  Material *green_50 = new Phong (Vector3D(0.2, 0.7, 0.3), Vector3D(0.2, 0.6, 0.2), 50);

	Material *green_50 = new Phong(Vector3D(0.2, 0.7, 0.3), Vector3D(0.2, 0.6, 0.2), 50);
	Material *red_50 = new Phong(Vector3D(0.7, 0.2, 0.3), Vector3D(0.6, 0.2, 0.2), 50);
	Material *blue_50 = new Phong(Vector3D(0.3, 0.2, 0.7), Vector3D(0.2, 0.2, 0.6), 50);

    /* ******* */
    /* Objects */
    /* ******* */
    // Create a heterogeneous list of objects of type shape
    // (some might be triangles, other spheres, plans, etc)
    objectsList = new std::vector<Shape*>;

    // Define and place a sphere
    Matrix4x4 sphereTransform1;
    sphereTransform1 = sphereTransform1.translate(Vector3D(-1.0, -0.5, 2*std::sqrt(2.0)));
    Shape *s1 = new Sphere (0.25, sphereTransform1, green_50);

    // Define and place a sphere
    Matrix4x4 sphereTransform2;
    sphereTransform2 = sphereTransform2.translate(Vector3D(1.0, 0.0, 6));
    Shape *s2 = new Sphere (1, sphereTransform2, red_50);

    // Define and place a sphere
    Matrix4x4 sphereTransform3;
    sphereTransform3 = sphereTransform3.translate(Vector3D(0.3, -0.75, 3.5));
    Shape *s3 = new Sphere (0.25, sphereTransform3, blue_50);

    // Store the objects in the object list
    objectsList->push_back(s1);
    objectsList->push_back(s2);
    objectsList->push_back(s3);


    /* ****** */
    /* Lights */
    /* ****** */
    //
    // ADD YOUR LIGHT SOURCES HERE
	PointLightSource light1(Vector3D(5, 0, 0), Vector3D(50, 50, 50));
	PointLightSource light2 (Vector3D(0, 5, 0), Vector3D(50, 50, 50));
	//PointLightSource *light3 = new PointLightSource(Vector3D(0, 0, 20), Vector3D(0, 0, 20));
    
    // DO NOT FORGET TO STORE THE LIGHT SOURCES IN THE "lightSourceList"
	lightSourceList->push_back(light1);
	lightSourceList->push_back(light2);
    
}
Пример #10
0
int main(int argc, char** argv)
{	
	ObjectProperties *redSphereProperties = new ObjectProperties();
	redSphereProperties->setColour({ MAX_COLOUR, MIN_COLOUR, MIN_COLOUR });
	redSphereProperties->setSpecularColor({ 0.0f, 0.0f, 0.0f });
	redSphereProperties->setPhongExponent(10000);
	Sphere *redSphere = new Sphere(Vec3(-6, 0, 5), 3, redSphereProperties);

	ObjectProperties *greenSphereProperties = new ObjectProperties();
	greenSphereProperties->setColour({ MAX_COLOUR, 0.84f, MIN_COLOUR });
	greenSphereProperties->setSpecularColor({ 1.0f, 0.84f, 0.2f });
	greenSphereProperties->setPhongExponent(10000);
	Sphere *greenSphere = new Sphere(Vec3(0, 3, 14), 6, greenSphereProperties);

	ObjectProperties *blueSphereProperties = new ObjectProperties();
	blueSphereProperties->setColour({ MIN_COLOUR, MIN_COLOUR, MAX_COLOUR });
	blueSphereProperties->setSpecularColor({ 0.0f, 0.0f, 0.0f });
	blueSphereProperties->setPhongExponent(10000);
	Sphere *blueSphere = new Sphere(Vec3(4, -2, 7), 1, blueSphereProperties);

	ObjectProperties *whiteSphereProperties = new ObjectProperties();
	whiteSphereProperties->setColour({ 0.3f, 0.3f, 0.3f });
	whiteSphereProperties->setSpecularColor({ MAX_COLOUR, MAX_COLOUR, MAX_COLOUR });
//	whiteSphereProperties->setSpecularColor({ MIN_COLOUR, MIN_COLOUR, MIN_COLOUR });
	whiteSphereProperties->setPhongExponent(10000);

	ObjectProperties *darkSphereProperties = new ObjectProperties();
	darkSphereProperties->setColour({ 0.3f, 0.3f, 0.3f });
	darkSphereProperties->setSpecularColor({ MIN_COLOUR, MIN_COLOUR, MIN_COLOUR });
	darkSphereProperties->setPhongExponent(10000);

	Dimension xLeft = -CAMERA_WIDTH / 2;
	Dimension xRight = CAMERA_WIDTH / 2;
	Dimension yBottom = -3;
	Dimension yTop = CAMERA_HEIGHT - 3;
	Dimension zFront = 1;
	Dimension zBack = 50;

	Quad *floor = new Quad({ xLeft, yBottom, zFront }, { xRight, yBottom, zFront }, { xRight, yBottom, zBack }, { xLeft, yBottom, zBack }, whiteSphereProperties);
	Quad *leftWall = new Quad({ xLeft, yBottom, zFront }, { xLeft, yBottom, zBack }, { xLeft, yTop, zBack }, { xLeft, yTop, zFront }, whiteSphereProperties);
	Quad *rightWall = new Quad({ xRight, yBottom, zFront }, { xRight, yTop, zFront }, { xRight, yTop, zBack }, { xRight, yBottom, zBack }, whiteSphereProperties);
	Quad *backWall = new Quad({ xLeft, yBottom, zBack }, { xRight, yBottom, zBack }, { xRight, yTop, zBack }, { xLeft, yTop, zBack }, whiteSphereProperties);
	Quad *ceiling = new Quad({ xLeft, yTop, zFront }, { xLeft, yTop, zBack }, { xRight, yTop, zBack }, { xRight, yTop, zFront }, whiteSphereProperties);
	

	PointLight light(Vec3(-5, 8, 4), { 0.6f, 0.6f, 0.6f });
	PointLight light2(Vec3(0, 15, 4), { 0.4f, 0.4f, 0.4f });
	PointLight light3(Vec3(14, 13, 2), { 0.5f, 0.5f, 0.5f });

	Scene scene;
	scene.addObject(redSphere);
	scene.addObject(greenSphere);
	scene.addObject(blueSphere);
	scene.addObject(floor);
//	scene.addObject(leftWall);
//	scene.addObject(rightWall);
//	scene.addObject(backWall);
//	scene.addObject(ceiling);
	scene.addPointLight(&light);
	scene.addPointLight(&light2);
//	scene.addPointLight(&light3);

	
	std::clock_t start = clock();
	raytracer.traceScene(scene, p_camera, image);
	std::clock_t finish = clock();

	double duration = (finish - start) / (double)CLOCKS_PER_SEC;
	std::cout << "Time taken to raytrace scene: " << duration << " seconds." << std::endl;
	
	// Initialize glut
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glEnable(GL_DEPTH_TEST);
	glClearColor(0.0, 0.0, 0.0, 1.0);

	// Set up display window
	glutInitWindowSize(WIDTH, HEIGHT);
	glutInitWindowPosition(50, 50);
	glutCreateWindow("Display");
	glutDisplayFunc(display);

	glutMainLoop();

	return 0;
}