Beispiel #1
0
void RayTracer::createSceneFromBook(HitableList& list)
{
	Camera& camera = m_cameraSystem.getCurrentCamera();

	camera.setPosition(vec3(16.857f, 2.0f, 6.474f));
	camera.setYaw(Math::toRadians(247.8f));
	camera.setPitch(Math::toRadians(-4.762f));
	camera.setAperture(0.1f);
	camera.setFocusDistance(17.29f);

	list.add( new Sphere(vec3(0,-1000,0), 1000, new Lambertian(vec3(0.5, 0.5, 0.5))) );

	for (int a = -11; a < 11; a++)
	{
		for (int b = -11; b < 11; b++)
		{
			float choose_mat = getRandom();
			vec3 center(a + 0.9f * getRandom(), 0.2f, b + 0.9f * getRandom());
			if ((center-vec3(4,0.2,0)).length() > 0.9f)
			{ 
				if (choose_mat < 0.8f)
				{
					// diffuse
					list.add( new Sphere(center, 0.2f, new Lambertian(vec3( getRandom()*getRandom(), getRandom()*getRandom(), getRandom()*getRandom()))));
				}
				else if (choose_mat < 0.95f)
				{
					// metal
					list.add( new Sphere(center, 0.2f,
							new Metal(vec3(0.5f*(1.0f + getRandom()), 0.5f*(1.0f + getRandom()), 0.5f*(1.0f + getRandom())), /*roughness*/ 0.5f*getRandom())));
				}
				else
				{
					// glass
					list.add( new Sphere(center, 0.2f, new Dielectric(vec3(0.8f, 0.5f, 0.3f), /*refractive_index*/1.5f)) );
				}
			}
		}
	}

	list.add( new Sphere(vec3(0, 1, 0), 1.0, new Dielectric(vec3(0.8f, 0.5f, 0.3f), /*refractive_index*/1.5f)) );
	list.add( new Sphere(vec3(-4, 1, 0), 1.0, new Lambertian(vec3(0.0, 0.2, 0.9))) );
	list.add( new Sphere(vec3(4, 1, 0), 1.0, new Metal(vec3(0.7, 0.6, 0.5), 0.0)) );

	m_tree.init(list.list(), 0, 0);
}
Beispiel #2
0
int main(int argc, char* argv[])
{
    ::glfwSetErrorCallback(errorCallback);

    auto result = ::glfwInit();
    if (!result) {
        assert(false);
        return 1;
    }

    ::glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
    ::glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);

    auto window = ::glfwCreateWindow(
        WIDTH,
        HEIGHT,
        TITLE,
        NULL, NULL);

    if (!window) {
        ::glfwTerminate();
        assert(false);
        return 1;
    }

#if 0
    ::glfwSetWindowCloseCallback(
        window,
        closeCallback);

    ::glfwSetKeyCallback(
        window,
        keyCallback);

    ::glfwSetMouseButtonCallback(
        window,
        mouseCallback);

    ::glfwSetCursorPosCallback(
        window,
        motionCallback);

    ::glfwSetScrollCallback(
        window,
        wheelCallback);
#endif

    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);

    SetCurrentDirectoryFromExe();

    // TODO
    Rand::Init(0);

#ifdef ENABLE_RANDOM_SCENE
    HitableList* world = new HitableList();
    random_scene(world);

    vec3 lookfrom(13, 2, 3);
    vec3 lookat(0, 0, 0);
#else
    hitable *list[5];
    float R = cos(_MATH_PI / 4);
    list[0] = new sphere(vec3(0, 0, -1), 0.5, new lambertian(vec3(0.1, 0.2, 0.5)));
    list[1] = new sphere(vec3(0, -100.5, -1), 100, new lambertian(vec3(0.8, 0.8, 0.0)));
    list[2] = new sphere(vec3(1, 0, -1), 0.5, new metal(vec3(0.8, 0.6, 0.2), 1.0));
    list[3] = new sphere(vec3(-1, 0, -1), 0.5, new dielectric(1.5));
    //list[4] = new sphere(vec3(-1, 0, -1), -0.45, new dielectric(1.5));
    HitableList* world = new HitableList();

    world->add(list[0]);
    world->add(list[1]);
    world->add(list[2]);
    world->add(list[3]);

    vec3 lookfrom(0, 0, 1);
    vec3 lookat(0, 0, -1);
#endif

    float dist_to_focus = 10.0;
    float aperture = 0.1;

    camera cam(
        lookfrom, 
        lookat, 
        vec3(0, 1, 0), 
        60,                     // vfov
        float(nx) / float(ny),  // aspect
        aperture, 
        dist_to_focus);

    Init();

    while (!glfwWindowShouldClose(window)) {
        display(world, cam);

        ::glfwSwapBuffers(window);
        ::glfwPollEvents();
    }

    ::glfwDestroyWindow(window);
    ::glfwTerminate();

    return 1;
}
Beispiel #3
0
void RayTracer::createSceneOne(HitableList& world, bool loadBunny)
{
	Camera& camera = m_cameraSystem.getCurrentCamera();

	camera.setFieldOfViewDeg(44.6f);

	//camera.setPosition(vec3(0.698890f, 1.275992f, 6.693169f));
	//camera.setYaw(Math::toRadians(188.0f));
	//camera.setPitch(Math::toRadians(-7.744f));
	//camera.setAperture(0.3f);
	//camera.setFocusDistance(7.6f);

	camera.setPosition(vec3(-0.16f, 2.9664f, 14.8691f));
	camera.setYaw(Math::toRadians(178.560333f));
	camera.setPitch(Math::toRadians(-10.8084f));
	camera.setAperture(0.07f);
	camera.setFocusDistance(14.763986f);

	// A big light
	world.add(
		new Sphere(vec3(0.0f, 6.0f, -1.0f), 2.0f,
		new Light(vec3(4.0f, 4.0f, 4.0f)))
		);

	// A small light
	world.add(
		new Sphere(vec3(0.85, 0.3, -0.15f), 0.1f,
		new Light(vec3(16.0f, 16.0f, 16.0f)))
		);

	// A ball
	world.add(
		new Sphere(vec3(0, 0, -1), 0.5f,
		new Lambertian(vec3(0.8f, 0.3f, 0.3f)))
		);
	// The planet
	world.add(
		new Sphere(vec3(0, -100.5f, -1), 100.0f,
		new Lambertian(vec3(0.0f, 0.7f, 0.8f)))
		);
	
	// Metal balls
	world.add(
		new Sphere(vec3(1, 0, -1), 0.5f,
		new Metal(vec3(0.8f, 0.6f, 0.2f), /*roughness*/0.0f))
		);
	world.add(
		new Sphere(vec3(-0.5f, 0.65f, -1), 0.4f,
		new Metal(vec3(0.8f, 0.4f, 0.8f), /*roughness*/0.3f))
		);
	// Dielectric
	world.add(
		new Sphere(vec3(-1, 0, -1), 0.5f,
		new Dielectric(vec3(0.8f, 0.5f, 0.3f), /*refractive_index*/1.5f))
		);
	world.add(
		new Sphere(vec3(-3.15f, 0.1f, -5), 0.6f,
		new Lambertian(vec3(0.05f, 0.2f, 0.8f)))
		);

	///////////////////

	auto bunny = new Mesh(0);
	if (loadBunny)
		bunny->loadModel("./data/models/bunny.obj");
	else bunny->generateBox();

	world.add(bunny);

	m_tree.init(world.list(), 0, 0);
}