<div dir="ltr">Han,<div>Yes, you will need to use shaders.</div><div><br></div><div>Attach your MRT (multiple-render-target) textures, like you are doing:</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>rtt->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER0), colorTex);</div><div>rtt->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER1), normalTex);</div><div>rtt->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER2), depthTex);</div></blockquote><div><br></div><div>Then in your fragment shader, make an output corresponding to each buffer attachment:</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>in vec3 normal;</div><div>in vec4 color;</div><div>...</div><div>layout(location=0) out vec4 gcolor;</div><div>layout(location=1) out vec4 gnormal;</div><div>layout(location=2) out vec4 gdepth;</div><div>...</div><div>gcolor = color;</div><div>gnormal = vec4((normal+1.0)/2.0, 1.0);</div><div>gdepth = vec4(gl_FragCoord.z, 1.0);</div></blockquote><div><br></div><div>Notice that you will need to normalize the "normal" value so it's between [0..1].</div><div><br></div><div>Hope this helps!</div><div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Glenn Waldron / osgEarth</div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Nov 11, 2019 at 4:20 AM Han Hu <<a href="mailto:huhan8807@gmail.com">huhan8807@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">Hi,<br>
<br>
I would like to do offscreen rendering of a mesh.<br>
Currently, I have suceeded to do this for both the color (RGB) and depth data using the built-in functions as below.<br>
<br>
<br>
Code:<br>
<br>
<br>
osg::ref_ptr<osg::Image> rttImage = new osg::Image;<br>
osg::ref_ptr<osg::Image> depthImage = new osg::Image;<br>
<br>
camera->attach(osg::Camera::COLOR_BUFFER, rttImage.get());<br>
camera->attach(osg::Camera::DEPTH_BUFFER, depthImage.get());<br>
<br>
rttImage->allocateImage(ATInfo.width, ATInfo.height, 1, GL_RGB, GL_UNSIGNED_BYTE);<br>
depthImage->allocateImage(ATInfo.width, ATInfo.height, 1, GL_DEPTH_COMPONENT, GL_FLOAT);<br>
<br>
<br>
<br>
<br>
But I also need to render the normal vectors to images too. I have googled this topic using native opengl, it seems that I have to write shaders for it. But my mesh are defined using the osgb plugin format, so I must implement in the osg.<br>
<br>
I would like to know, is there an approach to do this in osg? Thanks!<br>
<br>
Thank you!<br>
<br>
Cheers,<br>
Han<br>
<br>
------------------<br>
Read this topic online here:<br>
<a href="http://forum.openscenegraph.org/viewtopic.php?p=76892#76892" rel="noreferrer" target="_blank">http://forum.openscenegraph.org/viewtopic.php?p=76892#76892</a><br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org" target="_blank">osg-users@lists.openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
</blockquote></div>