<div dir="ltr">Nonone on this? Robert?<br><div><br></div><div>Thank you</div><div>Nick</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Mar 28, 2021 at 5:24 PM Trajce Nikolov NICK <<a href="mailto:trajce.nikolov.nick@gmail.com">trajce.nikolov.nick@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Attached is the minimal code that reproduce the problem<br><div><br></div><div>Thanks a bunch as always!</div><div><br></div><div>Nick</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Mar 28, 2021 at 2:49 PM Trajce Nikolov NICK <<a href="mailto:trajce.nikolov.nick@gmail.com" target="_blank">trajce.nikolov.nick@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Hi Community,<div><br></div><div>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.</div><div><br></div><div>Any hints?</div><div><br></div><div><div>mOsgExternalDepth = new osg::Texture2D;</div><div>mOsgExternalDepth->setSourceFormat(GL_DEPTH_COMPONENT);</div><div>mOsgExternalDepth->setSourceType(GL_FLOAT);</div><div>mOsgExternalDepth->setInternalFormat(GL_DEPTH_COMPONENT32F);</div><div>mOsgExternalDepth->setTextureWidth(screenWidth);</div><div>mOsgExternalDepth->setTextureHeight(screenHeight);</div><div>mOsgExternalDepth->setResizeNonPowerOfTwoHint(false);\</div><div><br></div><div>mOsgExternalColor = new osg::Texture2D;<span style="white-space:pre-wrap">                                </span></div><div>mOsgExternalColor->setInternalFormat(GL_RGBA16F_ARB);</div><div>mOsgExternalColor->setSourceFormat(GL_RGBA);</div><div>mOsgExternalColor->setSourceType(GL_FLOAT);</div><div>mOsgExternalColor->setTextureWidth(screenWidth);</div><div>mOsgExternalColor->setTextureHeight(screenHeight);</div><div>mOsgExternalColor->setResizeNonPowerOfTwoHint(false);</div><div><br></div><div>mainCamera->attach(osg::Camera::COLOR_BUFFER, (osg::Texture*)mOsgExternalColor);</div><div>mainCamera->attach(osg::Camera::DEPTH_BUFFER, (osg::Texture*)mOsgExternalDepth);</div><div><br></div><div>osg::ref_ptr<osg::Camera> camera = new osg::Camera;</div><div>camera->setProjectionMatrix(osg::Matrixd::ortho2D(0, screenWidth, 0, screenHeight));</div><div>camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);</div><div>camera->setViewMatrix(osg::Matrixd::identity());</div><div>camera->setClearMask(0);</div><div>camera->setRenderOrder(osg::Camera::POST_RENDER);</div><div>camera->setAllowEventFocus(false);</div><div><br></div><div>context.getImageGenerator()->getViewer()->getView(0)->getSceneData()->asGroup()->addChild(camera);<span style="white-space:pre-wrap">                                </span></div><div><br></div><div>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));</div><div>quad->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);</div><div>quad->getOrCreateStateSet()->setTextureAttributeAndModes(0, mOsgExternalDepth);</div><div><br></div><div>const std::string vertShader = ""\</div><div><span style="white-space:pre-wrap">  </span>"void main()<span style="white-space:pre-wrap">                                                                                               </span>"\</div><div><span style="white-space:pre-wrap">  </span>"{<span style="white-space:pre-wrap">                                                                                                                 </span>"\</div><div><span style="white-space:pre-wrap">  </span>"<span style="white-space:pre-wrap">  </span>gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;<span style="white-space:pre-wrap"> </span>"\</div><div><span style="white-space:pre-wrap">  </span>"<span style="white-space:pre-wrap">  </span>gl_TexCoord[0] = gl_TextureMatrix[0] *gl_MultiTexCoord0;"\</div><div><span style="white-space:pre-wrap">  </span>"}";</div><div><br></div><div>const std::string fragShader = ""\</div><div><span style="white-space:pre-wrap">       </span>"uniform sampler2D texture0;<span style="white-space:pre-wrap">                                                               </span>"\</div><div><span style="white-space:pre-wrap">  </span>"void main()<span style="white-space:pre-wrap">                                                                                               </span>"\</div><div><span style="white-space:pre-wrap">  </span>"{<span style="white-space:pre-wrap">                                                                                                                 </span>"\</div><div><span style="white-space:pre-wrap">  </span>"<span style="white-space:pre-wrap">  </span>float d = texture2D( texture0, gl_TexCoord[0].xy ).x;<span style="white-space:pre-wrap">   </span>"\</div><div><span style="white-space:pre-wrap">  </span>"<span style="white-space:pre-wrap">  </span>gl_FragColor = vec4(d, d, d, 1);<span style="white-space:pre-wrap">                                                </span>"\</div><div><span style="white-space:pre-wrap">  </span>"}";</div><div><br></div><div>osg::ref_ptr<osg::Shader> vert = new osg::Shader(osg::Shader::VERTEX, vertShader);</div><div>osg::ref_ptr<osg::Shader> frag = new osg::Shader(osg::Shader::FRAGMENT, fragShader);</div><div><br></div><div>osg::ref_ptr<osg::Program> program = new osg::Program;</div><div>program->addShader(vert);</div><div>program->addShader(frag);</div><div><br></div><div>quad->getOrCreateStateSet()->setAttributeAndModes(program);</div><div>quad->getOrCreateStateSet()->addUniform(new osg::Uniform(osg::Uniform::SAMPLER_2D, "texture0", 0));</div><div><span style="white-space:pre-wrap">                     </span></div><div>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));</div><div>quadColor->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);</div><div>quadColor->getOrCreateStateSet()->setTextureAttributeAndModes(0, mOsgExternalColor);</div><div><br></div><div>camera->addChild(quadColor);</div><div>camera->addChild(quad);</div><div><br></div>-- <br><div dir="ltr">trajce nikolov nick<br></div></div></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr">trajce nikolov nick<br></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature">trajce nikolov nick<br></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:osg-users+unsubscribe@googlegroups.com">osg-users+unsubscribe@googlegroups.com</a>.<br />
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/osg-users/CAO-%2Bzim8AG_PaxkzoRdKDEvMMtvykWW6aFy0OE6K%3DNP47PHB9A%40mail.gmail.com?utm_medium=email&utm_source=footer">https://groups.google.com/d/msgid/osg-users/CAO-%2Bzim8AG_PaxkzoRdKDEvMMtvykWW6aFy0OE6K%3DNP47PHB9A%40mail.gmail.com</a>.<br />