[osg-users] Depth and Color buffer attachemnts do not play along together

Trajce Nikolov NICK trajce.nikolov.nick at gmail.com
Tue Mar 30 02:45:15 PST 2021


Nonone on this? Robert?

Thank you
Nick

On Sun, Mar 28, 2021 at 5:24 PM Trajce Nikolov NICK <
trajce.nikolov.nick at gmail.com> wrote:

> Attached is the minimal code that reproduce the problem
>
> Thanks a bunch as always!
>
> Nick
>
> On Sun, Mar 28, 2021 at 2:49 PM Trajce Nikolov NICK <
> trajce.nikolov.nick at gmail.com> wrote:
>
>> Hi Community,
>>
>> I am attaching to the main camera DepthBuffer and ColorBuffer as
>> Texture2D - attached is the setup. I also have shader to check the depth
>> buffer - so it is ok as on the image. And I am displaying it on a quad. The
>> depth buffer is still getting me zeros when the colorbuffer is attached,
>> otherwise when it is not, then it works as it should.
>>
>> Any hints?
>>
>> mOsgExternalDepth = new osg::Texture2D;
>> mOsgExternalDepth->setSourceFormat(GL_DEPTH_COMPONENT);
>> mOsgExternalDepth->setSourceType(GL_FLOAT);
>> mOsgExternalDepth->setInternalFormat(GL_DEPTH_COMPONENT32F);
>> mOsgExternalDepth->setTextureWidth(screenWidth);
>> mOsgExternalDepth->setTextureHeight(screenHeight);
>> mOsgExternalDepth->setResizeNonPowerOfTwoHint(false);\
>>
>> mOsgExternalColor = new osg::Texture2D;
>> mOsgExternalColor->setInternalFormat(GL_RGBA16F_ARB);
>> mOsgExternalColor->setSourceFormat(GL_RGBA);
>> mOsgExternalColor->setSourceType(GL_FLOAT);
>> mOsgExternalColor->setTextureWidth(screenWidth);
>> mOsgExternalColor->setTextureHeight(screenHeight);
>> mOsgExternalColor->setResizeNonPowerOfTwoHint(false);
>>
>> mainCamera->attach(osg::Camera::COLOR_BUFFER,
>> (osg::Texture*)mOsgExternalColor);
>> mainCamera->attach(osg::Camera::DEPTH_BUFFER,
>> (osg::Texture*)mOsgExternalDepth);
>>
>> osg::ref_ptr<osg::Camera> camera = new osg::Camera;
>> camera->setProjectionMatrix(osg::Matrixd::ortho2D(0, screenWidth, 0,
>> screenHeight));
>> camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
>> camera->setViewMatrix(osg::Matrixd::identity());
>> camera->setClearMask(0);
>> camera->setRenderOrder(osg::Camera::POST_RENDER);
>> camera->setAllowEventFocus(false);
>>
>>
>> context.getImageGenerator()->getViewer()->getView(0)->getSceneData()->asGroup()->addChild(camera);
>>
>> osg::ref_ptr<osg::Geometry> quad =
>> osg::createTexturedQuadGeometry(osg::Vec3(0, 0, 0),
>> osg::Vec3(screenWidth/2, 0, 0), osg::Vec3(0, screenHeight/2, 0));
>> quad->getOrCreateStateSet()->setMode(GL_LIGHTING,
>> osg::StateAttribute::OFF);
>> quad->getOrCreateStateSet()->setTextureAttributeAndModes(0,
>> mOsgExternalDepth);
>>
>> const std::string vertShader = ""\
>> "void main() "\
>> "{ "\
>> " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; "\
>> " gl_TexCoord[0] = gl_TextureMatrix[0] *gl_MultiTexCoord0;"\
>> "}";
>>
>> const std::string fragShader = ""\
>> "uniform sampler2D texture0; "\
>> "void main() "\
>> "{ "\
>> " float d = texture2D( texture0, gl_TexCoord[0].xy ).x; "\
>> " gl_FragColor = vec4(d, d, d, 1); "\
>> "}";
>>
>> osg::ref_ptr<osg::Shader> vert = new osg::Shader(osg::Shader::VERTEX,
>> vertShader);
>> osg::ref_ptr<osg::Shader> frag = new osg::Shader(osg::Shader::FRAGMENT,
>> fragShader);
>>
>> osg::ref_ptr<osg::Program> program = new osg::Program;
>> program->addShader(vert);
>> program->addShader(frag);
>>
>> quad->getOrCreateStateSet()->setAttributeAndModes(program);
>> quad->getOrCreateStateSet()->addUniform(new
>> osg::Uniform(osg::Uniform::SAMPLER_2D, "texture0", 0));
>> osg::ref_ptr<osg::Geometry> quadColor =
>> osg::createTexturedQuadGeometry(osg::Vec3(screenWidth / 2, 0, 0),
>> osg::Vec3(screenWidth/2 , 0, 0), osg::Vec3(0, screenHeight/2, 0));
>> quadColor->getOrCreateStateSet()->setMode(GL_LIGHTING,
>> osg::StateAttribute::OFF);
>> quadColor->getOrCreateStateSet()->setTextureAttributeAndModes(0,
>> mOsgExternalColor);
>>
>> camera->addChild(quadColor);
>> camera->addChild(quad);
>>
>> --
>> trajce nikolov nick
>>
>
>
> --
> trajce nikolov nick
>


-- 
trajce nikolov nick

-- 
You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osg-users+unsubscribe at googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osg-users/CAO-%2Bzim8AG_PaxkzoRdKDEvMMtvykWW6aFy0OE6K%3DNP47PHB9A%40mail.gmail.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20210330/665eb194/attachment.html>


More information about the osg-users mailing list