Пример #1
0
void SSAOPass::setupBlurCamera()
{
    _blurCamera->setClearColor(osg::Vec4());
    _blurCamera->setClearMask(GL_DEPTH_BUFFER_BIT); // we cannot clear color buffer
    
    _blurCamera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
    _blurCamera->setRenderOrder(osg::Camera::PRE_RENDER);
    
    _blurCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
    _blurCamera->setProjectionMatrix(osg::Matrix::ortho2D(0, 1, 0, 1));
    _blurCamera->setViewMatrix(osg::Matrix::identity());
    _blurCamera->setViewport(0, 0, _screenWidth, _screenHeight);
    osg::ref_ptr<osg::TextureRectangle> blurTexOut = getOutputTexture(_out_ssao_tex_id);
    _blurCamera->attach(osg::Camera::COLOR_BUFFER0, blurTexOut);
    
    _blurCamera->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
    _blurCamera->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
    
    osg::ref_ptr<osg::Group> yDir = createTexturedQuad();
    osg::ref_ptr<osg::Group> xDir = createTexturedQuad();
    
    // create two screen Quad for two blurring direction
    configBlurQuadStateSet(yDir, 'y', blurTexOut);
    configBlurQuadStateSet(xDir, 'x', blurTexOut);
    _blurCamera->addChild(yDir);
    _blurCamera->addChild(xDir);
    
    _rootGroup->addChild(_blurCamera);
    
}
Пример #2
0
AggregatePass::AggregatePass(osg::TextureRectangle *diff_tex0,
							 osg::TextureRectangle *diff_tex1,
							 osg::TextureRectangle *diff_tex2,
							 osg::TextureRectangle *diff_tex3,
							 osg::TextureRectangle *agg_tex_in,
							 osg::TextureRectangle *agg_tex_out,
							 int width, int height,
							 int start_disparity, int window_size):
    _TextureWidth(width),
    _TextureHeight(height),
    _StartDisparity(start_disparity),
    _WindowSize(window_size)
{
    _RootGroup = new osg::Group;

    _InTextureDifference[0] = diff_tex0;
    _InTextureDifference[1] = diff_tex1;
    _InTextureDifference[2] = diff_tex2;
    _InTextureDifference[3] = diff_tex3;

    _InTextureAggregate = agg_tex_in;
    _OutTextureAggregate = agg_tex_out;

    _OutTexture = _OutTextureAggregate;

    _Camera = new osg::Camera;
    setupCamera();
    _Camera->addChild(createTexturedQuad().get());

    _RootGroup->addChild(_Camera.get());

    setShader("shaders/stereomatch_aggregate.frag");

}
Пример #3
0
void SSAOPass::configRTTCamera()
{
    _out_ssao_tex_id = addOutTexture();
    _stateSet = _rttCamera->getOrCreateStateSet();
    _screenQuad = createTexturedQuad();
    _rttCamera->addChild(_screenQuad);
    _rttCamera->setClearColor(osg::Vec4(0, 0, 0, 1));
    _rttCamera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    _rttCamera->attach(osg::Camera::COLOR_BUFFER0, getOutputTexture(_out_ssao_tex_id));
    
    _rootGroup->addChild(_rttCamera);
}
Пример #4
0
StereoMultipass::StereoMultipass(osg::TextureRectangle *left_tex,
								 osg::TextureRectangle *right_tex,
								 int width, int height,
								 int min_disparity, int max_disparity, int window_size) :
    _TextureWidth(width),
    _TextureHeight(height)
{
    _RootGroup = new osg::Group;

    createOutputTextures();

    _Camera = new osg::Camera;
    setupCamera();
    _Camera->addChild(createTexturedQuad().get());

    _RootGroup->addChild(_Camera.get());

    setShader("shaders/stereomatch_clear.frag");

    flip=1;
    flop=0;
	// we can do 16 differences in one pass,
	// but we must ping-pong the aggregate textures between passes
	// add passes until we cover the disparity range
	for (int i=min_disparity; i<=max_disparity; i+=16) {
		SubtractPass *subp = new SubtractPass(left_tex, right_tex,
											  width, height,
											  i);
		AggregatePass *aggp = new AggregatePass(subp->getOutputTexture(0).get(),
												subp->getOutputTexture(1).get(),
												subp->getOutputTexture(2).get(),
												subp->getOutputTexture(3).get(),
												_OutTexture[flip].get(),
												_OutTexture[flop].get(),
												width, height,
												i, window_size);

		_RootGroup->addChild(subp->getRoot().get());
		_RootGroup->addChild(aggp->getRoot().get());
		flip = flip ? 0 : 1;
		flop = flop ? 0 : 1;
    }
    // add select pass
    _SelectPass = new SelectPass(_OutTexture[flip].get(),
								 width, height,
								 min_disparity, max_disparity);
    _RootGroup->addChild(_SelectPass->getRoot().get());
}
Пример #5
0
SelectPass::SelectPass(osg::TextureRectangle *in_tex,
					   int width, int height,
					   int min_disparity, int max_disparity) :
    _TextureWidth(width),
    _TextureHeight(height),
    _MinDisparity(min_disparity),
    _MaxDisparity(max_disparity)
{
    _RootGroup = new osg::Group;
    _InTexture = in_tex;

    createOutputTextures();

    _Camera = new osg::Camera;
    setupCamera();
    _Camera->addChild(createTexturedQuad().get());

    _RootGroup->addChild(_Camera.get());

    setShader("shaders/stereomatch_select.frag");
}
Пример #6
0
SubtractPass::SubtractPass(osg::TextureRectangle *left_tex,
						   osg::TextureRectangle *right_tex,
						   int width, int height,
						   int start_disparity) :
    _TextureWidth(width),
    _TextureHeight(height),
    _StartDisparity(start_disparity)
{
    _RootGroup = new osg::Group;
    _InTextureLeft = left_tex;
    _InTextureRight = right_tex;

    createOutputTextures();

    _Camera = new osg::Camera;
    setupCamera();
    _Camera->addChild(createTexturedQuad().get());

    _RootGroup->addChild(_Camera.get());

    setShader("shaders/stereomatch_subtract.frag");
}
Пример #7
0
    void GlobalMap::requestOverlayTextureUpdate(int x, int y, int width, int height, osg::ref_ptr<osg::Texture2D> texture, bool clear, bool cpuCopy,
                                                float srcLeft, float srcTop, float srcRight, float srcBottom)
    {
        osg::ref_ptr<osg::Camera> camera (new osg::Camera);
        camera->setNodeMask(Mask_RenderToTexture);
        camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
        camera->setViewMatrix(osg::Matrix::identity());
        camera->setProjectionMatrix(osg::Matrix::identity());
        camera->setProjectionResizePolicy(osg::Camera::FIXED);
        camera->setRenderOrder(osg::Camera::PRE_RENDER);
        y = mHeight - y - height; // convert top-left origin to bottom-left
        camera->setViewport(x, y, width, height);

        if (clear)
        {
            camera->setClearMask(GL_COLOR_BUFFER_BIT);
            camera->setClearColor(osg::Vec4(0,0,0,0));
        }
        else
            camera->setClearMask(GL_NONE);

        camera->setUpdateCallback(new CameraUpdateGlobalCallback(this));

        camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT, osg::Camera::PIXEL_BUFFER_RTT);
        camera->attach(osg::Camera::COLOR_BUFFER, mOverlayTexture);

        // no need for a depth buffer
        camera->setImplicitBufferAttachmentMask(osg::DisplaySettings::IMPLICIT_COLOR_BUFFER_ATTACHMENT);

        if (cpuCopy)
        {
            // Attach an image to copy the render back to the CPU when finished
            osg::ref_ptr<osg::Image> image (new osg::Image);
            image->setPixelFormat(mOverlayImage->getPixelFormat());
            image->setDataType(mOverlayImage->getDataType());
            camera->attach(osg::Camera::COLOR_BUFFER, image);

            ImageDest imageDest;
            imageDest.mImage = image;
            imageDest.mX = x;
            imageDest.mY = y;
            mPendingImageDest.push_back(imageDest);
        }

        // Create a quad rendering the updated texture
        if (texture)
        {
            osg::ref_ptr<osg::Geometry> geom = createTexturedQuad(srcLeft, srcTop, srcRight, srcBottom);
            osg::ref_ptr<osg::Depth> depth = new osg::Depth;
            depth->setWriteMask(0);
            osg::StateSet* stateset = geom->getOrCreateStateSet();
            stateset->setAttribute(depth);
            stateset->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);
            stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
            stateset->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
            osg::ref_ptr<osg::Geode> geode = new osg::Geode;
            geode->addDrawable(geom);
            camera->addChild(geode);
        }

        mRoot->addChild(camera);

        mActiveCameras.push_back(camera);
    }