Hi,

On 18/01/2012 20:24, wang shuiying wrote:
Hi, J.P.

the camera isn't rendering to a texture.
Yes it is. It is just made for you automatically. FBO renders to a texture and the image is read from this texture when you attach it to the camera.

I suggest attaching a texture (to the same buffer component as the image), with the exact formats you require to the camera as well. E.g.

_OutputTexture = new osg::TextureRectangle;
_OutputTexture->setTextureSize(_TextureWidth, _TextureHeight);
_OutputTexture->setInternalFormat(GL_RGBA32F_ARB);
_OutputTexture->setSourceFormat(GL_RGBA);
_OutputTexture->setSourceType(GL_FLOAT);

camera->attach(osg::CameraNode::COLOR_BUFFER, _OutputTexture.get());
camera->attach(osg::CameraNode::COLOR_BUFFER, image);

rgds
jp

In my programme, camera is set
to be prerender, render target is FRAME_BUFFER_OBJECT, I attach the
camera to an image, in order to get the bufferdata via image. the image
data type is allocated as GL_FLOAT.

Related setup details are listed below.

// renderTarget
osg::Camera::RenderTargetImplementation renderTargetImplementation;
renderTargetImplementation = osg::CameraNode::FRAME_BUFFER_OBJECT;


// shader program
osg::Program * program = new osg::Program();
program->addShader(osg::Shader::readShaderFile(osg::Shader::FRAGMENT,
fragmentShaderPath));
program->addShader(osg::Shader::readShaderFile(osg::Shader::VERTEX,
vertexShaderPath));


// image
osg::Image * image = new osg::Image();
image->allocateImage((int)XRes, (int)YRes, 1, GL_RGBA, GL_FLOAT);

//camera
osg::ref_ptr<osg::CameraNode> camera(new osg::CameraNode());
camera->setProjectionMatrixAsFrustum(-tan(YawView * math::D2R * 0.5),
tan(YawView * math::D2R * 0.5), -tan(PitchView * math::D2R * 0.5),
tan(PitchView * math::D2R * 0.5),zNear, zFar);
camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
camera->setViewport(0, 0, XRes, YRes);
camera->setClearColor(osg::Vec4(1000.0f, 1000.0f, 1000.0f, 1000.0f));
camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera->setViewMatrix(osg::Matrix::lookAt(osg::Vec3d(0, 0, 1.0f),
osg::Vec3d(-10.0f, 0.0f, 0), osg::Vec3d(0, 0, 1)));
camera->setRenderOrder(osg::CameraNode::PRE_RENDER);
camera->setRenderTargetImplementation(renderTargetImplementation);
camera->attach(osg::CameraNode::COLOR_BUFFER, image);


//read out data
osg::Vec4f * rgbaData = (osg::Vec4f *) (image->data());
for (int h = 0; h < yRes; h++) {
for (int w = 0; w < xRes; w++) {
osg::Vec4f cur = rgbaData[xRes * h + w];
cout<<"cur[0]="<<cur[0]<<",cur[1]="<<cur[1]<<",cur[2]="<<cur[2]<<",cur[3]="<<cur[3]<<endl;

}
}

Thank you for any advice!

Shuiying

Message: 3
Date: Wed, 18 Jan 2012 09:11:15 +0200
From: "J.P. Delport"<[email protected]>
To: OpenSceneGraph Users<[email protected]>
Subject: Re: [osg-users] Help: wrong ouput from frag shader.
Message-ID:<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hi,

what format is the texture you are rendering to? If it is UNSIGNED CHAR
then your data would be discretised.

e.g. 45/255 = 0.176471

jp

On 17/01/2012 21:11, wang shuiying wrote:

Hello,

when I write gl_FragColor = vec4(0.174977,0,0,1) in Frag shader,
then I get through a related image: float Vec4: (0.176471,0,0,1)

so why 0.174977 changed into 0.176471?

I think there should be no process there after per fragment operations
that can change this element in the rendering pipeline. Blend, alphatest
and so on are all disenabled.

Thank you in advance!

Shuiying
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to