Hi all,
I'm instancing geometry using a floating point texture containing
worldspace positions. The position texture and instancing work.
Resolution is constant at 1024x768
Now I'm trying to use a FBO (pre-render) to write to a position texture
and use that in the instancing shader (It will later be used for
updating positions)
It doesn't work..
I'm using the exact same data in the FBO texture cos I'm passing the
original floating point texture into the fbo shader and setting
gl_FragData[0]. The instance shaders are simple and take the FBO texture.
I am not familiar with fbo's. Should I set the RTT camera with a scene?
is there another way to write to images using shaders without fbo's?
I'm calling dirty() on the image with a callback (not sure if necessary
with FBO)
Have included code below for the main setup and important shader fbo pass.
Thanks for any help..
P
vertex
------
passthrough vert shader
fragment
--------
#version 400 compatibility
uniform sampler2D positionTexture;
uniform float time;
void main(void)
{
vec4 position = texture2D(positionTexture, gl_TexCoord[0].xy);
gl_FragData[0] = position;
}
Main setup:
-----------
positionimage = create2DImage("Positions.tiff");
updatepositionimage = create2DImage("Positions.tiff");
//Textures used in
positionTexture = createFloatTexture(positionimage->s(),
positionimage->t());
newPositionTexture = createFloatTexture(updatepositionimage->s(),
updatepositionimage->t());
rttCamera = createRTTCamera( positionimage->s(), positionimage->t());
//Textures sent to the instancing shader
rttCamera->attach( osg::Camera::COLOR_BUFFER0, positionTexture );
rttCamera->attach( osg::Camera::COLOR_BUFFER1, directionTexture);
rttCamera->addChild( scene );
Creating RTT Camera:
---------------------
osg::Camera* createRenderTTCamera( int width, int height )
{
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setClearColor( osg::Vec4(0.5,0.5,0.5,1.0) );
camera->setClearMask( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
camera->setRenderTargetImplementation(
osg::Camera::FRAME_BUFFER_OBJECT );
camera->setRenderOrder( osg::Camera::PRE_RENDER );
camera->setViewport( 0, 0, width, height);
return camera.release();
}
Creating FBO texture:
---------------------
osg::Texture2D* createFBOFloatTexture(unsigned int width, unsigned int
height)
{
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
texture->setTextureSize( width, height );
texture->setDataVariance(osg::Object::DYNAMIC);
texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT);
texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT);
texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::NEAREST);
texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::NEAREST);
texture->setInternalFormat( GL_RGBA32F_ARB );
texture->setSourceFormat( GL_RGBA );
texture->setSourceType( GL_FLOAT );
texture->setResizeNonPowerOfTwoHint(false);
return texture.release();
}
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org