void DepthDarkening::process() { privatePort_.activateTarget(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (!interactionMode()) analyzeDepthBuffer(&inport_); // since the blurring is implemented as a separable filter, // two rendering passes are needed // first horizontal pass TextureUnit colorUnit, depthUnit0, depthUnit1; inport_.bindTextures(colorUnit.getEnum(), depthUnit0.getEnum()); inport_.bindDepthTexture(depthUnit1.getEnum()); // initialize shader program_->activate(); setGlobalShaderParameters(program_); program_->setUniform("colorTex_", colorUnit.getUnitNumber()); program_->setUniform("depthTex0_", depthUnit0.getUnitNumber()); program_->setUniform("depthTex1_", depthUnit1.getUnitNumber()); inport_.setTextureParameters(program_, "texParams_"); program_->setUniform("sigma_", sigma_.get()); program_->setUniform("lambda_", lambda_.get()); program_->setUniform("minDepth_", minDepth_.get()); program_->setUniform("maxDepth_", maxDepth_.get()); program_->setUniform("dir_", tgt::vec2(1.0,0.0)); renderQuad(); program_->deactivate(); LGL_ERROR; // second vertical pass outport_.activateTarget(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); inport_.bindColorTexture(colorUnit.getEnum()); privatePort_.bindDepthTexture(depthUnit0.getEnum()); // initialize shader program_->activate(); setGlobalShaderParameters(program_); program_->setUniform("colorTex_", colorUnit.getUnitNumber()); program_->setUniform("depthTex0_", depthUnit0.getUnitNumber()); program_->setUniform("depthTex1_", depthUnit1.getUnitNumber()); inport_.setTextureParameters(program_, "texParams_"); program_->setUniform("sigma_", sigma_.get()); program_->setUniform("lambda_", lambda_.get()); program_->setUniform("minDepth_", minDepth_.get()); program_->setUniform("maxDepth_", maxDepth_.get()); program_->setUniform("dir_", tgt::vec2(0.0,1.0)); renderQuad(); program_->deactivate(); outport_.deactivateTarget(); LGL_ERROR; }
void Gabor::process() { outport_.resize(tgt::ivec2(resolution_.get(), resolution_.get())); // activate and clear output render target outport_.activateTarget(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // activate shader and set uniforms: program_->activate(); setGlobalShaderParameters(program_); program_->setUniform("orientation_", (angle_.get()/360.0f)*2.0f*tgt::PIf); program_->setUniform("wavelength_", wavelength_.get()); program_->setUniform("offset_", offset_.get()); program_->setUniform("sigma_", sigma_.get()); program_->setUniform("aRatio_", aspectRatio_.get()); //program_->setUniform("aspectRatio_", aspectRatio_.get()); // render screen aligned quad: glDepthFunc(GL_ALWAYS); renderQuad(); glDepthFunc(GL_LESS); program_->deactivate(); outport_.deactivateTarget(); LGL_ERROR; }
void TouchEventSimulator::process() { // activate and clear output render target outport_.activateTarget(); outport_.clearTarget(); // bind input rendering to texture units tgt::TextureUnit colorUnit, depthUnit; inport_.bindTextures(colorUnit.getEnum(), depthUnit.getEnum()); // activate shader and set uniforms tgtAssert(program_, "bypass shader not loaded"); program_->activate(); setGlobalShaderParameters(program_); inport_.setTextureParameters(program_, "texParams_"); program_->setUniform("colorTex_", colorUnit.getUnitNumber()); program_->setUniform("depthTex_", depthUnit.getUnitNumber()); // render screen aligned quad renderQuad(); // cleanup program_->deactivate(); outport_.deactivateTarget(); tgt::TextureUnit::setZeroUnit(); // check for OpenGL errors LGL_ERROR; }
void VolumeRaycaster::rescaleRendering(RenderPort& srcPort, RenderPort& destPort) { // activate and clear output render target destPort.activateTarget(); destPort.clearTarget(); // activate shader and set uniforms tgtAssert(rescaleShader_, "bypass shader not loaded"); rescaleShader_->activate(); setGlobalShaderParameters(rescaleShader_, 0, destPort.getSize()); // bind input rendering to texture units tgt::TextureUnit colorUnit, depthUnit; srcPort.bindTextures(colorUnit.getEnum(), depthUnit.getEnum(), GL_LINEAR); srcPort.setTextureParameters(rescaleShader_, "texParams_"); rescaleShader_->setUniform("colorTex_", colorUnit.getUnitNumber()); rescaleShader_->setUniform("depthTex_", depthUnit.getUnitNumber()); // render screen aligned quad renderQuad(); // cleanup rescaleShader_->deactivate(); destPort.deactivateTarget(); TextureUnit::setZeroUnit(); // check for OpenGL errors LGL_ERROR; }
void StereoMeshEntryExitPoints::jitterEntryPoints() { shaderProgramJitter_->activate(); tgt::Camera cam = camera_.get(); setGlobalShaderParameters(shaderProgramJitter_, &cam); // bind texture TextureUnit entryUnit, entryDepthUnit, exitUnit; // bind entry points texture and depth texture (have been rendered to temporary port) tmpPort_.bindColorTexture(entryUnit.getEnum()); shaderProgramJitter_->setUniform("entryPoints_", entryUnit.getUnitNumber()); tmpPort_.bindDepthTexture(entryDepthUnit.getEnum()); shaderProgramJitter_->setUniform("entryPointsDepth_", entryDepthUnit.getUnitNumber()); tmpPort_.setTextureParameters(shaderProgramJitter_, "entryParameters_"); // bind exit points texture exitPort_.bindColorTexture(exitUnit.getEnum()); shaderProgramJitter_->setUniform("exitPoints_", exitUnit.getUnitNumber()); exitPort_.setTextureParameters(shaderProgramJitter_, "exitParameters_"); shaderProgramJitter_->setUniform("stepLength_", jitterStepLength_.get()); entryPort_.activateTarget("jitteredEntryParams"); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // render screen aligned quad renderQuad(); shaderProgramJitter_->deactivate(); }
void RenderLoopInitiator::process() { outport_.activateTarget(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // activate shader shader_->activate(); TextureUnit colorUnit, depthUnit; if (loopInport_.getLoopIteration() == 0) { // first iteration => copy initial input image to outport inport_.bindTextures(colorUnit.getEnum(), depthUnit.getEnum()); } else { // loop iteration => copy loop input image to outport loopInport_.bindTextures(colorUnit.getEnum(), depthUnit.getEnum()); } LGL_ERROR; // set common uniforms setGlobalShaderParameters(shader_); // pass texture parameters to the shader shader_->setUniform("colorTex_", colorUnit.getUnitNumber()); shader_->setUniform("depthTex_", depthUnit.getUnitNumber()); inport_.setTextureParameters(shader_, "texParams_"); // execute shader renderQuad(); // clean up shader_->deactivate(); outport_.deactivateTarget(); LGL_ERROR; }
/* * Pass the image from inport to outport without changes */ void ImageProcessorBypassable::bypass(RenderPort* inport, RenderPort* outport) { tgtAssert(inport && outport, "null pointer passed"); // activate and clear output render target outport->activateTarget(); outport->clearTarget(); // bind input rendering to texture units TextureUnit colorUnit, depthUnit; inport->bindTextures(colorUnit.getEnum(), depthUnit.getEnum()); // activate shader and set uniforms tgtAssert(bypassProgram_, "bypass shader not loaded"); bypassProgram_->activate(); setGlobalShaderParameters(bypassProgram_); inport->setTextureParameters(bypassProgram_, "texParams_"); bypassProgram_->setUniform("colorTex_", colorUnit.getUnitNumber()); bypassProgram_->setUniform("depthTex_", depthUnit.getUnitNumber()); // render screen aligned quad renderQuad(); // cleanup bypassProgram_->deactivate(); outport->deactivateTarget(); TextureUnit::setZeroUnit(); // check for OpenGL errors LGL_ERROR; }
void RenderLoopFinalizer::process() { if (loopOutport_.getLoopIteration() == loopOutport_.getNumLoopIterations()-1) { // last iteration: write input image to outport outport_.activateTarget(); } else { // loop iteration: write input image to loop port loopOutport_.activateTarget(); } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); TextureUnit colorUnit, depthUnit; inport_.bindTextures(colorUnit.getEnum(), depthUnit.getEnum()); LGL_ERROR; // initialize shader shaderPrg_->activate(); // set common uniforms used by all shaders setGlobalShaderParameters(shaderPrg_); // pass the remaining uniforms to the shader shaderPrg_->setUniform("colorTex_", colorUnit.getUnitNumber()); shaderPrg_->setUniform("depthTex_", depthUnit.getUnitNumber()); inport_.setTextureParameters(shaderPrg_, "texParams_"); renderQuad(); shaderPrg_->deactivate(); outport_.deactivateTarget(); TextureUnit::setZeroUnit(); LGL_ERROR; }
void Fade::process() { if (!enableSwitch_.get()){ bypass(&inport_, &outport_); return; } outport_.activateTarget(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); TextureUnit colorUnit, depthUnit; inport_.bindTextures(colorUnit.getEnum(), depthUnit.getEnum()); // intialize shader program_->activate(); setGlobalShaderParameters(program_); program_->setUniform("colorTex_", colorUnit.getUnitNumber()); program_->setUniform("depthTex_", depthUnit.getUnitNumber()); inport_.setTextureParameters(program_, "texParams_"); program_->setUniform("fading_", 1-fading_.get()); program_->setUniform("fadeColor_",color_.get()); renderQuad(); program_->deactivate(); outport_.deactivateTarget(); LGL_ERROR; }
void ToneMapping::process() { if (getInvalidationLevel() >= Processor::INVALID_PROGRAM) compile(); outport_.activateTarget(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); TextureUnit colorUnit, depthUnit; inport_.bindColorTexture(colorUnit.getEnum()); if (toneMappingMethod_.get() == "rahman-retinex") { glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glGenerateMipmapEXT(GL_TEXTURE_2D); } inport_.bindDepthTexture(depthUnit.getEnum()); // initialize shader program_->activate(); setGlobalShaderParameters(program_); // set uniforms program_->setUniform("colorTex_", colorUnit.getUnitNumber()); program_->setUniform("depthTex_", depthUnit.getUnitNumber()); inport_.setTextureParameters(program_, "textureParameters_"); // set method specific uniforms if (toneMappingMethod_.get() == "s-curve") { program_->setUniform("sigma_", scurveSigma_.get()); program_->setUniform("power_", scurvePower_.get()); } if (toneMappingMethod_.get() == "rahman-retinex") { if(rahmanTotalUpdate_ || inport_.hasChanged()){ wTotal_ = 0.0f; float i = 0.0f; while(i<rahmanIterations_.get()){ wTotal_ += pow(rahmanIterations_.get() - i + 1, rahmanFrequency_.get()); i++; } rahmanTotalUpdate_ = false; } //colorUnit.activate(); //glGenerateMipmapEXT(GL_TEXTURE_2D); program_->setUniform("frequency_", rahmanFrequency_.get()); program_->setUniform("subtractionFactor_", rahmanSubtractionFactor_.get()); program_->setUniform("iterations_", rahmanIterations_.get()); program_->setUniform("maxLevel_", rahmanMaxLevel_.get()); program_->setUniform("wTotal_", wTotal_); } renderQuad(); program_->deactivate(); outport_.deactivateTarget(); TextureUnit::setZeroUnit(); LGL_ERROR; }
void SimpleRaycaster::process() { // activate and clear output render target outport_.activateTarget(); outport_.clearTarget(); // retrieve shader from shader property tgt::Shader* shader = shader_.getShader(); if (!shader || !shader->isLinked()) { outport_.deactivateTarget(); return; } // activate shader and set common uniforms shader->activate(); tgt::Camera cam = camera_.get(); setGlobalShaderParameters(shader, &cam); // bind entry and exit params and pass texture units to the shader TextureUnit entryUnit, entryDepthUnit, exitUnit, exitDepthUnit; entryPort_.bindTextures(entryUnit, entryDepthUnit); shader->setUniform("entryPoints_", entryUnit.getUnitNumber()); shader->setUniform("entryPointsDepth_", entryDepthUnit.getUnitNumber()); entryPort_.setTextureParameters(shader, "entryParameters_"); exitPort_.bindTextures(exitUnit, exitDepthUnit); shader->setUniform("exitPoints_", exitUnit.getUnitNumber()); shader->setUniform("exitPointsDepth_", exitDepthUnit.getUnitNumber()); exitPort_.setTextureParameters(shader, "exitParameters_"); // bind volume texture and pass it to the shader std::vector<VolumeStruct> volumeTextures; TextureUnit volUnit; volumeTextures.push_back(VolumeStruct( volumePort_.getData(), &volUnit, "volume_", "volumeStruct_", volumePort_.getTextureClampModeProperty().getValue(), tgt::vec4(volumePort_.getTextureBorderIntensityProperty().get()), volumePort_.getTextureFilterModeProperty().getValue()) ); bindVolumes(shader, volumeTextures, &cam, lightPosition_.get()); // bind transfer function and pass it to the shader TextureUnit transferUnit; if (transferFunc_.get()) { transferUnit.activate(); transferFunc_.get()->bind(); transferFunc_.get()->setUniform(shader, "transferFunc_", "transferFuncTex_", transferUnit.getUnitNumber()); } // render screen aligned quad renderQuad(); // clean up shader->deactivate(); outport_.deactivateTarget(); TextureUnit::setZeroUnit(); LGL_ERROR; }
void ImageThreshold::process() { if (!enableSwitch_.get()){ bypass(&inport_, &outport_); return; } outport_.activateTarget(); outport_.clearTarget(); TextureUnit colorUnit, depthUnit; inport_.bindTextures(colorUnit, depthUnit); // initialize shader program_->activate(); setGlobalShaderParameters(program_); program_->setUniform("colorTex_", colorUnit.getUnitNumber()); program_->setUniform("depthTex_", depthUnit.getUnitNumber()); inport_.setTextureParameters(program_, "texParams_"); program_->setUniform("lowerThreshold_", lowerThreshold_.get()); program_->setUniform("upperThreshold_", upperThreshold_.get()); program_->setUniform("lowerMaskColor_", lowerMaskColor_.get()); program_->setUniform("upperMaskColor_", upperMaskColor_.get()); renderQuad(); program_->deactivate(); outport_.deactivateTarget(); TextureUnit::setZeroUnit(); LGL_ERROR; }
void RenderColorCube::fillEntryPoints(tgt::RenderTarget *firstBackTarget, tgt::RenderTarget *firstFrontTarget, tgt::RenderTarget *output, const tgt::Geometry *geometry, tgt::Camera *camera) { MatStack.matrixMode(tgt::MatrixStack::PROJECTION); MatStack.pushMatrix(); MatStack.loadIdentity(); MatStack.matrixMode(tgt::MatrixStack::MODELVIEW); MatStack.pushMatrix(); MatStack.loadIdentity(); shaderInsideVolume_->activate(); setGlobalShaderParameters(shaderInsideVolume_, camera, output->getSize()); // bind texture tgt::TextureUnit firstFrontUnit, firstFrontDepthUnit, firstBackUnit, firstBackDepthUnit; // bind firstFront points texture and depth texture firstFrontTarget->bindColorTexture(firstFrontUnit.getEnum()); shaderInsideVolume_->setUniform("firstFront_", firstFrontUnit.getUnitNumber()); firstFrontTarget->bindDepthTexture(firstFrontDepthUnit.getEnum()); shaderInsideVolume_->setUniform("firstFrontDepth_", firstFrontDepthUnit.getUnitNumber()); firstFrontTarget->setTextureParameters(shaderInsideVolume_, "firstFrontParameters_"); // bind firstBack points texture firstBackTarget->bindColorTexture(firstBackUnit.getEnum()); shaderInsideVolume_->setUniform("firstBack_", firstBackUnit.getUnitNumber()); firstBackTarget->bindDepthTexture(firstBackDepthUnit.getEnum()); //shaderInsideVolume_->setUniform("firstBackDepth_", firstBackDepthUnit.getUnitNumber()); firstBackTarget->setTextureParameters(shaderInsideVolume_, "firstBackParameters_"); shaderInsideVolume_->setUniform("near_", camera->getNearDist()); shaderInsideVolume_->setUniform("far_", camera->getFarDist()); tgt::BoundingBox bounds = geometry->getBoundingBox(false); shaderInsideVolume_->setUniform("llf_", bounds.getLLF()); shaderInsideVolume_->setUniform("urb_", bounds.getURB()); glm::mat4 worldToTextureMatrix = glm::inverse(geometry->getTransformationMatrix()); shaderInsideVolume_->setUniform("worldToTexture_", worldToTextureMatrix); output->activateTarget(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // render screen aligned quad renderQuad(); shaderInsideVolume_->deactivate(); output->deactivateTarget(); MatStack.matrixMode(tgt::MatrixStack::PROJECTION); MatStack.popMatrix(); MatStack.matrixMode(tgt::MatrixStack::MODELVIEW); MatStack.popMatrix(); LGL_ERROR; }
void RenderBackground::Process(tgt::RenderTarget *input) { privatetarget_->activateTarget(); MatStack.matrixMode(tgt::MatrixStack::PROJECTION); MatStack.loadIdentity(); MatStack.matrixMode(tgt::MatrixStack::MODELVIEW); MatStack.loadIdentity(); glClearDepth(1.0); glDisable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // first the background renderBackground(); privatetarget_->deactivateTarget(); /// /// glEnable(GL_DEPTH_TEST); // blending background with input output_->activateTarget(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // use the shader to to blend the original picture over the background and to keep the // depth values tgt::TextureUnit colorUnit0, depthUnit0, colorUnit1, depthUnit1; privatetarget_->bindTextures(colorUnit0.getEnum(), depthUnit0.getEnum()); input->bindTextures(colorUnit1.getEnum(), depthUnit1.getEnum()); // initialize shader program_->activate(); setGlobalShaderParameters(program_, 0, output_->getSize()); program_->setUniform("colorTex0_", colorUnit0.getUnitNumber()); program_->setUniform("depthTex0_", depthUnit0.getUnitNumber()); program_->setUniform("colorTex1_", colorUnit1.getUnitNumber()); program_->setUniform("depthTex1_", depthUnit1.getUnitNumber()); privatetarget_->setTextureParameters(program_, "textureParameters0_"); input->setTextureParameters(program_, "textureParameters1_"); glDepthFunc(GL_ALWAYS); renderQuad(); glDepthFunc(GL_LESS); program_->deactivate(); output_->deactivateTarget(); tgt::TextureUnit::setZeroUnit(); }
void EntryExitPoints::jitterEntryPoints() { // if canvas resolution has changed, regenerate jitter texture if (!jitterTexture_ || (jitterTexture_->getDimensions().x != entryPort_.getSize().x) || (jitterTexture_->getDimensions().y != entryPort_.getSize().y)) { generateJitterTexture(); } shaderProgramJitter_->activate(); tgt::Camera cam = camera_.get(); setGlobalShaderParameters(shaderProgramJitter_, &cam); // bind jitter texture TextureUnit jitterUnit; jitterUnit.activate(); jitterTexture_->bind(); jitterTexture_->uploadTexture(); shaderProgramJitter_->setUniform("jitterTexture_", jitterUnit.getUnitNumber()); shaderProgramJitter_->setIgnoreUniformLocationError(true); shaderProgramJitter_->setUniform("jitterParameters_.dimensions_", tgt::vec2(jitterTexture_->getDimensions().xy())); shaderProgramJitter_->setUniform("jitterParameters_.dimensionsRCP_", tgt::vec2(1.0f) / tgt::vec2(jitterTexture_->getDimensions().xy())); shaderProgramJitter_->setUniform("jitterParameters_.matrix_", tgt::mat4::identity); shaderProgramJitter_->setIgnoreUniformLocationError(false); // bind entry points texture and depth texture (have been rendered to temporary port) TextureUnit entryParams, exitParams, entryParamsDepth; tmpPort_.bindColorTexture(entryParams.getEnum()); shaderProgramJitter_->setUniform("entryPoints_", entryParams.getUnitNumber()); tmpPort_.bindDepthTexture(entryParamsDepth.getEnum()); shaderProgramJitter_->setUniform("entryPointsDepth_", entryParamsDepth.getUnitNumber()); tmpPort_.setTextureParameters(shaderProgramJitter_, "entryParameters_"); // bind exit points texture exitPort_.bindColorTexture(exitParams.getEnum()); shaderProgramJitter_->setUniform("exitPoints_", exitParams.getUnitNumber()); exitPort_.setTextureParameters(shaderProgramJitter_, "exitParameters_"); shaderProgramJitter_->setUniform("stepLength_", jitterStepLength_.get()); entryPort_.activateTarget("jitteredEntryParams"); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // render screen aligned quad renderQuad(); shaderProgramJitter_->deactivate(); }
void SimpleRaycaster::process() { // activate and clear output render target outport_.activateTarget(); outport_.clearTarget(); // activate shader and set common uniforms raycastPrg_->activate(); tgt::Camera cam = camera_.get(); setGlobalShaderParameters(raycastPrg_, &cam); // bind entry and exit params and pass texture units to the shader TextureUnit entryUnit, entryDepthUnit, exitUnit, exitDepthUnit; entryPort_.bindTextures(entryUnit, entryDepthUnit); raycastPrg_->setUniform("entryPoints_", entryUnit.getUnitNumber()); raycastPrg_->setUniform("entryPointsDepth_", entryDepthUnit.getUnitNumber()); entryPort_.setTextureParameters(raycastPrg_, "entryParameters_"); exitPort_.bindTextures(exitUnit, exitDepthUnit); raycastPrg_->setUniform("exitPoints_", exitUnit.getUnitNumber()); raycastPrg_->setUniform("exitPointsDepth_", exitDepthUnit.getUnitNumber()); exitPort_.setTextureParameters(raycastPrg_, "exitParameters_"); // bind volume texture and pass it to the shader std::vector<VolumeStruct> volumeTextures; TextureUnit volUnit; volumeTextures.push_back(VolumeStruct( volumePort_.getData()->getVolumeGL(), &volUnit, "volume_", "volumeParameters_", true) ); bindVolumes(raycastPrg_, volumeTextures, &cam, lightPosition_.get()); // bind transfer function and pass it to the shader TextureUnit transferUnit; if (transferFunc_.get()) { transferUnit.activate(); transferFunc_.get()->bind(); raycastPrg_->setUniform("transferFunc_", transferUnit.getUnitNumber()); } // render screen aligned quad renderQuad(); // clean up raycastPrg_->deactivate(); outport_.deactivateTarget(); TextureUnit::setZeroUnit(); LGL_ERROR; }
void DepthPeelingProcessor::process() { outport_.activateTarget(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // set modelview and projection matrices glMatrixMode(GL_PROJECTION); tgt::loadMatrix(camera_.get().getProjectionMatrix()); glMatrixMode(GL_MODELVIEW); tgt::loadMatrix(camera_.get().getViewMatrix()); LGL_ERROR; TextureUnit depthTexUnit; inport_.bindDepthTexture(depthTexUnit.getEnum()); LGL_ERROR; // initialize shader shaderPrg_->activate(); // set common uniforms used by all shaders tgt::Camera cam = camera_.get(); setGlobalShaderParameters(shaderPrg_, &cam); // pass the remaining uniforms to the shader shaderPrg_->setUniform("depthTex_", depthTexUnit.getUnitNumber()); inport_.setTextureParameters(shaderPrg_, "depthTexParameters_"); std::vector<GeometryRendererBase*> portData = cpPort_.getConnectedProcessors(); for (size_t i=0; i<portData.size(); i++) { GeometryRendererBase* pdcp = portData.at(i); if(pdcp->isReady()) { pdcp->setCamera(camera_.get()); pdcp->setViewport(outport_.getSize()); pdcp->render(); LGL_ERROR; } } shaderPrg_->deactivate(); outport_.deactivateTarget(); // restore matrices glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); LGL_ERROR; }
void ColorDepth::process() { if (!enableSwitch_.get()) { bypass(&inport_, &outport_); return; } if (!chromaDepthTex_) { LERROR("No chroma depth texture"); return; } //compute Depth Range tgt::vec2 depthRange = computeDepthRange(&inport_); outport_.activateTarget(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); TextureUnit colorUnit, depthUnit; inport_.bindTextures(colorUnit.getEnum(), depthUnit.getEnum()); // bind chroma depth texture TextureUnit chromaDepthUnit; chromaDepthUnit.activate(); //chromaDepthTex_ is 0 here chromaDepthTex_->bind(); LGL_ERROR; // initialize shader program_->activate(); setGlobalShaderParameters(program_); program_->setUniform("colorTex_", colorUnit.getUnitNumber()); program_->setUniform("depthTex_", depthUnit.getUnitNumber()); inport_.setTextureParameters(program_, "texParams_"); program_->setUniform("chromadepthTex_", chromaDepthUnit.getUnitNumber()); program_->setUniform("minDepth_", depthRange.x); program_->setUniform("maxDepth_", depthRange.y); program_->setUniform("colorMode_", colorMode_.getValue()); program_->setUniform("colorDepthFactor_", factor_.get()); renderQuad(); program_->deactivate(); TextureUnit::setZeroUnit(); outport_.deactivateTarget(); LGL_ERROR; }
void ButtonOverlayProcessor::process() { if (!outport_.isReady()) return; if (!inport_.isReady()) return; if (getInvalidationLevel() >= Processor::INVALID_PROGRAM) compile(); if(outport_.getSize() != oldSize_) { regenerateOverlay_ = true; oldSize_ = outport_.getSize(); } if(regenerateOverlay_) renderOverlayImage(); outport_.activateTarget(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); TextureUnit colorUnit0, depthUnit0, colorUnit1, depthUnit1; overlayPort_.bindTextures(colorUnit0.getEnum(), depthUnit0.getEnum()); inport_.bindTextures(colorUnit1.getEnum(), depthUnit1.getEnum()); // initialize shader program_->activate(); setGlobalShaderParameters(program_); program_->setUniform("colorTex0_", colorUnit0.getUnitNumber()); program_->setUniform("depthTex0_", depthUnit0.getUnitNumber()); program_->setUniform("colorTex1_", colorUnit1.getUnitNumber()); program_->setUniform("depthTex1_", depthUnit1.getUnitNumber()); overlayPort_.setTextureParameters(program_, "textureParameters0_"); inport_.setTextureParameters(program_, "textureParameters1_"); glDepthFunc(GL_ALWAYS); renderQuad(); glDepthFunc(GL_LESS); outport_.deactivateTarget(); program_->deactivate(); TextureUnit::setZeroUnit(); LGL_ERROR; }
void EntryExitPoints::complementClippedEntryPoints() { // note: since this a helper function which is only called internally, // we assume that the modelview and projection matrices have already been set correctly // and that a current dataset is available tgtAssert(inport_.getData(), "No Volume active"); tgtAssert(shaderProgramClipping_, "Clipping shader not available"); RenderPort& activePort = jitterEntryPoints_.get() ? entryPort_ : tmpPort_; TextureUnit entryUnit, entryDepthUnit, exitUnit; activePort.bindTextures(entryUnit.getEnum(), entryDepthUnit.getEnum()); exitPort_.bindColorTexture(exitUnit.getEnum()); LGL_ERROR; shaderProgramClipping_->activate(); tgt::Camera cam = camera_.get(); setGlobalShaderParameters(shaderProgramClipping_, &cam); shaderProgramClipping_->setUniform("entryTex_", entryUnit.getUnitNumber()); activePort.setTextureParameters(shaderProgramClipping_, "entryParameters_"); shaderProgramClipping_->setUniform("exitTex_", exitUnit.getUnitNumber()); exitPort_.setTextureParameters(shaderProgramClipping_, "exitParameters_"); shaderProgramClipping_->setUniform("entryTexDepth_", entryDepthUnit.getUnitNumber()); shaderProgramClipping_->setUniform("volumeCubeSizeRCP_", 1.f / inport_.getData()->getVolume()->getCubeSize()); LGL_ERROR; glCullFace(GL_FRONT); // write to temporary target if jittering is active if (jitterEntryPoints_.get()) tmpPort_.activateTarget("entry filled"); else entryPort_.activateTarget("entry filled"); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); cpPort_.getConnectedProcessor()->render(); shaderProgramClipping_->deactivate(); glCullFace(GL_BACK); LGL_ERROR; }
void ImageSource::process() { // clear output outport_.activateTarget(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); LGL_ERROR; // no image to render if (!texture_) { outport_.invalidateResult(); outport_.deactivateTarget(); LGL_ERROR; return; } // activate shader shader_->activate(); // set common uniforms setGlobalShaderParameters(shader_); // bind image texture glActiveTexture(GL_TEXTURE0); texture_->bind(); LGL_ERROR; // pass texture parameters to the shader shader_->setUniform("colorTex_", 0); shader_->setIgnoreUniformLocationError(true); shader_->setUniform("texParams_.dimensions_", tgt::vec2(texture_->getDimensions().xy())); shader_->setUniform("texParams_.dimensionsRCP_", tgt::vec2(1.f) / tgt::vec2(texture_->getDimensions().xy())); shader_->setUniform("texParams_.matrix_", tgt::mat4::identity); shader_->setIgnoreUniformLocationError(false); // execute the shader renderQuad(); LGL_ERROR; // clean up shader_->deactivate(); outport_.deactivateTarget(); LGL_ERROR; }
void UnaryImageProcessor::process() { if (!enableSwitch_.get()) { bypass(&inport_, &outport_); return; } outport_.activateTarget(); // compile program if needed if (getInvalidationLevel() >= Processor::INVALID_PROGRAM) compile(); LGL_ERROR; // initialize shader if (!program_ || !program_->isLinked()) return; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); TextureUnit colorUnit, depthUnit; inport_.bindTextures(colorUnit.getEnum(), depthUnit.getEnum()); program_->activate(); setGlobalShaderParameters(program_); program_->setIgnoreUniformLocationError(true); program_->setUniform("colorTex_", colorUnit.getUnitNumber()); program_->setUniform("depthTex_", depthUnit.getUnitNumber()); inport_.setTextureParameters(program_, "texParams_"); program_->setIgnoreUniformLocationError(false); glDepthFunc(GL_ALWAYS); renderQuad(); glDepthFunc(GL_LESS); program_->deactivate(); outport_.deactivateTarget(); glActiveTexture(GL_TEXTURE0); LGL_ERROR; }
void Convolution::process() { if (!enableSwitch_.get()) { bypass(&inport_, &outport_); return; } // activate and clear output render target outport_.activateTarget(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // bind result from previous processor inport_.bindTextures(GL_TEXTURE0, GL_TEXTURE1); filterPort_.bindColorTexture(GL_TEXTURE2); // activate shader and set uniforms: program_->activate(); setGlobalShaderParameters(program_); LGL_ERROR; program_->setUniform("colorTex_", 0); program_->setUniform("depthTex_", 1); inport_.setTextureParameters(program_, "textureParameters_"); LGL_ERROR; program_->setUniform("filter_", 2); LGL_ERROR; filterPort_.setTextureParameters(program_, "filterParameters_"); LGL_ERROR; program_->setUniform("filterSize_", filterSize_.get()); LGL_ERROR; // render screen aligned quad: glDepthFunc(GL_ALWAYS); renderQuad(); glDepthFunc(GL_LESS); program_->deactivate(); outport_.deactivateTarget(); glActiveTexture(GL_TEXTURE0); LGL_ERROR; }
void RenderColorCube::renderGeometry(const tgt::Geometry* geometry, tgt::Camera *camera, tgt::RenderTarget* outport, GLenum depthFunc, float clearDepth, GLenum cullFace) { // activate shader program shader_->activate(); setGlobalShaderParameters(shader_, camera, outport->getSize()); shader_->setUniform("modelMatrix_", geometry->getTransformationMatrix()); // enable culling glEnable(GL_CULL_FACE); outport->activateTarget(); outport->clearTarget(); glClearDepth(clearDepth); glDepthFunc(depthFunc); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glCullFace(cullFace); geometry->render(); outport->deactivateTarget(); glFinish(); // deactivate shader program shader_->deactivate(); glDepthFunc(GL_LESS); glDisable(GL_CULL_FACE); glCullFace(GL_BACK); glClearDepth(1.0f); LGL_ERROR; }
void BinaryImageProcessor::process() { // compile program if needed if (getInvalidationLevel() >= Processor::INVALID_PROGRAM) compile(); LGL_ERROR; if(!program_ || !program_->isLinked()) return; outport_.activateTarget(); outport_.clearTarget(); TextureUnit colorUnit0, depthUnit0, colorUnit1, depthUnit1; inport0_.bindTextures(colorUnit0.getEnum(), depthUnit0.getEnum()); inport1_.bindTextures(colorUnit1.getEnum(), depthUnit1.getEnum()); // initialize shader program_->activate(); setGlobalShaderParameters(program_); program_->setIgnoreUniformLocationError(true); program_->setUniform("colorTex0_", colorUnit0.getUnitNumber()); program_->setUniform("depthTex0_", depthUnit0.getUnitNumber()); program_->setUniform("colorTex1_", colorUnit1.getUnitNumber()); program_->setUniform("depthTex1_", depthUnit1.getUnitNumber()); inport0_.setTextureParameters(program_, "texParams0_"); inport1_.setTextureParameters(program_, "texParams1_"); program_->setIgnoreUniformLocationError(false); glDepthFunc(GL_ALWAYS); renderQuad(); glDepthFunc(GL_LESS); program_->deactivate(); outport_.deactivateTarget(); TextureUnit::setZeroUnit(); LGL_ERROR; }
void ImageMasking::process() { outport_.activateTarget(); outport_.clearTarget(); TextureUnit colorUnit, depthUnit, maskUnit; inport_.bindTextures(colorUnit.getEnum(), depthUnit.getEnum()); inportMask_.bindColorTexture(maskUnit.getEnum()); // compile program if needed if (getInvalidationLevel() >= Processor::INVALID_PROGRAM) compile(); LGL_ERROR; // initialize shader program_->activate(); setGlobalShaderParameters(program_); program_->setIgnoreUniformLocationError(true); program_->setUniform("colorTex_", colorUnit.getUnitNumber()); program_->setUniform("depthTex_", depthUnit.getUnitNumber()); program_->setUniform("colorTexMask_", maskUnit.getUnitNumber()); inport_.setTextureParameters(program_, "texParams_"); inportMask_.setTextureParameters(program_, "texParamsMask_"); program_->setIgnoreUniformLocationError(false); program_->setUniform("maskColor_", maskColor_.get()); glDepthFunc(GL_ALWAYS); renderQuad(); glDepthFunc(GL_LESS); program_->deactivate(); outport_.deactivateTarget(); glActiveTexture(GL_TEXTURE0); LGL_ERROR; }
void ConnectedComponents2D::process() { // activate and clear output render target outport_.activateTarget(); outport_.clearTarget(); tgt::col4* colorBuffer = inport_.readColorBuffer<uint8_t>(); LGL_ERROR; int numPixels = tgt::hmul(inport_.getSize()); uint8_t* img = new uint8_t[numPixels]; switch (channel_.getValue()) { case GL_RED: for (int i=0; i<numPixels; i++) img[i] = colorBuffer[i].r; break; case GL_GREEN: for (int i=0; i<numPixels; i++) img[i] = colorBuffer[i].g; break; case GL_BLUE: for (int i=0; i<numPixels; i++) img[i] = colorBuffer[i].b; break; case GL_ALPHA: for (int i=0; i<numPixels; i++) img[i] = colorBuffer[i].a; break; case GL_RGB: // no correct gray value conversion necessary here, since we only need to assign a value greater zero // to foreground pixels for (int i=0; i<numPixels; i++) img[i] = (colorBuffer[i].r > 0 ? 1 : 0) + (colorBuffer[i].g > 0 ? 1 : 0) + (colorBuffer[i].b > 0 ? 1 : 0); break; case GL_RGBA: for (int i=0; i<numPixels; i++) img[i] = (colorBuffer[i].r > 0 ? 1 : 0) + (colorBuffer[i].g > 0 ? 1 : 0) + (colorBuffer[i].b > 0 ? 1 : 0) + (colorBuffer[i].a > 0 ? 1 : 0); break; default: LWARNING("Unknown channel option: " << channel_.get()); } delete[] colorBuffer; // compute connected components uint16_t* labels = new uint16_t[tgt::hmul(inport_.getSize())]; //Connexe_verbose(); tgt::ivec3 size(inport_.getSize(), 1); int numLabels = CountConnectedComponentsWithAllParams(reinterpret_cast<void*>(img), UCHAR_TYPE, reinterpret_cast<void*>(labels), USHORT_TYPE, size.elem, 1.0, connectivity_.getValue(), minComponentSize_.get(), maxComponents_.get(), binarizeOutput_.get() ? 1 : 0); // free cpu buffer delete[] img; // sort components if (!componentSorting_.isSelected("none") && !binarizeOutput_.get()) { int decreasing = componentSorting_.isSelected("decreasing") ? 1 : 0; RelabelConnectedComponentsBySize(labels, USHORT_TYPE, size.elem, decreasing); } // stretch labels to use full range if (stretchLabels_.get() && !binarizeOutput_.get()) { float scale = static_cast<float>((1<<16) - 2) / numLabels; for (int i=0; i<tgt::hmul(inport_.getSize()); i++) labels[i] = tgt::ifloor(labels[i]*scale); } // render label texture TextureUnit colorUnit, depthUnit; colorUnit.activate(); tgt::Texture* labelTex = new tgt::Texture(reinterpret_cast<GLubyte*>(labels), tgt::ivec3(inport_.getSize(), 1), GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_SHORT, tgt::Texture::NEAREST, !GpuCaps.isNpotSupported()); labelTex->uploadTexture(); program_->activate(); inport_.bindDepthTexture(depthUnit.getEnum()); inport_.setTextureParameters(program_, "texParams_"); setGlobalShaderParameters(program_); program_->setUniform("colorTex_", colorUnit.getUnitNumber()); program_->setUniform("depthTex_", depthUnit.getUnitNumber()); // render screen aligned quad: glDepthFunc(GL_ALWAYS); renderQuad(); glDepthFunc(GL_LESS); // cleanup program_->deactivate(); delete labelTex; outport_.deactivateTarget(); glActiveTexture(GL_TEXTURE0); LGL_ERROR; }
/** * Performs the raycasting. * * Initialize two texture units with the entry and exit params and renders * a screen aligned quad. */ void IDRaycaster::process() { if (!volumePort_.isReady()) return; if(getInvalidationLevel() >= Processor::INVALID_PROGRAM) compile(); LGL_ERROR; idMapPort_.activateTarget(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // don't render when in interaction mode if (interactionMode()) { idMapPort_.deactivateTarget(); TextureUnit::setZeroUnit(); return; } TextureUnit entryUnit, entryDepthUnit, exitUnit, exitDepthUnit, firstHitPointUnit; // bind entry params entryPort_.bindTextures(entryUnit.getEnum(), entryDepthUnit.getEnum()); // bind first hit points firstHitpointsPort_.bindColorTexture(firstHitPointUnit.getEnum()); // bind exit params exitPort_.bindTextures(exitUnit.getEnum(), exitDepthUnit.getEnum()); // vector containing the volumes to bind std::vector<VolumeStruct> volumes; TextureUnit volUnit; volumes.push_back(VolumeStruct( volumePort_.getData(), &volUnit, "segmentation_","segmentationParameters_", GL_CLAMP_TO_EDGE, tgt::vec4(0.f), GL_NEAREST) ); // initialize shader raycastPrg_->activate(); tgt::Camera cam = camera_.get(); setGlobalShaderParameters(raycastPrg_, &cam); bindVolumes(raycastPrg_, volumes, &cam, lightPosition_.get()); raycastPrg_->setUniform("entryPoints_", entryUnit.getUnitNumber()); raycastPrg_->setUniform("entryPointsDepth_", entryDepthUnit.getUnitNumber()); entryPort_.setTextureParameters(raycastPrg_, "entryParameters_"); raycastPrg_->setUniform("firstHitPoints_", firstHitPointUnit.getUnitNumber()); firstHitpointsPort_.setTextureParameters(raycastPrg_, "firstHitParameters_"); raycastPrg_->setUniform("exitPoints_", exitUnit.getUnitNumber()); raycastPrg_->setUniform("exitPointsDepth_", exitDepthUnit.getUnitNumber()); entryPort_.setTextureParameters(raycastPrg_, "exitParameters_"); raycastPrg_->setUniform("penetrationDepth_", penetrationDepth_.get()); renderQuad(); raycastPrg_->deactivate(); idMapPort_.deactivateTarget(); TextureUnit::setZeroUnit(); LGL_ERROR; }
void TextOverlay::process() { if (!inport_.isReady()) outport_.activateTarget(); else privatePort_.activateTarget(); if (getInvalidationLevel() >= Processor::INVALID_PROGRAM) compile(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClearDepth(1.0); glDisable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); #ifndef VRN_MODULE_FONTRENDERING LWARNING("Empty output, enable module 'fontrendering'."); #endif if(enabled_.get()) renderOverlay(); if (!inport_.isReady()) outport_.deactivateTarget(); else privatePort_.deactivateTarget(); glEnable(GL_DEPTH_TEST); // skip if there's nothing to render above if (inport_.isReady()) { outport_.activateTarget(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); TextureUnit colorUnit0, colorUnit1, depthUnit0, depthUnit1; privatePort_.bindTextures(colorUnit0.getEnum(), depthUnit0.getEnum()); inport_.bindTextures(colorUnit1.getEnum(), depthUnit1.getEnum()); // initialize shader program_->activate(); setGlobalShaderParameters(program_); program_->setUniform("colorTex0_", colorUnit0.getUnitNumber()); program_->setUniform("colorTex1_", colorUnit1.getUnitNumber()); program_->setUniform("depthTex1_", depthUnit1.getUnitNumber()); privatePort_.setTextureParameters(program_, "textureParameters0_"); inport_.setTextureParameters(program_, "textureParameters1_"); program_->setUniform("option_", blendMode_.getValue()); ImageProcessor::renderQuad(); outport_.deactivateTarget(); TextureUnit::setZeroUnit(); program_->deactivate(); } LGL_ERROR; }
void GeometryRenderer::render() { tgtAssert(inport_.hasData(), "No geometry"); if(useShader_.get() && (!shaderProp_.hasValidShader() || getInvalidationLevel() >= Processor::INVALID_PROGRAM)) compile(); if(useShader_.get() && !shaderProp_.hasValidShader()) { LERROR("Shader for geometry failed to compile"); return; } glPushAttrib(GL_ALL_ATTRIB_BITS); glPolygonMode(GL_FRONT_AND_BACK, polygonMode_.getValue()); glShadeModel(GL_SMOOTH); if (polygonMode_.isSelected("point")) glPointSize(pointSize_.get()); else if (polygonMode_.isSelected("line")) glLineWidth(lineWidth_.get()); if (mapTexture_.get() && texPort_.isReady()) { texPort_.bindColorTexture(GL_TEXTURE0); glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, textureMode_.getValue()); } if (enableLighting_.get()) { glEnable(GL_LIGHTING); glEnable(GL_COLOR_MATERIAL); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, tgt::vec4(0.f).elem); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, lightPosition_.get().elem); glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient_.get().elem); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse_.get().elem); glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular_.get().elem); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, materialShininess_.get()); LGL_ERROR; } // for triangle meshes, we need to use a correctly layouted shader if(useShader_.get()) { tgt::Shader* prog = shaderProp_.getShader(); prog->activate(); setGlobalShaderParameters(prog, &camera_); prog->setIgnoreUniformLocationError(true); prog->setUniform("enableLighting_", enableLighting_.get()); if(enableLighting_.get()) { prog->setUniform("lightPosition_", lightPosition_.get()); prog->setUniform("lightSource_.ambientColor_", lightAmbient_.get().xyz()); prog->setUniform("lightSource_.diffuseColor_", lightDiffuse_.get().xyz()); prog->setUniform("lightSource_.specularColor_", lightSpecular_.get().xyz()); //prog->setUniform("lightSource_.attenuation_", tgt::vec3(1.f, 0.f, 0.f)); prog->setUniform("shininess_", materialShininess_.get()); } prog->setUniform("enableClipping_", enableClipping_.get()); if(enableClipping_.get()) prog->setUniform("plane_", tgt::vec4(normalize(planeNormal_.get()), planeDistance_.get())); } inport_.getData()->render(); if(useShader_.get()) shaderProp_.getShader()->deactivate(); glPopAttrib(); }