Hi, J.P.

the camera isn't rendering to a texture. 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


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

Reply via email to