Actually it worked after rethinking it. Thanks Glenn On Tue, Mar 30, 2021, 17:10 Trajce Nikolov NICK < trajce.nikolov.n...@gmail.com> wrote:
> Thanks Glenn. How this will work with setting the render target > implementation to the main view camera? I am trying to avoid multiple > cameras and I am not sure this is doable > > On Tue, Mar 30, 2021, 15:07 Glenn Waldron <gwald...@gmail.com> wrote: > >> Nick, >> Pretty sure you can only attach one texture to a FRAME_BUFFER render >> target. And in that case, it is just copying the framebuffer to your >> texture after rendering it. Consider using a FRAME_BUFFER_OBJECT instead. >> >> On Monday, March 29, 2021 at 10:45:27 PM UTC-4 trajce.ni...@gmail.com >> wrote: >> >>> Nonone on this? Robert? >>> >>> Thank you >>> Nick >>> >>> On Sun, Mar 28, 2021 at 5:24 PM Trajce Nikolov NICK < >>> trajce.ni...@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.ni...@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+unsubscr...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/osg-users/64c1877d-50c2-4fad-801d-41cd63529376n%40googlegroups.com >> <https://groups.google.com/d/msgid/osg-users/64c1877d-50c2-4fad-801d-41cd63529376n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/osg-users/CAO-%2BzinCoWyd%3DbsbupGW4qRGWpmXxct9EU%3DK%2B%3DU1TU2s7UFJMw%40mail.gmail.com.
_______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org