Hi, Delport:
I use them, the fragment shader code is very easy.
varying vec4 worldPos;
void main(void)
{
gl_FragData[0]=worldPos;
}
I'm sure the worldPos is
calculated right, you can try
if(worldPos.x>1)
{
gl_FragData[0]=vec4(0,1,1,1);
}
else
{
gl_FragData[0]=worldPos;
}
And the x value exceed 1 will
output as color (0,1,1,1).
The major problem I guess is
happened when camera read the texture image value back to memory!
J.P. Delport wrote:
Hi,
have you tried using COLOR_BUFFER0 and gl_FragData in shader?
jp
hesicong2006 wrote:
Hi, Robert:
I'm now writing shader to compute world coordinate of the scene and
save them as image. The value output by shader will exceed 1 and
require float values, so I use GL_RGBA32F_ARB for RTT texture. Since I
must save them to an image, I must allocate a Image and attach it to
the texture. My texture setup code is :
osg::ref_ptr<osg::Texture2D> texture=new osg::Texture2D();
osg::ref_ptr<osg::Image> image=new osg::Image;
image->allocateImage(1024,768 , 1, GL_RGBA, GL_FLOAT);
texture->setTextureSize(1024,768);
texture->setInternalFormat(GL_RGBA32F_ARB);
texture->setSourceFormat(GL_RGBA);
texture->setSourceType(GL_FLOAT);
texture->setResizeNonPowerOfTwoHint(false);
texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
texture->setImage(0, image.get());
And then I attach the image to camera:
camera=viewer->getCamera();
camera->setGraphicsContext(gc.get());
camera->setViewport(0,0,wWidth,wHeight);
camera->attach(osg::Camera::COLOR_BUFFER,
texture->getImage());
camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
But after I ran the program and saved the image, I found out the shader
output value which exceed 1 is clamped to 1! In order to check the
problem, I wrote a small callback to check it:
class VoxlizationPreDrawCallback : public osg::Camera::DrawCallback
{
public:
virtual void operator () (osg::RenderInfo& ) const
{
for(int y=0;y<768;y++)
{
for(int x=0;x<1024;x++)
{
float value=*(float*)imageToSave->data(x,y);
if(value>1)
{
std::cout<<"x="<<x<<"
y="<<y<<std::endl;
}
}
}
}
osg::Image* imageToSave;
};
But no value exceed 1. I changed the value>1 to value==1, it will
give me a lot of values.
I also tried if my shader can't output values above 1, I changed the
camera setting from
camera->attach(osg::Camera::COLOR_BUFFER,
texture->getImage());
to
camera->attach(osg::Camera::COLOR_BUFFER,
texture->get());
And I can see in GDebugger 4.2 frame buffer object, some values
actually above 1.
So I guess the process of camera writing values to osg::Image does not
support RGBA32 float format or it clamp the value to 1, float value
should not clamp to 1, it buggy!
Please check it! Thanks! And I also attached my little code and a box
model which size is (2*2*2) to help reproduce the problem.
Hesicong
2008-7-3
------------------------------------------------------------------------
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
|