State::stateResult_t PhotonRenderer::doEnableState(FrameContext & context, Node * node, const RenderParam & rp){ #ifdef MINSG_THESISSTANISLAW_GATHER_STATISTICS Rendering::RenderingContext::finish(); _timer.reset(); #endif // MINSG_THESISSTANISLAW_GATHER_STATISTICS if(!_photonSampler){ WARN("No PhotonSampler present in PhotonRenderer!"); return State::stateResult_t::STATE_SKIPPED; } if(!_approxScene){ WARN("No approximated Scene present in PhotonRenderer!"); return State::stateResult_t::STATE_SKIPPED; } auto& rc = context.getRenderingContext(); rc.setImmediateMode(true); rc.applyChanges(); if(_fboChanged){ if(!initializeFBO(rc)){ WARN("Could not initialize FBO for PhotonRenderer!"); return State::stateResult_t::STATE_SKIPPED; } _fboChanged = false; } RenderParam newRp; rc.pushAndSetFBO(_fbo.get()); rc.clearDepth(1.0f); rc.applyChanges(); for(int32_t i = 0; i < _photonSampler->getPhotonNumber(); i++){ _fbo->setDrawBuffers(2); rc.pushAndSetShader(_indirectLightShader.get()); _lightPatchRenderer->bindTBO(rc, true, false); _photonSampler->bindPhotonBuffer(1); context.pushAndSetCamera(_photonCamera.get()); _indirectLightShader->setUniform(rc, Rendering::Uniform("photonID", i)); rc.clearDepth(1.0f); rc.clearColor(Util::Color4f(0.f, 0.f, 0.f, 0.f)); _approxScene->display(context, newRp); context.popCamera(); _photonSampler->unbindPhotonBuffer(1); _lightPatchRenderer->unbindTBO(rc); rc.popShader(); // Accumulate all pixel values in one photon _fbo->setDrawBuffers(0); rc.pushAndSetShader(_accumulationShader.get()); _accumulationShader->setUniform(rc, Rendering::Uniform("photonID", i)); _accumulationShader->setUniform(rc, Rendering::Uniform("samplingWidth", static_cast<int>(_samplingWidth))); _accumulationShader->setUniform(rc, Rendering::Uniform("samplingHeight", static_cast<int>(_samplingHeight))); _photonSampler->bindPhotonBuffer(1); rc.clearDepth(1.0f); Rendering::TextureUtils::drawTextureToScreen(rc, Geometry::Rect_i(0, 0, _samplingWidth, _samplingHeight), *_indirectLightTexture.get(), Geometry::Rect_f(0.0f, 0.0f, 1.0f, 1.0f)); _photonSampler->unbindPhotonBuffer(1); rc.popShader(); } rc.popFBO(); rc.setImmediateMode(false); // rc.pushAndSetShader(nullptr); // Rendering::TextureUtils::drawTextureToScreen(rc, Geometry::Rect_i(0, 0, _samplingWidth, _samplingHeight), *(_indirectLightTexture.get()), Geometry::Rect_f(0.0f, 0.0f, 1.0f, 1.0f)); // rc.popShader(); // return State::stateResult_t::STATE_SKIP_RENDERING; #ifdef MINSG_THESISSTANISLAW_GATHER_STATISTICS Rendering::RenderingContext::finish(); _timer.stop(); auto& stats = context.getStatistics(); Statistics::instance(stats).addPhotonRendererTime(stats, _timer.getMilliseconds()); #endif // MINSG_THESISSTANISLAW_GATHER_STATISTICS return State::stateResult_t::STATE_OK; }
void OpenGLRenderer::initialize() { std::srand(std::time(0)); glEnable(GL_DEPTH_TEST); //glEnable(GL_CULL_FACE); //glEnable(GL_TEXTURE_2D); // Einem Befehl wurde ein falscher Wert übergeben --> wurde in OpenGL 3.x entfernt (deprecated in 2.x) //glEnable(GL_BLEND); //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); checkForErrors(); initializeVAOs(); initializeMeshShader(); initializeFinalShader(); initializeAddShader(); initializeStarWarsShader(); // Textur-Handler erzeugen glGenTextures(1, &texture_ID); sizeChanged(523, 482); // sonst sind viewWidth & viewHeight noch uninitialisiert, was zu Fehlern beim Rendern mit den FBOs und bei configureFBOTextures() führt // FBOs zugehörige Texturen für Transparenz & PostScreen-Effekte initialisieren initializeFBO(fbo1, colorTexture1, depthTexture1); initializeFBO(fbo2, colorTexture2, depthTexture2); initializeFBO(fbo3, colorTexture3, depthTexture3); /*// Texturhandles erstellen glGenTextures(1, &colorTexture1); glGenTextures(1, &depthTexture1); glGenTextures(1, &colorTexture2); glGenTextures(1, &depthTexture2); glGenTextures(1, &colorTexture3); glGenTextures(1, &depthTexture3); checkForErrors(); // Konfiguriert leere Color- und Depth-Texturen in Bildschirmgröße, in die am Ende die leeren Dreiecke aus dem VBO_fbo gerendert werden können configureFBOTextures(colorTexture1, depthTexture1); configureFBOTextures(colorTexture2, depthTexture2); configureFBOTextures(colorTexture3, depthTexture3); checkForErrors(); // Erzeuge neue FBOs glGenFramebuffers(1, &fbo1); glBindFramebuffer(GL_FRAMEBUFFER, fbo1); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, colorTexture1, 0); // Verknüpfe Color-Textur 1 mit dem FBO glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthTexture1, 0); // Verknüpfe Depth-Textur 1 mit dem FBO glGenFramebuffers(1, &fbo2); glBindFramebuffer(GL_FRAMEBUFFER, fbo2); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, colorTexture2, 0); // Verknüpfe Color-Textur 2 mit dem FBO glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthTexture2, 0); // Verknüpfe Depth-Textur 2 mit dem FBO glGenFramebuffers(1, &fbo3); glBindFramebuffer(GL_FRAMEBUFFER, fbo3); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, colorTexture3, 0); // Verknüpfe Color-Textur 3 mit dem FBO glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthTexture3, 0); // Verknüpfe Depth-Textur 3 mit dem FBO if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { qDebug ( ) << "Error, FBO not complete!"; } // gebundene Framebuffer wieder loslösen glBindFramebuffer(GL_FRAMEBUFFER, 0); checkForErrors();*/ }