Hi,
I am using a pre_render stage camera to generate a texture for later use.
However the texture is not accessable to a later stage shader when it is set as
uniform, Since the texture functions fine when attached to geometry and the
shaders handle non generated textures without problem, I am wondering whether
is even possible to send an earlier render stage output to a later stage
shader. Conceptually it makes sense that this is possible. If it is, I would
appreciate possible examples of this working. The code below is a snippet of
how I am currently try to implement this functionality.
thank you for any help offered
Code:
//constructor for the render camera class, which prerenders to a texture
RenderCamera::RenderCamera(int height, int width){
_texture = new osg::Texture2D();
_height = height;
_width = width;
//Will need to set the texture size to the size of the viewport, it is not
right now
_texture->setTextureSize(width, height);
_texture->setInternalFormat(GL_RGBA);
_texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::NEAREST);
_texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::NEAREST);
// set up the render to camera attributes.
setClearMask( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
setClearColor(osg::Vec4(0.0f,0.0f,0.0f,1.0f));
// set viewport
setViewport(0,0, _width, _height);
setRenderOrder(osg::Camera::PRE_RENDER);
//set the render target, the frame buffer object is required else the textures
seg fault for some reason
setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT,
osg::Camera::FRAME_BUFFER);
// attach the texture and use it as the color buffer. this will render the
depth buffer to the texture.
osg::ref_ptr<osg::Image> image = new osg::Image;
image->allocateImage(_width, _height, 1, GL_RGBA, GL_FLOAT);
_texture->setImage(0, image.get());
//render the color buffer to texture
attach(osg::Camera::COLOR_BUFFER0, _texture.get(), 0, 0, false, 8, 8);
}
//send the texture generated from the prerender camera
osg::Texture2D* RenderCamera::getTexture(){
return _texture.get();
}
//initialize the prerender camera class
osg::ref_ptr<RenderCamera> smokeCamera = new RenderCamera(1024, 1024);
smokeCamera->setShader("shaders/depthPosition.vs", "shaders/depthPosition.fs");
smokeCamera->setRenderOrder(osg::Camera::PRE_RENDER, 0);
smokeCamera->addChild(_cloud);
root->addChild(smokeCamera.get());
//set the second stage stateset
osg::ref_ptr<osg::StateSet> stateset = root->getOrCreateStateSet();
stateset->setRenderBinDetails(1,"RenderBin");
osg::ref_ptr<osg::Program> program(new osg::Program);
program->addShader(osg::Shader::readShaderFile(osg::Shader::VERTEX,
"shaders/volumetricSmoke.vs"));
program->addShader(osg::Shader::readShaderFile(osg::Shader::FRAGMENT,
"shaders/volumetricSmoke.fs"));
//the texture does not get passed to the shader
stateset->setTextureAttributeAndModes(0, smokeCamera->getTexture(),
osg::StateAttribute::ON);
stateset->addUniform(new osg::Uniform("smokeDepthTexture", 0), true);
stateset->setAttribute(program.get());
Thank you!
Cheers,
Ross
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=20075#20075
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org