Image draw(float width, float height) { IntersectRecord record; vector<Shape*> shapes = makeScene(); vector<Lighting*> lights = makeLighting(); Image im(width, height); Camera cam(Vector3(0, 0, 0), Vector3(0, 0, -1), Vector3(0, 1, 0), 0.0, -2.0, 2.0, -2.0, 2.0, 3, width, height); //for each pixel for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { Ray r = cam.getRay(i, j, 0, 0); Color radiance = traceRay(r, shapes, lights, 0.0001f, 100000.0f, 0, 5); im.set(i, j, radiance); } } return im; }
void App::onInit() { GApp::onInit(); createDeveloperHUD(); renderDevice->setSwapBuffersAutomatically(true); window()->setCaption("Pixel Shader Demo"); ArticulatedModel::Specification spec; spec.filename = System::findDataFile("teapot/teapot.obj"); spec.scale = 0.015f; spec.stripMaterials = true; spec.preprocess.append(ArticulatedModel::Instruction(Any::parse("setCFrame(root(), Point3(0, -0.5, 0));"))); model = ArticulatedModel::create(spec); makeLighting(); makeColorList(); makeGui(); // Color 1 is red lambertianColorIndex = 1; // The last color is white glossyColorIndex = colorList.size() - 1; m_debugCamera->setPosition(Vector3(1.0f, 1.0f, 2.5f)); m_debugCamera->setFieldOfView(45 * units::degrees(), FOVDirection::VERTICAL); m_debugCamera->lookAt(Point3::zero()); // Add axes for dragging and turning the model manipulator = ThirdPersonManipulator::create(); addWidget(manipulator); // Turn off the default first-person camera controller and developer UI m_debugController->setEnabled(false); developerWindow->setVisible(false); developerWindow->cameraControlWindow->setVisible(false); showRenderingStats = false; }