<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<font size="-1"><font face="Verdana">Hi, Delport:<br>
I use them, the fragment shader code is very easy.<br>
<br>
</font></font>
<blockquote><font size="-1"><font face="Verdana">varying vec4 worldPos;
</font></font><br>
<font size="-1"><font face="Verdana"></font></font><font size="-1"><font
face="Verdana">void main(void)</font></font><br>
<font size="-1"><font face="Verdana">{</font></font><br>
<font size="-1"><font face="Verdana"> gl_FragData[0]=worldPos;</font></font><br>
<font size="-1"><font face="Verdana">}<br>
<br>
<br>
</font></font></blockquote>
<font size="-1"><font face="Verdana">I'm sure the worldPos is
calculated right, you can try </font></font><br>
<blockquote><font size="-1"><font face="Verdana">if(worldPos.x>1)</font></font><br>
<font size="-1"><font face="Verdana">{</font></font><br>
<font size="-1"><font face="Verdana"> gl_FragData[0]=vec4(0,1,1,1);</font></font><br>
<font size="-1"><font face="Verdana">}</font></font><br>
<font size="-1"><font face="Verdana">else</font></font><br>
<font size="-1"><font face="Verdana">{</font></font><br>
<font size="-1"><font face="Verdana"> gl_FragData[0]=worldPos;</font></font><br>
<font size="-1"><font face="Verdana">}</font></font><br>
</blockquote>
<br>
<font size="-1"><font face="Verdana">And the x value exceed 1 will
output as color (0,1,1,1).</font></font><br>
<br>
<font size="-1"><font face="Verdana">The major problem I guess is
happened when camera read the texture image value back to memory!</font></font><br>
<font size="-1"><font face="Verdana"></font></font><br>
J.P. Delport wrote:
<blockquote cite="mid:486C78F6.4050609@csir.co.za" type="cite">Hi,
<br>
<br>
have you tried using COLOR_BUFFER0 and gl_FragData in shader?
<br>
<br>
jp
<br>
<br>
hesicong2006 wrote:
<br>
<blockquote type="cite">Hi, Robert:
<br>
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 :
<br>
<br>
osg::ref_ptr<osg::Texture2D> texture=new osg::Texture2D();
<br>
<br>
osg::ref_ptr<osg::Image> image=new osg::Image;
<br>
image->allocateImage(1024,768 , 1, GL_RGBA, GL_FLOAT);
<br>
<br>
texture->setTextureSize(1024,768);
<br>
texture->setInternalFormat(GL_RGBA32F_ARB);
<br>
texture->setSourceFormat(GL_RGBA);
<br>
texture->setSourceType(GL_FLOAT);
<br>
texture->setResizeNonPowerOfTwoHint(false);
<br>
texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
<br>
texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
<br>
texture->setImage(0, image.get());
<br>
<br>
<br>
And then I attach the image to camera:
<br>
<br>
camera=viewer->getCamera();
<br>
camera->setGraphicsContext(gc.get());
<br>
camera->setViewport(0,0,wWidth,wHeight);
<br>
camera->attach(osg::Camera::COLOR_BUFFER,
texture->getImage());
<br>
camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
<br>
<br>
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:
<br>
<br>
class VoxlizationPreDrawCallback : public osg::Camera::DrawCallback
<br>
{
<br>
public:
<br>
virtual void operator () (osg::RenderInfo& ) const
<br>
{
<br>
for(int y=0;y<768;y++)
<br>
{
<br>
for(int x=0;x<1024;x++)
<br>
{
<br>
float value=*(float*)imageToSave->data(x,y);
<br>
if(value>1)
<br>
{
<br>
std::cout<<"x="<<x<<"
y="<<y<<std::endl;
<br>
}
<br>
}
<br>
}
<br>
}
<br>
<br>
osg::Image* imageToSave;
<br>
};
<br>
<br>
But no value exceed 1. I changed the value>1 to value==1, it will
give me a lot of values.
<br>
<br>
I also tried if my shader can't output values above 1, I changed the
camera setting from
<br>
<br>
camera->attach(osg::Camera::COLOR_BUFFER,
texture->getImage());
<br>
to
<br>
camera->attach(osg::Camera::COLOR_BUFFER,
texture->get());
<br>
<br>
And I can see in GDebugger 4.2 frame buffer object, some values
actually above 1.
<br>
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!
<br>
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.
<br>
<br>
Hesicong
<br>
2008-7-3
<br>
<br>
<br>
------------------------------------------------------------------------
<br>
<br>
_______________________________________________
<br>
osg-users mailing list
<br>
<a class="moz-txt-link-abbreviated" href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a>
<br>
<a class="moz-txt-link-freetext" href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a>
<br>
</blockquote>
<br>
</blockquote>
</body>
</html>