Hello,

My blending version doesn't work.
Parts of the code:

// 1. create RTT-Texture (Rendertarget)
ref_ptr<Texture2D> baseTex = createRenderTexture(width,height);

// 2. Blend Texture
ref_ptr<Texture2D> blendTex = new Texture2D;
blendTex->setImage(osgDB::readImageFile(argv[2]));

// 3. Quads
ref_ptr< TexturedQuad > texQuad1 = new TexturedQuad(baseTex.get());
ref_ptr< TexturedQuad > texQuad2 = new TexturedQuad(blendTex.get());

// 4. Stack (Quad stack)
ref_ptr<Group> stack = new Group;

ref_ptr<MatrixTransform> mt1 = new MatrixTransform;
mt1->setMatrix(Matrix::translate(0,0,-1));
mt1->addChild(texQuad1);
stack->addChild(mt1);

ref_ptr<MatrixTransform> mt2 = new MatrixTransform;
mt2->setMatrix(Matrix::translate(0,0,0));
mt2->addChild(texQuad2);
stack->addChild(mt2);

// 5. BlendEquation
BlendEquation* blendEquation = new BlendEquation(BlendEquation::FUNC_ADD);
blendEquation->setDataVariance(Object::DYNAMIC);

// 6. BlendFunc
ref_ptr<BlendFunc> blendFunc = new BlendFunc();
blendFunc->setFunction(BlendFunc::ONE,BlendFunc::DST_COLOR );

// 7. StateSet
StateSet* stateset = new StateSet;

stateset->setDataVariance(Object::DYNAMIC);
stateset->setAttributeAndModes(blendEquation,StateAttribute::OVERRIDE|StateAttribute::ON);
stateset->setAttributeAndModes(blendFunc, StateAttribute::ON);
stateset->setRenderingHint(StateSet::TRANSPARENT_BIN);
stateset->setMode(GL_BLEND, StateAttribute::ON);

// 8. RTT Camera
osg::Camera* rtt_cam = new osg::Camera;
rtt_cam->setClearColor(osg::Vec4(0,0,0,0));
//rtt_cam->setClearMask( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
rtt_cam->setViewport(0,0,width,height);
rtt_cam->setRenderOrder(osg::Camera::PRE_RENDER, 0);
rtt_cam->setRenderTargetImplementation( osg::Camera::FRAME_BUFFER );
rtt_cam->attach(osg::Camera::COLOR_BUFFER0, baseTex, 0, 0);
rtt_cam->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
rtt_cam->setProjectionMatrixAsOrtho2D(0.0,1.0,0.0,1.0);
rtt_cam->setViewMatrix(osg::Matrix::identity());
rtt_cam->addChild(stack);

I think that is the important code. It doesn't increment the blend texture. If 
I change the camera, it looks like a infinite mirror. What is my mistake? I 
think I don't understand the blendequation in combination with RTT.

Regards,

Martin 

-------- Original-Nachricht --------
> Datum: Tue, 22 Feb 2011 14:02:30 +0100
> Von: "Martin Großer" <[email protected]>
> An: OpenSceneGraph Users <[email protected]>
> Betreff: Re: [osg-users] Can I increment the gl_FragData?

> Hello Juan,
> 
> I think in my case the ping-pong is OK, because I want to render a
> fullscreen quad. I developed a texture painting tool which is hardware
> accelerated. I can do it very easy with a glsl shader. Only the RTT into the 
> image is
> the bottle neck.
> 
> I will try the three versions.
> 
> 1. OSG: PingPong
> 2. OSG: Blending
> 3. OpenGL: EXT_shader_image_load_store
> 
> I will post my results here in the mailing list. Then we can talk about
> the osg integration.
> 
> It seems to me that the discussion was very useful. Thank you very much.
> 
> Regards,
> 
> Martin
> 
> -------- Original-Nachricht --------
> > Datum: Tue, 22 Feb 2011 13:23:26 +0100
> > Von: Juan Hernando <[email protected]>
> > An: OpenSceneGraph Users <[email protected]>
> > Betreff: Re: [osg-users] Can I increment the gl_FragData?
> 
> > Hi Martin,
> > > I don't understand the fact that I need a swap per triangle. In the
> > > osggameoflife there is one swap per render pass.
> > It depends on what you want to do.
> > If you are rendering a fullscreen quad and performing some pixel level 
> > operations, then ping-pong textures are OK. This is the case of the game
> > of life example.
> > However, if you are combining into each target pixel the contribution of
> > all the triangles that hit that pixel, then you can't use ping-pong 
> > because you have to swap the read and write textures after each triangle
> > (I assume you are not binding the same texture as input and output for a
> > shader because it has undefined behaviour). For example, this would be 
> > the case when you want to count the fragments falling into a pixel. If 
> > you can't use blending operations to do your calculations, then 
> > EXT_shader_image_load_store may be the last resort.
> > 
> >  > So my object is for
> >  > example a wall (plane) and I want to add a texture (brush) to this
> >  > wall like a airbrush. That is a simple test scenario.
> > Assuming your wall is screen aligned, I'd say that this airbrush example
> > falls in the category of blending. However, if your actual intent is to 
> > develop a realtime texture painting tool then, it might be easier to do 
> > it in completely in the CPU (I'm not an expert in texturing so there 
> > might be some clever tricks to take advantange of OpenGL to do it with 
> > random access image buffers).
> > 
> > > Ok first of all I should try the additive blending with osg::TexEnv.
> > > After this I can try a example with the extension
> > > EXT_shader_image_load_store. I have a NV GTX470, it should work. And
> > > then we can talk about a integration in OSG. I can send the example
> > > and we can discuss a suitable design. I am very interested in a
> > > smoothly integration in OSG.
> > Me too ;)
> > 
> > Cheers,
> > Juan
> > _______________________________________________
> > osg-users mailing list
> > [email protected]
> >
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> 
> -- 
> NEU: FreePhone - kostenlos mobil telefonieren und surfen!                     
> Jetzt informieren: http://www.gmx.net/de/go/freephone
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

-- 
Schon gehört? GMX hat einen genialen Phishing-Filter in die
Toolbar eingebaut! http://www.gmx.net/de/go/toolbar
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to