PhongMaterial Converter::getPhongMaterial(FbxSurfaceMaterial *material) { auto ambient = ((FbxSurfacePhong *)material)->Ambient; XMFLOAT3 amb = XMFLOAT3(ambient.Get()[0], ambient.Get()[1], ambient.Get()[2]); auto diffuse = ((FbxSurfacePhong *)material)->Diffuse; XMFLOAT3 dif = XMFLOAT3(diffuse.Get()[0], diffuse.Get()[1], diffuse.Get()[2]); auto specular = ((FbxSurfacePhong *)material)->Specular; XMFLOAT3 spec = XMFLOAT3(specular.Get()[0], specular.Get()[1], specular.Get()[2]); auto emissive = ((FbxSurfacePhong *)material)->Emissive; XMFLOAT3 emi = XMFLOAT3(emissive.Get()[0], emissive.Get()[1], emissive.Get()[2]); auto alpha = 1.0 - ((FbxSurfacePhong *)material)->TransparencyFactor; auto shininess = ((FbxSurfacePhong *)material)->Shininess; auto reflectivity = ((FbxSurfacePhong *)material)->ReflectionFactor; return PhongMaterial(amb, dif, spec, emi, alpha, shininess, reflectivity); }
void init() { SDL_GL_application::init(); perspective_.setPerspectiveTransform(50.0, getWindowWidth(), getWindowHeight(), 1.0, 60.0); camera_.initCamera(Vec3(0, 1.8, -6.0), Vec3(1, 0, 0), Vec3(0, 1, 0), Vec3(0, 0, 1)); dLight_.ambientIntensity_ = 0.0; dLight_.diffuseIntensity_ = 0.0; dLight_.color_ = Vec3(1.0, 1.0, 1.0); dLight_.dir_ = Vec3(0.0, 0.0, 1.0); pLight_.color_ = Vec3(0.8, 0.0, 0.0); pLight_.position_ = Vec3(1.0,1.0,1.0); pLight_.ambientIntensity_ = 0.0; pLight_.diffuseIntensity_ = 0.8; pLight_.att_.constant_ = 0.2; pLight_.att_.linear_ = 0.2; pLight_.att_.exp_ = 0.2; //pLight_.ambientIntensity_ = 0.2; //pLight_.diffuseIntensity_ = 0.8; //pLight_.att_.constant_ = 1.0; //pLight_.att_.linear_ = 0.0; //pLight_.att_.exp_ = 0.0; glEnable(GL_TEXTURE_2D); room_.loadMesh("../../meshes/room.obj"); room_.buildFakeVertexNormals(); textures_.reserve(10); Texture r; r.createTextureFromImage("../../textures/wall_floor.png"); textures_.push_back(std::move(r)); Texture *t = &textures_[0]; roomMat_ = PhongMaterial(0.0f, 200.0f, 1.0f, t); room_.setMaterial(&roomMat_); //renderManager.setupShaders(shaderList,shaderConfigurations,...); shader_.initShader(*camera_.getPosPointer(), perspective_.getPerspectiveTransform(), camera_.getCameraTranslationTransform(), camera_.getCameraCoordinateTransform(), roomMat_); shader_.setDirectionLight(&dLight_); shader_.setPointLight(&pLight_); room_.shader_ = &shader_; room_.transform_.translation_ = i3d::Vec4(0, 0, 0, 1); room_.transform_.setRotationEuler(i3d::Vec3(0.0, 0.0, 0.0)); room_.initRender(); world_.loadMesh("../../meshes/world.obj"); world_.buildSmoothNormals(); Texture e; e.createTextureFromImage("../../textures/earth1.png"); textures_.push_back(std::move(e)); t = &textures_[1]; worldMat_ = PhongMaterial(15.0f, 30.0f, 1.0f, t); world_.setMaterial(&worldMat_); world_.transform_.translation_ = i3d::Vec4(0.9, -1.0, 0.0, 1); world_.transform_.setRotationEuler(i3d::Vec3(0.0, 0.0, 0.0)); world_.initRender(); }
void init() { SDL_GL_application::init(); perspective_.setPerspectiveTransform(70.f, static_cast<float>(getWindowWidth()), static_cast<float>(getWindowHeight()), 1.f, 60.f); camera_.initCamera(Vec3(0.f, 1.8f, -6.0f), Vec3(1.f, 0.f, 0.f), Vec3(0.f, 1.f, 0.f), Vec3(0.f, 0.f, 1.f)); dLight_.ambientIntensity_ = 0.0f; dLight_.diffuseIntensity_ = 0.8f; dLight_.color_ = Vec3(0.0f, 0.0f, 0.0f); //dLight_.color_ = Vec3(0.0f, 0.0f, 0.0f); dLight_.dir_ = Vec3(0.25f, -0.5f, 1.0f); dLight_.dir_ = Vec3(1.0f, -0.75f, 1.0f); dLight_.dir_ = Vec3(-1.0f, 0.0f, 0.0f); pLight_.color_ = Vec3(0.8f, 0.8f, 0.8f); //pLight_.color_ = Vec3(0.0f, 0.0f, 0.0f); pLight_.position_ = Vec3(0.0f, 2.5f, 1.0f); pLight_.ambientIntensity_ = 3.0f; pLight_.diffuseIntensity_ = 5.0f; pLight_.att_.constant_ = 1.0f; pLight_.att_.linear_ = 1.0f; pLight_.att_.exp_ = 0.2f; sLight_.color_ = Vec3(0.95f, 0.7f, 0.4f); sLight_.color_ = Vec3(0.0f, 0.0f, 0.0f); sLight_.position_ = Vec3(0.0f, 1.0f, -2.0f); sLight_.dir_ = Vec3(0.f, 0.0f, 1.0f); sLight_.ambientIntensity_ = 0.0f; sLight_.diffuseIntensity_ = 0.5f; sLight_.cutoff_ = 0.925f; sLight_.att_.constant_ = 0.09f; sLight_.att_.linear_ = 0.09f; sLight_.att_.exp_ = 0.1f; cameraShadow_.setLookAt(Vec3(0.f, 1.0f, -6.0f), Vec3(0.f, 0.f, 1.f), Vec3(0.f, 1.f, 0.f)); renderTex_.createDepthTexture(getWindowWidth(), getWindowHeight()); glGenRenderbuffers(1, &renderBuffer); glBindRenderbuffer(GL_RENDERBUFFER, renderBuffer); // the renderbuffer needs also a depth component glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, getWindowWidth(), getWindowHeight()); // get a framebuffer object glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, renderTex_.id_, 0); glEnable(GL_DEPTH_TEST); room_.loadMesh("../../meshes/big_room.obj"); room_.buildFakeVertexNormals(); textures_.reserve(10); Texture r; r.createTextureFromImage("../../textures/wall_floor2.png"); textures_.push_back(std::move(r)); roomMat_ = PhongMaterial(0.0f, 100.0f, 1.0f, &textures_.back()); room_.setMaterial(&roomMat_); shaderShadow_.initShader(*camera_.getPosPointer(), perspective_.getPerspectiveTransform(), camera_.getCameraTranslationTransform(), camera_.getCameraCoordinateTransform(), roomMat_); shaderShadow_.setDirectionLight(&dLight_); shaderShadow_.setPointLight(&pLight_); shaderShadow_.setSpotLight(&sLight_); //renderManager.setupShaders(shaderList,shaderConfigurations,...); shader_.initShader(*camera_.getPosPointer(), perspective_.getPerspectiveTransform(), camera_.getCameraTranslationTransform(), camera_.getCameraCoordinateTransform(), roomMat_); shader_.setDirectionLight(&dLight_); shader_.setPointLight(&pLight_); room_.shader_ = &shader_; shaderPhong_.initShader(*camera_.getPosPointer(), perspective_.getPerspectiveTransform(), camera_.getCameraTranslationTransform(), camera_.getCameraCoordinateTransform(), roomMat_); shaderPhong_.setDirectionLight(&dLight_); shaderPhong_.setPointLight(&pLight_); shaderPhong_.setSpotLight(&sLight_); room_.shader_ = &shaderPhong_; room_.transform_.translation_ = i3d::Vec4(0.f, 0.f, 0.f, 1.f); room_.transform_.setRotationEuler(i3d::Vec3(0.0f, 0.0f, 0.0f)); room_.initRender(); //////////////////////////////////////////////////////////////////////////////////////////////////////// quad_.loadMesh("../../meshes/ground.obj"); quad_.buildSmoothNormals(); Texture e; //e.createTextureFromImage("../../textures/earth1.png"); e.createTextureFromImage("../../textures/ground.png"); textures_.push_back(std::move(e)); planeMat_ = PhongMaterial(15.0f, 30.0f, 1.0f, &textures_.back()); quad_.setMaterial(&planeMat_); quad_.transform_.translation_ = i3d::Vec4(0.f, 0.0f, 0.f, 1.f); quad_.transform_.setRotationEuler(i3d::Vec3(0.0f, 0.0f, 0.0f)); quad_.initRender(); //////////////////////////////////////////////////////////////////////////////////////////////////////// wall_.loadMesh("../../meshes/wall.obj"); //world_.loadMesh("../../meshes/sphere0.obj"); wall_.buildSmoothNormals(); //world_.buildFakeVertexNormals(); Texture w; w.createTextureFromImage("../../textures/brick.png"); textures_.push_back(std::move(w)); worldMat_ = PhongMaterial(5.0f, 30.0f, 1.0f, &textures_.back()); wall_.setMaterial(&worldMat_); wall_.transform_.translation_ = i3d::Vec4(0.0, 0.0, 0.0, 1); //world_.transform_.translation_ = i3d::Vec4(0.0, 1.0, 0.0, 1); wall_.transform_.setRotationEuler(i3d::Vec3(0.0, 0.0, 0.0)); wall_.initRender(); wall2_.loadMesh("../../meshes/wall_r.obj"); //world_.loadMesh("../../meshes/sphere0.obj"); wall2_.buildSmoothNormals(); //world_.buildFakeVertexNormals(); wall2_.setMaterial(&worldMat_); wall2_.transform_.translation_ = i3d::Vec4(0.0, 0.0, 0.0, 1); //world_.transform_.translation_ = i3d::Vec4(0.0, 1.0, 0.0, 1); wall2_.transform_.setRotationEuler(i3d::Vec3(0.0, 0.0, 0.0)); wall2_.initRender(); }