void View::render ( void ) { ::glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); ::glLoadIdentity(); // model view. const Camera& camera = this->_model.getCamera(); Eigen::Vector3f eye = camera.getEye(); Eigen::Vector3f center = camera.getCenter(); Eigen::Vector3f up = camera.getUpVector(); ::gluLookAt ( eye.x(), eye.y(), eye.z(), center.x(), center.y(), center.z(), up.x(), up.y(), up.z() ); //light Light light = this->_model.getLight(); this->setLight ( light ); //draw mesh RenderingMode mode = this->_model.getPreference().getRenderingMode() ; if ( mode == WIRE ) { ::glDisable ( GL_LIGHTING ); ::glPolygonMode ( GL_FRONT_AND_BACK, GL_LINE ); const Color3f fg = this->_model.getPreference().getWireColor(); ::glColor3f ( fg.x(), fg.y(), fg.z() ); } else if ( mode == SURFACE ) { ::glEnable ( GL_LIGHTING ); const Color3f fg = this->_model.getPreference().getSurfaceColor(); ::glPolygonMode ( GL_FRONT_AND_BACK, GL_FILL ); GLfloat mat_ambient[4] = {fg.x(), fg.y(), fg.z(), 1.0}; GLfloat mat_diffuse[4] = {0.8,0.8, 0.8, 1.0}; GLfloat mat_specular[4] = {0.2, 0.2, 0.2, 1.0}; GLfloat mat_shininess[1] = {100.0f}; ::glMaterialfv ( GL_FRONT, GL_AMBIENT, mat_ambient ); ::glMaterialfv ( GL_FRONT, GL_DIFFUSE, mat_diffuse ); ::glMaterialfv ( GL_FRONT, GL_SPECULAR, mat_specular ); ::glMaterialfv ( GL_FRONT, GL_SHININESS,mat_shininess ); GLfloat mat2_ambient[4] = {1-fg.x(), 1-fg.y(), 1-fg.z(), 1.0}; GLfloat mat2_diffuse[4] = {0.8,0.8, 0.8, 1.0}; GLfloat mat2_specular[4] = {0.2, 0.2, 0.2, 1.0}; GLfloat mat2_shininess[1] = {100.0f}; ::glMaterialfv ( GL_BACK, GL_AMBIENT, mat2_ambient ); ::glMaterialfv ( GL_BACK, GL_DIFFUSE, mat2_diffuse ); ::glMaterialfv ( GL_BACK, GL_SPECULAR, mat2_specular ); ::glMaterialfv ( GL_BACK, GL_SHININESS,mat2_shininess ); } this->render_mesh(); return; }
void View::setLight ( const Light& light ) { Color3f amb = light.getAmbient(); Color3f dif = light.getDiffuse(); Color3f spe = light.getSpecular(); Eigen::Vector3f eye = light.getPosition(); GLfloat light_ambient[4] = {amb.x(), amb.y(), amb.z(), 1.0f}; GLfloat light_diffuse[4] = {dif.x(), dif.y(), dif.z(), 1.0f}; GLfloat light_specular[4] = {spe.x(), spe.y(), spe.z(), 1.0f}; GLfloat light_position[4] = {eye.x(), eye.y(), eye.z(), 1.0f}; ::glLightfv ( GL_LIGHT0, GL_AMBIENT, light_ambient ); ::glLightfv ( GL_LIGHT0, GL_DIFFUSE, light_diffuse ); ::glLightfv ( GL_LIGHT0, GL_SPECULAR, light_specular ); ::glLightfv ( GL_LIGHT0, GL_POSITION, light_position ); return; }
void View::init ( void ) { ::glEnable( GL_CULL_FACE ); ::glEnable ( GL_DEPTH_TEST ); ::glEnable ( GL_LIGHT0 ); ::glShadeModel ( GL_FLAT ); const Color3f bg = this->_model.getPreference().getBackgroundColor(); ::glClearColor ( bg.x(), bg.y(), bg.z(), 1 ); return; }
Color3f Li(const Scene *scene, Sampler *sampler, const Ray3f &r) const { /* Find the surface that is visible in the requested direction */ Intersection its; Ray3f ray(r); if (!scene->rayIntersect(ray, its)) return Color3f(0.0f); Color3f radiance(0.0f); bool specularBounce = false; Color3f pathThroughput(1.0f); for ( int bounces = 0; ; ++bounces ) { const Luminaire* luminaire = its.mesh->getLuminaire(); if ((bounces == 0 || specularBounce) && luminaire != NULL) { Vector3f wo = (-ray.d).normalized(); Color3f emission = luminaire->le(its.p, its.shFrame.n, wo); radiance += pathThroughput*emission; } const Texture* texture = its.mesh->getTexture(); Color3f texel(1.0f); if ( texture ) { texel = texture->lookUp(its.uv.x(), its.uv.y()); } const BSDF* bsdf = its.mesh->getBSDF(); // sample illumination from lights, add to path contribution if (!bsdf->isSpecular()){ radiance += pathThroughput*UniformSampleAllLights(scene, ray, its, sampler, m_samplePolicy)*texel; } // sample bsdf to get new path direction BSDFQueryRecord bRec(its.toLocal((-ray.d)).normalized()); Color3f f = bsdf->sample(bRec, sampler->next2D() ); if (f.isZero() ) { // farther path no contribution break; } specularBounce = bsdf->isSpecular(); Vector3f d = its.toWorld(bRec.wo); f *= texel; pathThroughput *= f; ray = Ray3f(its.p, d ); // possibly termination if (bounces > kSampleDepth) { #if 0 float continueProbability = std::min( 0.5f, pathThroughput.y() ); if ( sampler->next1D() > continueProbability ) { break; } #else float continueProbability = std::max(f.x(), std::max(f.y(), f.z())); if ( sampler->next1D() > continueProbability ) { break; } #endif pathThroughput /= continueProbability; } if (bounces == m_maxDepth) { break; } // find next vertex of path if ( !scene->rayIntersect(ray, its) ) { break; } } return radiance; }