[osg-users] Render normal vectors to image

Glenn Waldron gwaldron at gmail.com
Mon Nov 11 05:01:07 PST 2019


Han,
Yes, you will need to use shaders.

Attach your MRT (multiple-render-target) textures, like you are doing:

rtt->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER0),
colorTex);
rtt->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER1),
normalTex);
rtt->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER2),
depthTex);


Then in your fragment shader, make an output corresponding to each buffer
attachment:

in vec3 normal;
in vec4 color;
...
layout(location=0) out vec4 gcolor;
layout(location=1) out vec4 gnormal;
layout(location=2) out vec4 gdepth;
...
gcolor = color;
gnormal = vec4((normal+1.0)/2.0, 1.0);
gdepth = vec4(gl_FragCoord.z, 1.0);


Notice that you will need to normalize the "normal" value so it's between
[0..1].

Hope this helps!

Glenn Waldron / osgEarth


On Mon, Nov 11, 2019 at 4:20 AM Han Hu <huhan8807 at gmail.com> wrote:

> Hi,
>
> I would like to do offscreen rendering of a mesh.
> Currently, I have suceeded to do this for both the color (RGB) and depth
> data using the built-in functions as below.
>
>
> Code:
>
>
>         osg::ref_ptr<osg::Image> rttImage = new osg::Image;
>         osg::ref_ptr<osg::Image> depthImage = new osg::Image;
>
> camera->attach(osg::Camera::COLOR_BUFFER, rttImage.get());
>         camera->attach(osg::Camera::DEPTH_BUFFER, depthImage.get());
>
>         rttImage->allocateImage(ATInfo.width, ATInfo.height, 1, GL_RGB,
> GL_UNSIGNED_BYTE);
>         depthImage->allocateImage(ATInfo.width, ATInfo.height, 1,
> GL_DEPTH_COMPONENT, GL_FLOAT);
>
>
>
>
> 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.
>
> I would like to know, is there an approach to do this in osg? Thanks!
>
> Thank you!
>
> Cheers,
> Han
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=76892#76892
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20191111/8044ecf6/attachment.html>


More information about the osg-users mailing list