예제 #1
0
void bindAndSetUniforms(Shader& shader, TextureUnitContainer& cont,
    const TransferFunctionProperty& tf) {
    TextureUnit unit;
    bindTexture(tf, unit);
    shader.setUniform(tf.getIdentifier(), unit.getUnitNumber());
    cont.push_back(std::move(unit));
}
예제 #2
0
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;
}
예제 #3
0
void bindAndSetUniforms(Shader& shader, TextureUnitContainer& cont,
    const Texture& texture, const std::string samplerID) {
    TextureUnit unit;
    bindTexture(texture, unit);
    shader.setUniform(samplerID, unit.getUnitNumber());
    cont.push_back(std::move(unit));
}
예제 #4
0
void bindAndSetUniforms(Shader& shader, TextureUnitContainer& cont, VolumeInport& volumePort) {
    TextureUnit unit;
    utilgl::bindTexture(volumePort, unit);
    shader.setUniform(volumePort.getIdentifier(), unit.getUnitNumber());
    utilgl::setShaderUniforms(shader, volumePort, volumePort.getIdentifier() + "Parameters");
    cont.push_back(std::move(unit));
}
예제 #5
0
void ImageGLProcessor::process() {
    if (internalInvalid_) {
        internalInvalid_ = false;
        const DataFormatBase* format = inport_.getData()->getDataFormat();
        size2_t dimensions;
        if (outport_.isHandlingResizeEvents() || !inport_.isOutportDeterminingSize())
            dimensions  = outport_.getData()->getDimensions();
        else
            dimensions = inport_.getData()->getDimensions();
        if (!outport_.hasData() || format != outport_.getData()->getDataFormat()
            || dimensions != outport_.getData()->getDimensions()){
            Image *img = new Image(dimensions, format);
            img->copyMetaDataFrom(*inport_.getData());
            outport_.setData(img);
        }
    }

    TextureUnit imgUnit;    
    utilgl::bindColorTexture(inport_, imgUnit);

    utilgl::activateTargetAndCopySource(outport_, inport_, ImageType::ColorOnly);
    shader_.activate();

    utilgl::setShaderUniforms(shader_, outport_, "outportParameters_");
    shader_.setUniform("inport_", imgUnit.getUnitNumber());

    preProcess();

    utilgl::singleDrawImagePlaneRect();
    shader_.deactivate();
    utilgl::deactivateCurrentTarget();

    postProcess();
}
예제 #6
0
void ImageMapping::preProcess() {
    TextureUnit transFuncUnit;
    const Layer* tfLayer = transferFunction_.get().getData();
    const LayerGL* transferFunctionGL = tfLayer->getRepresentation<LayerGL>();

    transferFunctionGL->bindTexture(transFuncUnit.getEnum());
    shader_.setUniform("transferFunc_", transFuncUnit.getUnitNumber());
}
예제 #7
0
IVW_MODULE_OPENGL_API void bindAndSetUniforms(Shader& shader, TextureUnitContainer& cont,
                                              const Volume& volume, const std::string& samplerID) {
    TextureUnit unit;
    utilgl::bindTexture(volume, unit);
    shader.setUniform(samplerID, unit.getUnitNumber());
    utilgl::setShaderUniforms(shader, volume, samplerID + "Parameters");
    cont.push_back(std::move(unit));
}
void PCPUploadRenderer::renderParallelCoordinates() {
    std::shared_ptr<const ParallelCoordinatesPlotRawData> data = _inport.getData();
    int nDimensions = data->minMax.size();
    int nValues = data->data.size();

    utilgl::GlBoolState depthTest(GL_DEPTH_TEST, !_depthTesting);
    utilgl::BlendModeEquationState blendEquation(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_FUNC_ADD);

    utilgl::GlBoolState lineSmooth(GL_LINE_SMOOTH, _lineSmoothing);
    if (_lineSmoothing)
        glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

    _shader.activate();

    _shader.setUniform("_nDimensions", nDimensions);
    _shader.setUniform("_nData", nValues / nDimensions);
    _shader.setUniform("_horizontalBorder", _horizontalBorder);
    _shader.setUniform("_verticalBorder", _verticalBorder);
    _shader.setUniform("_depthTesting", !_depthTesting);
    _shader.setUniform("_alphaFactor", _alphaFactor);

    TextureUnit tfUnit;
    utilgl::bindTexture(_transFunc, tfUnit);
    _shader.setUniform("_transFunc", tfUnit.getUnitNumber());

    glBindVertexArray(_vao);

    bool hasColoringData = _coloringData.hasData() && _coloringData.getData()->hasData;
    _shader.setUniform("_hasColoringData", hasColoringData);
    if (hasColoringData) {
        glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, _coloringData.getData()->ssboColor);
    }

    //glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, data->ssboData);
    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, _dimensionOrderingBuffer);

    //for (int i = 0; i < nValues / nDimensions; ++i) {
    //    glDrawElements(GL_LINE_STRIP, nDimensions, )
    //}

    glEnable(GL_PRIMITIVE_RESTART);
    glPrimitiveRestartIndex(PRIM_RESTART);

    glDrawElements(GL_LINE_STRIP, nValues / nDimensions, GL_UNSIGNED_INT, _drawElements);


    glDisable(GL_PRIMITIVE_RESTART);
    //glDrawArrays(GL_LINE_STRIP, 0, nValues);

    //glMultiDrawArrays(GL_LINE_STRIP, _multiDrawIndices, _multiDrawCount, nValues / nDimensions);

    //glDrawArraysInstanced(GL_LINE_STRIP, 0, data->nDimensions, data->nValues / data->nDimensions);

    glBindVertexArray(0);

    _shader.deactivate();
}
예제 #9
0
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;
}
예제 #10
0
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();
}
예제 #11
0
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;
}
예제 #12
0
void CanvasGL::renderLayer(size_t idx) {
    previousRenderedLayerIdx_ = idx;
    if (imageGL_) {
        const LayerGL* layerGL = imageGL_->getLayerGL(layerType_,idx);
        if (layerGL) {
            TextureUnit textureUnit;
            layerGL->bindTexture(textureUnit.getEnum());
            renderTexture(textureUnit.getUnitNumber());
            layerGL->unbindTexture();
            return;
        } else {
            renderNoise();
        }
    }
    if (!image_) renderNoise();
}
예제 #13
0
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;
}
예제 #14
0
void bindAndSetUniforms(Shader& shader, TextureUnitContainer& cont, const Image& image,
                        const std::string& id, ImageType type) {
    switch (type) {
        case COLOR_ONLY: {
            TextureUnit unit;
            bindColorTexture(image, unit);
            utilgl::setShaderUniforms(shader, image, id + "Parameters");
            shader.setUniform(id + "Color", unit.getUnitNumber());
            cont.push_back(std::move(unit));
            break;
        }
        case COLOR_DEPTH: {
            TextureUnit unit1, unit2;
            bindTextures(image, unit1, unit2);
            utilgl::setShaderUniforms(shader, image, id + "Parameters");
            shader.setUniform(id + "Color", unit1.getUnitNumber());
            shader.setUniform(id + "Depth", unit2.getUnitNumber());
            cont.push_back(std::move(unit1));
            cont.push_back(std::move(unit2));
            break;
        }
        case COLOR_PICKING: {
            TextureUnit unit1, unit2;
            bindColorTexture(image, unit1);
            bindPickingTexture(image, unit2);
            utilgl::setShaderUniforms(shader, image, id + "Parameters");
            shader.setUniform(id + "Color", unit1.getUnitNumber());
            shader.setUniform(id + "Picking", unit2.getUnitNumber());
            cont.push_back(std::move(unit1));
            cont.push_back(std::move(unit2));
            break;
        }
        case COLOR_DEPTH_PICKING: {
            TextureUnit unit1, unit2, unit3;
            bindTextures(image, unit1, unit2, unit3);
            utilgl::setShaderUniforms(shader, image, id + "Parameters");
            shader.setUniform(id + "Color", unit1.getUnitNumber());
            shader.setUniform(id + "Depth", unit2.getUnitNumber());
            shader.setUniform(id + "Picking", unit3.getUnitNumber());
            cont.push_back(std::move(unit1));
            cont.push_back(std::move(unit2));
            cont.push_back(std::move(unit3));
            break;
        }
    }
}
void PCPRenderer::renderParallelCoordinates() {
    std::shared_ptr<const ParallelCoordinatesPlotData> data = _inport.getData();
    utilgl::GlBoolState depthTest(GL_DEPTH_TEST, !_depthTesting);

    //utilgl::GlBoolState alpha(GL_ALPHA, _alphaFactor != 1.f);
    utilgl::BlendModeEquationState blendEquation(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_FUNC_ADD);

    utilgl::GlBoolState lineSmooth(GL_LINE_SMOOTH, _lineSmoothing);
    if (_lineSmoothing)
        glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

    _shader.activate();

    _shader.setUniform("_nDimensions", data->nDimensions);
    _shader.setUniform("_nData", data->nValues / data->nDimensions);
    _shader.setUniform("_horizontalBorder", _horizontalBorder);
    _shader.setUniform("_verticalBorder", _verticalBorder);
    _shader.setUniform("_depthTesting", _depthTesting);
    _shader.setUniform("_alphaFactor", _alphaFactor);

    TextureUnit tfUnit;
    utilgl::bindTexture(_transFunc, tfUnit);
    _shader.setUniform("_transFunc", tfUnit.getUnitNumber());

    glBindVertexArray(_vao);

    bool hasColoringData = _coloringData.hasData() && _coloringData.getData()->hasData;
    _shader.setUniform("_hasColoringData", hasColoringData);
    if (hasColoringData) {
        glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, _coloringData.getData()->ssboColor);
    }

    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, data->ssboData);
    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, _dimensionOrderingBuffer);

    glDrawArraysInstanced(GL_LINE_STRIP, 0, data->nDimensions, data->nValues / data->nDimensions);

    glBindVertexArray(0);

    _shader.deactivate();
}
예제 #16
0
void RGBRaycaster::process() {

    if (!volumePort_.isReady())
        return;

    if (!outport_.isReady())
        return;

    outport_.activateTarget();

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // compile program
    if (getInvalidationLevel() >= Processor::INVALID_PROGRAM)
        compile();
    LGL_ERROR;

    TextureUnit entryUnit, entryDepthUnit, exitUnit, exitDepthUnit;
    // bind entry params
    entryPort_.bindTextures(entryUnit.getEnum(), entryDepthUnit.getEnum());

    // bind exit params
    exitPort_.bindTextures(exitUnit.getEnum(), exitDepthUnit.getEnum());

    // vector containing the volumes to bind; is passed to bindVolumes()
    std::vector<VolumeStruct> volumeTextures;

    // add main volume
    TextureUnit volUnit;
    volumeTextures.push_back(VolumeStruct(
        volumePort_.getData(),
        &volUnit,
        "volumeStruct_")
    );

    // bind transfer function
    TextureUnit transferUnit;
    transferUnit.activate();
    if (transferFunc_.get())
        transferFunc_.get()->bind();

    // initialize shader
    raycastPrg_->activate();

    // set common uniforms used by all shaders
    tgt::Camera cam = camera_.get();
    setGlobalShaderParameters(raycastPrg_, &cam);
    // bind the volumes and pass the necessary information to the shader
    bindVolumes(raycastPrg_, volumeTextures, &cam, lightPosition_.get());

    // pass the remaining uniforms to the shader
    raycastPrg_->setUniform("entryPoints_", entryUnit.getUnitNumber());
    raycastPrg_->setUniform("entryPointsDepth_", entryDepthUnit.getUnitNumber());
    entryPort_.setTextureParameters(raycastPrg_, "entryParameters_");
    raycastPrg_->setUniform("exitPoints_", exitUnit.getUnitNumber());
    raycastPrg_->setUniform("exitPointsDepth_", exitDepthUnit.getUnitNumber());
    exitPort_.setTextureParameters(raycastPrg_, "exitParameters_");
    transferFunc_.get()->setUniform(raycastPrg_, "transferFunc_", transferUnit.getUnitNumber());
    raycastPrg_->setUniform("applyColorModulation_", applyColorModulation_.get());

    renderQuad();

    raycastPrg_->deactivate();
    TextureUnit::setZeroUnit();

    outport_.deactivateTarget();
    LGL_ERROR;
}
예제 #17
0
void HalfAngleSlicer::process() {

    // compile program if needed
    if (getInvalidationLevel() >= Processor::INVALID_PROGRAM)
        compile();
    LGL_ERROR;

    lightport_.activateTarget();
    glClearColor(1.0, 1.0, 1.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    lightport_.deactivateTarget();
    outport_.activateTarget();
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    outport_.deactivateTarget();

    // bind transfer function
    TextureUnit transferUnit;
    transferUnit.activate();
    if (transferFunc_.get())
        transferFunc_.get()->bind();

    transferFunc_.setVolumeHandle(volumeInport_.getData());

    // vector containing the volumes to bind; is passed to bindVolumes()
    std::vector<VolumeStruct> volumeTextures;

    // add main volume
    TextureUnit volUnit;
    volumeTextures.push_back(VolumeStruct(
        volumeInport_.getData(),
        &volUnit,
        "volume_","volumeStruct_")
    );

    // initialize slicing shader
    tgt::Shader* slicingPrg = shaderProp_.getShader();
    slicingPrg->activate();

    // fragment shader uniforms
    transferFunc_.get()->setUniform(slicingPrg, "transferFunc_", "transferFuncTex_", transferUnit.getUnitNumber());

    // set common uniforms used by all shaders
    tgt::Camera cam = eyeCamera_.get();
    // bind the volumes and pass the necessary information to the shader
    bindVolumes(slicingPrg, volumeTextures, &cam, lightPosition_.get());

    setupUniforms(slicingPrg);

    // correct slice distance for this technique
    sliceDistance_ *= 0.5f*std::sqrt(1.f + dot(eyeCamera_.get().getLook(), lightCamera_.getLook()));
    slicingPrg->setUniform("dPlaneIncr_", sliceDistance_);

    glDisable(GL_DEPTH_TEST);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    tgt::loadMatrix(eyeCamera_.get().getProjectionMatrix(outport_.getSize()));

    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    tgt::loadMatrix(eyeCamera_.get().getViewMatrix());

    slicingPrg->activate();
    glEnable(GL_BLEND);

    unsigned int numSlices = static_cast<unsigned int>(maxLength_ / sliceDistance_);

    TextureUnit lightBufferUnit;

    slicingPrg->setUniform("lightBuf_", lightBufferUnit.getUnitNumber());
    slicingPrg->setUniform("lightMat_", lightCamera_.getViewMatrix());
    lightport_.setTextureParameters(slicingPrg, "lightBufParameters_");

    for (unsigned int curSlice = 0; curSlice < numSlices; curSlice++) {
        outport_.activateTarget();

        // FIRST PASS
        if(invert_)
            glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
        else
            glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);

        lightBufferUnit.activate();
        glEnable(GL_TEXTURE_2D);
        lightport_.bindColorTexture();

        tgt::Camera cam = eyeCamera_.get();
        setGlobalShaderParameters(slicingPrg, &cam);
        slicingPrg->setUniform("secondPass_", false);

        glBegin(GL_POLYGON);
            for (unsigned int curPoint=0; curPoint<6; curPoint++)
                glVertex2i(curPoint, curSlice);
        glEnd();

        outport_.deactivateTarget();

        // SECOND PASS
        lightport_.activateTarget();

        glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
        glPushMatrix();
        tgt::loadMatrix(lightCamera_.getViewMatrix());
        setGlobalShaderParameters(slicingPrg, &lightCamera_);
        slicingPrg->setUniform("secondPass_", true);

        glBegin(GL_POLYGON);
            for (unsigned int curPoint=0; curPoint<6; curPoint++)
                glVertex2i(curPoint, curSlice);
        glEnd();
        glPopMatrix();

        lightport_.deactivateTarget();
    }

    glBlendFunc(GL_ONE, GL_ZERO);
    glDisable(GL_BLEND);
    glEnable(GL_DEPTH_TEST);

    glPopMatrix();
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);

    slicingPrg->deactivate();

    glClearColor(0.0, 0.0, 0.0, 0.0);
    TextureUnit::setZeroUnit();
    LGL_ERROR;
}
예제 #18
0
void CurvatureRaycaster::process() {
    // compile program if needed
    if (getInvalidationLevel() >= Processor::INVALID_PROGRAM)
        compile();
    LGL_ERROR;

    // bind transfer function
    TextureUnit transferUnit;
    transferUnit.activate();
    if (transferFunc_.get())
        transferFunc_.get()->bind();

    portGroup_.activateTargets();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    LGL_ERROR;

    transferFunc_.setVolumeHandle(volumeInport_.getData());

    TextureUnit entryUnit, entryDepthUnit, exitUnit, exitDepthUnit;
    // bind entry params
    entryPort_.bindTextures(entryUnit.getEnum(), entryDepthUnit.getEnum());
    LGL_ERROR;

    // bind exit params
    exitPort_.bindTextures(exitUnit.getEnum(), exitDepthUnit.getEnum());
    LGL_ERROR;

    // vector containing the volumes to bind; is passed to bindVolumes()
    std::vector<VolumeStruct> volumeTextures;

    // add main volume
    TextureUnit volUnit, volUnit2;
    volumeTextures.push_back(VolumeStruct(
        volumeInport_.getData(),
        &volUnit,
        "volumeStruct_")
        );
    volumeTextures.push_back(VolumeStruct(
        gradientInport_.getData(),
        &volUnit2,
        "gradientVolumeParameters_")
        );

    // segmentation volume
    //VolumeHandle* volumeSeg = volumeInport_.getData()->getRelatedVolumeHandle(Modality::MODALITY_SEGMENTATION);
    VolumeHandle* volumeSeg = 0;

    bool usingSegmentation = (maskingMode_.get() == "Segmentation") && volumeSeg;
    TextureUnit segUnit;
    if (usingSegmentation) {
        // Important to set the correct texture unit before getRepresentation<VolumeGL>() is called or
        // glTexParameter() might influence the wrong texture.
        segUnit.activate();

        volumeTextures.push_back(VolumeStruct(volumeSeg,
                                              &segUnit,
                                              "segmentationParameters_"));

        // set texture filtering for this texture unit
        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    }

    // initialize shader
    raycastPrg_->activate();

    // set common uniforms used by all shaders
    tgt::Camera cam = camera_.get();
    setGlobalShaderParameters(raycastPrg_, &cam);
    // bind the volumes and pass the necessary information to the shader
    bindVolumes(raycastPrg_, volumeTextures, &cam, lightPosition_.get());

    // pass the remaining uniforms to the shader
    raycastPrg_->setUniform("entryPoints_", entryUnit.getUnitNumber());
    raycastPrg_->setUniform("entryPointsDepth_", entryDepthUnit.getUnitNumber());
    entryPort_.setTextureParameters(raycastPrg_, "entryParameters_");
    raycastPrg_->setUniform("exitPoints_", exitUnit.getUnitNumber());
    raycastPrg_->setUniform("exitPointsDepth_", exitDepthUnit.getUnitNumber());
    exitPort_.setTextureParameters(raycastPrg_, "exitParameters_");

    if (compositingMode_.get() ==  "iso" ||
        compositingMode1_.get() == "iso" ||
        compositingMode2_.get() == "iso")
        raycastPrg_->setUniform("isoValue_", isoValue_.get());

    if (classificationMode_.get() == "transfer-function")
        transferFunc_.get()->setUniform(raycastPrg_, "transferFunc_", transferUnit.getUnitNumber());

    // curvature uniforms
    GLint curvatureType = -1;
    if (curvatureType_.get() == "first") curvatureType = 0;
    else if (curvatureType_.get() == "second") curvatureType = 1;
    else if (curvatureType_.get() == "mean") curvatureType = 2;
    else if (curvatureType_.get() == "gauss") curvatureType = 3;
    raycastPrg_->setUniform("curvatureType_", curvatureType);
    raycastPrg_->setUniform("curvatureFactor_", curvatureFactor_.get());
    raycastPrg_->setUniform("silhouetteWidth_", silhouetteWidth_.get());
    raycastPrg_->setUniform("minGradientLength_", minGradientLength_.get());

    LGL_ERROR;

    renderQuad();

    raycastPrg_->deactivate();

    if (usingSegmentation) {
        // restore default texture filtering mode
        segUnit.activate();
        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    }

    LGL_ERROR;
}
예제 #19
0
void SingleVolumeSlicer::process() {

    // compile program if needed
    if (getInvalidationLevel() >= Processor::INVALID_PROGRAM)
        compile();
    LGL_ERROR;

    // bind transfer function
    TextureUnit transferUnit;
    transferUnit.activate();
    if (transferFunc_.get())
        transferFunc_.get()->bind();

    transferFunc_.setVolumeHandle(volumeInport_.getData());

    // vector containing the volumes to bind; is passed to bindVolumes()
    std::vector<VolumeStruct> volumeTextures;

    // add main volume
    TextureUnit volUnit;
    volumeTextures.push_back(VolumeStruct(
        volumeInport_.getData(),
        &volUnit,
        "volume_","volumeStruct_")
    );

    // initialize slicing shader
    tgt::Shader* slicingPrg = shaderProp_.getShader();
    slicingPrg->activate();
    // fragment shader uniforms
    transferFunc_.get()->setUniform(slicingPrg, "transferFunc_", "transferFuncTex_", transferUnit.getUnitNumber());

    setupUniforms(slicingPrg);

    // set common uniforms used by all shaders
    tgt::Camera cam = camera_.get();
    setGlobalShaderParameters(slicingPrg, &cam);
    // bind the volumes and pass the necessary information to the shader
    bindVolumes(slicingPrg, volumeTextures, &cam, lightPosition_.get());

    glDisable(GL_DEPTH_TEST);

    MatStack.matrixMode(tgt::MatrixStack::PROJECTION);
    MatStack.pushMatrix();
    MatStack.loadMatrix(camera_.get().getProjectionMatrix(outport_.getSize()));

    MatStack.matrixMode(tgt::MatrixStack::MODELVIEW);
    MatStack.pushMatrix();
    MatStack.loadMatrix(camera_.get().getViewMatrix());

    unsigned int numSlices = static_cast<unsigned int>(maxLength_ / sliceDistance_);

    slicingPrg->activate();
    outport_.activateTarget();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);

    for (unsigned int curSlice=0; curSlice<numSlices; curSlice++) {
        glBegin(GL_POLYGON);
            for (unsigned int curPoint=0; curPoint<6; curPoint++)
                glVertex2i(curPoint, curSlice);
        glEnd();
    }

    glBlendFunc(GL_ONE, GL_ZERO);
    glDisable(GL_BLEND);
    glEnable(GL_DEPTH_TEST);

    MatStack.popMatrix();
    MatStack.matrixMode(tgt::MatrixStack::PROJECTION);
    MatStack.popMatrix();
    MatStack.matrixMode(tgt::MatrixStack::MODELVIEW);

    slicingPrg->deactivate();
    outport_.deactivateTarget();
    TextureUnit::setZeroUnit();

    LGL_ERROR;
}
예제 #20
0
void TransFuncOverlay::process() {
    #ifndef VRN_MODULE_FONTRENDERING
    LWARNING("Empty output, enable module 'fontrendering'.");
    return;
    #endif

    tgtAssert(outport_.isReady(), "Outport not ready");
    tgtAssert(imageInport_.isReady(), "Inport not ready");
    tgtAssert(program_ && copyShader_, "Shader missing");

    if(dynamic_cast<TransFunc1DKeys*>(transferFunc_.get()) == 0){
        LWARNING("No transfer function of class TransFuncIntensity is given!!!");
        return;
    }
    TransFunc1DKeys* tfi = dynamic_cast<TransFunc1DKeys*>(transferFunc_.get());

    //render overlay
    privatePort_.activateTarget();
        glPushAttrib(GL_ALL_ATTRIB_BITS);
            glClearColor(fontColor_.get().r,fontColor_.get().g,fontColor_.get().b,0.0f);
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            //render the transfer function texture
            const tgt::Texture* tfTex = 0;
            if(renderPreIntegrationTable_.get())
                tfTex = tfi->getPreIntegrationTable(1.0f / (41.0f * 2.0f))->getTexture();
            else
                tfTex = tfi->getTexture();

            tgtAssert(tfTex, "No transfer function texture");
            tfTex->bind();
            glColor4f(1.f,1.f,1.f,1.f);
            glDisable(GL_DEPTH_TEST);
                glBegin(GL_QUADS);
                    glVertex2f(-0.8f,-0.9f);
                    glVertex2f(-0.5f,-0.9f);
                    glVertex2f(-0.5f,0.7f);
                    glVertex2f(-0.8f,0.7f);
                glEnd();
                glColor4f(0.8f,0.8f,0.8f,1.f);
                glBegin(GL_QUADS);
                    glVertex2f(-0.8f,-0.9f);
                    glVertex2f(-0.65f,-0.9f);
                    glVertex2f(-0.65f,-0.58f);
                    glVertex2f(-0.8f,-0.58f);

                    glVertex2f(-0.65f,-0.58f);
                    glVertex2f(-0.5f,-0.58f);
                    glVertex2f(-0.5f,-0.26f);
                    glVertex2f(-0.65f,-0.26f);

                    glVertex2f(-0.8f,-0.26f);
                    glVertex2f(-0.65f,-0.26f);
                    glVertex2f(-0.65f,0.06f);
                    glVertex2f(-0.8f,0.06f);

                    glVertex2f(-0.65f,0.06f);
                    glVertex2f(-0.5f,0.06f);
                    glVertex2f(-0.5f,0.38f);
                    glVertex2f(-0.65f,0.38f);

                    glVertex2f(-0.8f,0.38f);
                    glVertex2f(-0.65f,0.38f);
                    glVertex2f(-0.65f,0.7f);
                    glVertex2f(-0.8f,0.7f);
                glEnd();
                glColor4f(1.f,1.f,1.f,1.f);

                if(renderPreIntegrationTable_.get())
                    glEnable(GL_TEXTURE_2D);
                else
                    glEnable(GL_TEXTURE_1D);
                
                glEnable(GL_BLEND);
                    glBlendColor(0.0f,0.0f,0.0f,overlayOpacity_.get());
                    glBlendFuncSeparate(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA,GL_ZERO,GL_CONSTANT_ALPHA);
                    glBegin(GL_QUADS);
                    if(renderPreIntegrationTable_.get()) {
                        glTexCoord2f(0.f, 0.f); glVertex2f(-0.8f,-0.9f);
                        glTexCoord2f(1.f, 0.f); glVertex2f(-0.5f,-0.9f);
                        glTexCoord2f(1.f, 1.f); glVertex2f(-0.5f,0.7f);
                        glTexCoord2f(0.f, 1.f); glVertex2f(-0.8f,0.7f);
                    }
                    else {
                        glTexCoord1f(0.f); glVertex2f(-0.8f,-0.9f);
                        glTexCoord1f(0.f); glVertex2f(-0.5f,-0.9f);
                        glTexCoord1f(1.f); glVertex2f(-0.5f,0.7f);
                        glTexCoord1f(1.f); glVertex2f(-0.8f,0.7f);
                    }
                    glEnd();
                glDisable(GL_BLEND);
                glDisable(GL_TEXTURE_1D);
            glEnable(GL_DEPTH_TEST);
            //render fonts
            glPushMatrix();
                glTranslatef(-1.f,-1.f,0.f);
                float scaleFactorX = 2.0f / (float)privatePort_.getSize().x;
                float scaleFactorY = 2.0f / (float)privatePort_.getSize().y;
                glScalef(scaleFactorX, scaleFactorY, 1.f);
                glColor4f(fontColor_.get().r,fontColor_.get().g,fontColor_.get().b,fontColor_.get().a*overlayOpacity_.get());
                fontProp_.get()->setSize(privatePort_.getSize().y/12);
                fontProp_.get()->setVerticalTextAlignment(tgt::Font::Middle);
                fontProp_.get()->setFontType(tgt::Font::BitmapFont);
                fontProp_.get()->setLineWidth(privatePort_.getSize().x*0.35f);
                fontProp_.get()->setTextAlignment(tgt::Font::Center);
                fontProp_.get()->render(tgt::vec3(0,privatePort_.getSize().y*0.925f,0), tfUnit_.get());
                fontProp_.get()->setLineWidth((float)privatePort_.getSize().x);
                fontProp_.get()->setTextAlignment(tgt::Font::Left);
                std::stringstream strstr;
                strstr << tfi->getDomain(0).x * scalingProp_.get();
                fontProp_.get()->render(tgt::vec3(privatePort_.getSize().x*0.3f,privatePort_.getSize().y*0.05f,0), strstr.str());
                strstr.clear();
                strstr.str("");
                strstr << (tfi->getDomain(0).x+((tfi->getDomain(0).y-tfi->getDomain(0).x)/2)) * scalingProp_.get();
                fontProp_.get()->render(tgt::vec3(privatePort_.getSize().x*0.3f,privatePort_.getSize().y*0.45f,0), strstr.str());
                strstr.clear();
                strstr.str("");
                strstr << tfi->getDomain(0).y * scalingProp_.get();
                fontProp_.get()->render(tgt::vec3(privatePort_.getSize().x*0.3f,privatePort_.getSize().y*0.85f,0), strstr.str());
            glPopMatrix();
        glPopAttrib();
         // render border around overlay
        if (renderBorder_.get()) {
            glPushAttrib(GL_ALL_ATTRIB_BITS);
                glColor4f(borderColor_.get().r,borderColor_.get().g,borderColor_.get().b,borderColor_.get().a*overlayOpacity_.get());
                glLineWidth(borderWidth_.get());
                glDepthFunc(GL_ALWAYS);
                glBegin(GL_LINE_STRIP);
                    glVertex2f(-0.8f,-0.9f);
                    glVertex2f(-0.5f,-0.9f);
                    glVertex2f(-0.5f,0.7f);
                    glVertex2f(-0.8f,0.7f);
                    glVertex2f(-0.8f,-0.9f);
                glEnd();
            glPopAttrib();
        }
        LGL_ERROR;
    privatePort_.deactivateTarget();

    //same code as in ImageOverlay
    //          |
    //          v
    outport_.activateTarget();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // bind input image to tex unit
    TextureUnit imageUnit, imageUnitDepth;
    imageInport_.bindTextures(imageUnit.getEnum(), imageUnitDepth.getEnum());

    // 1. copy input image to outport
    copyShader_->activate();
    setGlobalShaderParameters(copyShader_);
    imageInport_.setTextureParameters(copyShader_, "texParams_");
    copyShader_->setUniform("colorTex_", imageUnit.getUnitNumber());
    copyShader_->setUniform("depthTex_", imageUnitDepth.getUnitNumber());
    renderQuad();
    copyShader_->deactivate();
    LGL_ERROR;

    // 2. render overlay over copied input image (using compositor shader)
    // check, if overlay dims are greater zero
    bool dimensionsValid = ( (usePixelCoordinates_.getValue()  && tgt::hand(tgt::greaterThan(overlayDimensions_.get(), tgt::ivec2(0)))) ||
                             (!usePixelCoordinates_.getValue() && tgt::hand(tgt::greaterThan(overlayDimensionsRelative_.get(), tgt::vec2(0.f)))) );
    if (renderOverlay_.get() && /*overlayInport_.isReady() &&*/ dimensionsValid) {
        // bind overlay to tex unit
        TextureUnit overlayUnit;
        tgt::Texture* overlayTex = privatePort_.getColorTexture();//overlayInport_.getColorTexture();
        tgtAssert(overlayTex, "No overlay texture");
        overlayUnit.activate();
        overlayTex->bind();

        program_->activate();
        setGlobalShaderParameters(program_);

        // image texture parameters
        imageInport_.setTextureParameters(program_, "textureParameters0_");
        program_->setUniform("colorTex0_", imageUnit.getUnitNumber());
        program_->setUniform("depthTex0_", imageUnitDepth.getUnitNumber());
        program_->setUniform("colorTex1_", overlayUnit.getUnitNumber());
        //program_->setUniform("weightingFactor_", 1.f-overlayOpacity_.get());

        // determine overlay dimensions and bottom-left in float pixel coords
        tgt::vec2 outportDim = tgt::vec2(outport_.getSize());
        tgt::vec2 overlayDim, overlayBL;
        if (usePixelCoordinates_.getValue()) {
            overlayDim = tgt::vec2(overlayDimensions_.get());
            overlayBL = tgt::vec2(overlayBottomLeft_.get());
        }
        else {
            overlayDim = overlayDimensionsRelative_.get() * outportDim;
            overlayBL = overlayBottomLeftRelative_.get() * outportDim;
        }

        // overlay texture matrix mapping from normalized frag coords (outport) to overlay tex coords
        tgt::mat4 overlayTexCoordMatrix = tgt::mat4::identity;
        overlayTexCoordMatrix *= tgt::mat4::createScale(tgt::vec3(outportDim / overlayDim, 0.f));
        overlayTexCoordMatrix *= tgt::mat4::createTranslation(-tgt::vec3(overlayBL / outportDim, 1.f));

        // overlay texture parameters
        bool oldIgnoreError = program_->getIgnoreUniformLocationError();
        program_->setIgnoreUniformLocationError(true);
        program_->setUniform("textureParameters1_.dimensions_",    overlayDim);
        program_->setUniform("textureParameters1_.dimensionsRCP_", tgt::vec2(1.f) / overlayDim);
        program_->setUniform("textureParameters1_.matrix_", overlayTexCoordMatrix);
        program_->setIgnoreUniformLocationError(oldIgnoreError);
        LGL_ERROR;

        // render overlay at specified position and size
        tgt::vec2 bl = 2.f*overlayBL / outportDim - 1.f;
        tgt::vec2 dim = 2.f*overlayDim / outportDim;
        glDepthFunc(GL_ALWAYS);
        glBegin(GL_QUADS);
            glVertex2f(bl.x, bl.y);
            glVertex2f(bl.x + dim.x, bl.y);
            glVertex2f(bl.x + dim.x, bl.y + dim.y);
            glVertex2f(bl.x, bl.y + dim.y);
        glEnd();
        glDepthFunc(GL_LESS);
        program_->deactivate();
        LGL_ERROR;
    }

    outport_.deactivateTarget();
    TextureUnit::setZeroUnit();
    LGL_ERROR;
}
예제 #21
0
void LightVolumeGL::process() {
    bool lightColorChanged = false;

    if (lightSource_.isChanged()) {
        lightColorChanged = lightSourceChanged();
    }

    bool reattach = false;

    if (internalVolumesInvalid_ || lightColorChanged || inport_.isChanged()) {
        reattach = volumeChanged(lightColorChanged);
    }

    VolumeGL* outVolumeGL = volume_->getEditableRepresentation<VolumeGL>();
    TextureUnit volUnit;
    const VolumeGL* inVolumeGL = inport_.getData()->getRepresentation<VolumeGL>();
    inVolumeGL->bindTexture(volUnit.getEnum());
    TextureUnit transFuncUnit;
    const Layer* tfLayer = transferFunction_.get().getData();
    const LayerGL* transferFunctionGL = tfLayer->getRepresentation<LayerGL>();
    transferFunctionGL->bindTexture(transFuncUnit.getEnum());
    TextureUnit lightVolUnit[2];
    propParams_[0].vol->bindTexture(lightVolUnit[0].getEnum());
    propParams_[1].vol->bindTexture(lightVolUnit[1].getEnum());
    propagationShader_.activate();
    propagationShader_.setUniform("volume_", volUnit.getUnitNumber());
    utilgl::setShaderUniforms(propagationShader_, *inport_.getData(), "volumeParameters_");
    propagationShader_.setUniform("transferFunc_", transFuncUnit.getUnitNumber());
    propagationShader_.setUniform("lightVolumeParameters_.dimensions", volumeDimOutF_);
    propagationShader_.setUniform("lightVolumeParameters_.reciprocalDimensions", volumeDimOutFRCP_);

    BufferObjectArray* rectArray = utilgl::enableImagePlaneRect();

    //Perform propagation passes
    for (int i=0; i<2; ++i) {
        propParams_[i].fbo->activate();
        glViewport(0, 0, static_cast<GLsizei>(volumeDimOut_.x), static_cast<GLsizei>(volumeDimOut_.y));

        if (reattach)
            propParams_[i].fbo->attachColorTexture(propParams_[i].vol->getTexture().get(), 0);

        propagationShader_.setUniform("lightVolume_", lightVolUnit[i].getUnitNumber());
        propagationShader_.setUniform("permutationMatrix_", propParams_[i].axisPermutation);

        if (lightSource_.getData()->getLightSourceType() == LightSourceType::LIGHT_POINT) {
            propagationShader_.setUniform("lightPos_", lightPos_);
            propagationShader_.setUniform("permutedLightMatrix_", propParams_[i].axisPermutationLight);
        }
        else {
            propagationShader_.setUniform("permutedLightDirection_", propParams_[i].permutedLightDirection);
        }

        for (unsigned int z=0; z<volumeDimOut_.z; ++z) {
            glFramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_3D, propParams_[i].vol->getTexture()->getID(), 0, z);
            propagationShader_.setUniform("sliceNum_", static_cast<GLint>(z));
            glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
            glFlush();
        }

        propParams_[i].fbo->deactivate();
    }

    utilgl::disableImagePlaneRect(rectArray);

    propagationShader_.deactivate();
    mergeShader_.activate();
    mergeShader_.setUniform("lightVolume_", lightVolUnit[0].getUnitNumber());
    mergeShader_.setUniform("lightVolumeSec_", lightVolUnit[1].getUnitNumber());
    mergeShader_.setUniform("lightVolumeParameters_.dimensions", volumeDimOutF_);
    mergeShader_.setUniform("lightVolumeParameters_.reciprocalDimensions", volumeDimOutFRCP_);
    mergeShader_.setUniform("permMatInv_", propParams_[0].axisPermutationINV);
    mergeShader_.setUniform("permMatInvSec_", propParams_[1].axisPermutationINV);
    mergeShader_.setUniform("blendingFactor_", blendingFactor_);
    //Perform merge pass
    mergeFBO_->activate();
    glViewport(0, 0, static_cast<GLsizei>(volumeDimOut_.x), static_cast<GLsizei>(volumeDimOut_.y));

    if (reattach)
        mergeFBO_->attachColorTexture(outVolumeGL->getTexture().get(), 0);

    utilgl::multiDrawImagePlaneRect(static_cast<int>(volumeDimOut_.z));
    mergeShader_.deactivate();
    mergeFBO_->deactivate();
}
예제 #22
0
void OcclusionSlicer::process() {

    // compile program if needed
    if (getInvalidationLevel() >= Processor::INVALID_PROGRAM)
        compile();
    LGL_ERROR;

    occlusionbuffer0_.activateTarget();
    glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    occlusionbuffer1_.activateTarget();
    glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    outport_.activateTarget();
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    LGL_ERROR;

    // bind transfer function
    TextureUnit transferUnit;
    transferUnit.activate();
    if (transferFunc_.get())
        transferFunc_.get()->bind();

    transferFunc_.setVolumeHandle(volumeInport_.getData());

    // vector containing the volumes to bind; is passed to bindVolumes()
    std::vector<VolumeStruct> volumeTextures;

    // add main volume
    TextureUnit volUnit;
    volumeTextures.push_back(VolumeStruct(
        volumeInport_.getData(),
        &volUnit,
        "volume_","volumeStruct_")
    );

    // initialize slicing shader
    tgt::Shader* slicingPrg = shaderProp_.getShader();
    slicingPrg->activate();

    // fragment shader uniforms
    TextureUnit occlusionUnit;
    transferFunc_.get()->setUniform(slicingPrg, "transferFunc_", "transferFuncTex_", transferUnit.getUnitNumber());
    slicingPrg->setUniform("occlusion_", occlusionUnit.getUnitNumber());
    occlusionbuffer1_.setTextureParameters(slicingPrg, "occlusionParams_");

    //clipping uniforms
    setupUniforms(slicingPrg);

    // set common uniforms used by all shaders
    tgt::Camera cam = camera_.get();
    setGlobalShaderParameters(slicingPrg, &cam);

    slicingPrg->setUniform("sigma_", sigma_.get());
    slicingPrg->setUniform("radius_", radius_.get());
    slicingPrg->setUniform("lightPos_", lightPosition_.get().xyz());

    // bind the volumes and pass the necessary information to the shader
    bindVolumes(slicingPrg, volumeTextures, &cam, lightPosition_.get());

    glDisable(GL_DEPTH_TEST);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    tgt::loadMatrix(camera_.get().getProjectionMatrix(outport_.getSize()));

    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    tgt::loadMatrix(camera_.get().getViewMatrix());

    unsigned int numSlices = static_cast<unsigned int>(maxLength_ / sliceDistance_);

    slicingPrg->activate();

    for (unsigned int curSlice=0; curSlice<numSlices; curSlice++) {
        // first pass
        slicingPrg->setUniform("secondPass_", false);
        outport_.activateTarget();
        glEnable(GL_BLEND);
        glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);

        occlusionbuffer0_.bindColorTexture(occlusionUnit.getEnum());

        glBegin(GL_POLYGON);
        for (unsigned int curPoint=0; curPoint<6; curPoint++)
            glVertex2i(curPoint, curSlice);
        glEnd();
        glDisable(GL_BLEND);

        outport_.deactivateTarget();

        // second pass
        slicingPrg->setUniform("secondPass_", true);

        occlusionbuffer1_.activateTarget();

        slicingPrg->setUniform("blurDirection_", tgt::vec2(1.f, 0.f));
        glBegin(GL_POLYGON);
        for (unsigned int curPoint=0; curPoint<6; curPoint++)
            glVertex2i(curPoint, curSlice);
        glEnd();

        occlusionbuffer1_.deactivateTarget();
        occlusionbuffer0_.activateTarget();
        occlusionbuffer1_.bindColorTexture(occlusionUnit.getEnum());

        slicingPrg->setUniform("blurDirection_", tgt::vec2(0.f, 1.f));
        glBegin(GL_POLYGON);
        for (unsigned int curPoint=0; curPoint<6; curPoint++)
            glVertex2i(curPoint, curSlice);
        glEnd();

        occlusionbuffer0_.deactivateTarget();
    }

    slicingPrg->deactivate();

    glEnable(GL_DEPTH_TEST);

    glPopMatrix();
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);

    glBlendFunc(GL_ONE, GL_ZERO);
    TextureUnit::setZeroUnit();
    LGL_ERROR;
}