[osg-users] Draw vertex as Circle with color given by some Vec4 array

Trajce Nikolov NICK trajce.nikolov.nick at gmail.com
Mon Jan 2 12:56:20 PST 2017


Hi Bruno,

yes, you can pass VertexAttributes to the program and look them up in the
shader. You can pass the centers as Vec3Array, Vec4Array for colors and
probably encode the radius into float array or the vertex.w() from the
vertex array.

Do a search through the examples for how to set up your program with
VertexAttributes ... Ping me if you if troubles, I might be able to give
some snippets

Cheers,
Nick

On Mon, Jan 2, 2017 at 8:21 PM, Bruno Oliveira <
bruno.manata.oliveira at gmail.com> wrote:

> Hello,
>
>
> I have an array of 3d points that I want to render in a scene. I want to
> render them as circles, centered on each point coordinates, with a given
> radius and a color that is given by a color array I have in memory.
>
> For now, I am creating a node for each point, that consists of a
> PrimitiveSet (polygon) that I iterate around the point center. (Check code
> below).
>
>
> Now I know this can be done with Shaders. I can draw the circle directly
> in the fragment shader with this example (http://www.geeks3d.com/
> 20130705/shader-library-circle-disc-fake-sphere-in-glsl-opengl-glslhacker/).
>
>
> But I need to pass the vertex centers and respective colors. Is it
> possible to pass a osg::Vec3Array* with vertex centers and a
> osg::Vec4Array* of colors directly to a Shader, so that I can , in a single
> compiled Shader program, handle all point positions and colors?
>
> Here is teh code for drawing the circle, I use this for each vertex:
>
> osg::Vec3Array* getArray(const float radius, const int points, const
> osg::Vec3& center) {
>     auto array = new osg::Vec3Array();
>     const float ratio = (float(2.0*osg::PI) / float(points));
>     for (int i = 0; i < points; i++) {
>         const float angle = float(i) * ratio;
>         array->push_back(osg::Vec3(
>                     center.x() + radius*cosf( angle ),
>                     center.y() + radius*sinf( angle ),
>                     center.z())
>                 );
>     }
>     return array;
> }
>
> osg::Geometry* getGeometry(const float radius, const int points, const
> osg::Vec3& center) {
>     osg::Geometry* geom = new osg::Geometry();
>
>     geom->setVertexArray(getArray(radius, points, center));
>     geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,
> 0, points));
>
>     return geom;
> }
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>


-- 
trajce nikolov nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20170102/825a2f83/attachment-0003.htm>


More information about the osg-users mailing list