[osg-users] Render to Texture without clamping values

Philipp Meyer philipp.meyer at fh-bielefeld.de
Mon Jun 13 07:15:55 PDT 2016


Hi,

for my current project I need to do some computations in the fragment shader and retrieve the values within my application. For that I am using the render to texture feature together with a float texture.

I'm having some trouble reading values > 1.0 though. It seems like the values are getting clamped to 0..1, even though I followed the osgprerender HDR setup. Besides the code below, I have also tried GL_RGBA32F (ARB and not ARB) for the internal texture format, tried double for the image and source type and tried using osg::ClampColor to disable clamping for the RTT camera, all without success.

When reading the texture, It returns (0.123,0.5,1,1) for every texel.

Code for texture setup:


Code:
radarTexture = new osg::Texture2D;
	radarTexture->setInternalFormat(GL_RGBA16F_ARB);
	radarTexture->setSourceFormat(GL_RGBA);
	radarTexture->setSourceType(GL_FLOAT);

	auto textureImage = osgHelper::make_osgref<osg::Image>();
	textureImage->allocateImage(16,16,1,GL_RGBA, GL_FLOAT);
//	textureImage->setImage(128, 128, 1, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE,
//			nullptr, osg::Image::AllocationMode::NO_DELETE);
	radarTexture->setImage(textureImage);
	radarTexture->setMaxAnisotropy(0);
	radarTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
	radarTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
	radarTexture->setFilter(osg::Texture::FilterParameter::MIN_FILTER,
			osg::Texture::FilterMode::NEAREST);
	radarTexture->setFilter(osg::Texture::FilterParameter::MAG_FILTER,
			osg::Texture::FilterMode::NEAREST);
	radarTexture->setDataVariance(osg::Object::DYNAMIC);



RTT Camera setup (some)

Code:

// set the camera to render before the main camera.
	this->setRenderOrder(osg::Camera::PRE_RENDER);

	// tell the camera to use OpenGL frame buffer object where supported.
	this->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);

	// attach the texture and use it as the color buffer.
	this->attach(osg::Camera::COLOR_BUFFER0, dest->getImage());



GLSL Fragment Shader Code (simplified):


Code:
void main()
{
gl_FragColor = vec4(0.123,0.5,3,4);
}





Thank you!

Cheers,
Philipp

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=67593#67593








More information about the osg-users mailing list