Hello,
I would like the fragment shader to read values from a uniform
sampler2DRect.
The sampler2DRect stores some data that I want to give to the shader.
The problem is that the shader always gets filtered value of the actual
data. I want the shader to get the exact value without any filtering.
I use the following binding method and shader programming:
//set image
osg::ref_ptr<osg::Image> imageSampler = new osg::Image();
imageSampler->allocateImage((int)XRes, (int)YRes, 1, GL_RGBA, GL_FLOAT);
osg::Vec4f * rgba = (osg::Vec4f *)(imageSampler->data());
// write date to the image
for (int row = 0; row < subYRes; row++) {
for (int column = 0; column < subXRes; column++) {
*rgba = osg::Vec4f(data, data, 0, 0);
rgba++;
}
}
// texture for sampler
osg::ref_ptr<osg::TextureRectangle> textureRect = new osg::TextureRectangle;
textureRect->setTextureSize((int)subXRes, (int)subYRes);
textureRect->setInternalFormat(GL_RGBA);
textureRect->setImage(0, imageSampler);
textureRect->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST);
// configure shader
stateset->addUniform(new osg::Uniform("textureID0", 0));
stateset->setTextureAttributeAndModes(0, textureRect,
osg::StateAttribute::ON);
// in fragment shader:
uniform sampler2DRect textureID0;
void main()
{
vec2 st=vec2(gl_FragCoord.x -0.5,gl_FragCoord.y-0.5);
vec4 rgba = texelFetch(textureID0, ivec2(st));
Frag_Color = vec4(rgba.r,rgba.g,0,0);
}
If I read the frame buffer, the value of rgba.r and rgba.g seem to be filtered
value, not exactly what the real value.
Where I am wrong here ?
Thanks a lot!
Best wishes
Shuiying
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org