[osg-users] Glowing Sphere Effect

Erik Hensens ehensens at hunter.com
Thu Nov 19 07:53:20 PST 2015


Hi Sebastian,

Thank you for your reply.

As far as what type of glowing effect I'm after, I want something similar to the following:
http://i.stack.imgur.com/54Z2C.png
That is, I want a shiny glowing light to emit beyond the boundaries of the sphere.

As far as your comment about normals, I thought that was taken care of by the smoothing visitor. Perhaps you can help me understand this concept a little better...

As an experiment, I modified my code for six different variations and took screen captures of each of them. The experiments were:
1) No normals set, without the smoothing visitor
2) No normals set, with the smoothing visitor
3) "Good" normals set per primitive, without the smoothing visitor
4) "Good" normals set per primitive, with the smoothing visitor
5) "Bad" normals set per primitive, without the smoothing visitor
6) "Bad" normals set per primitive, with the smoothing visitor

By "good" normals I mean that for each triangle I set the normal to be the cross product of the two vectors that go along two sides of the triangle, and by "bad" normals I mean that I always set each normal vector to (0.0f, 0.0f, 1.0f). I set the normal vectors like so:


Code:

// Create the normal array for this geometry
osg::ref_ptr < osg::Vec3Array > pNormalsArray = new osg::Vec3Array;

//
// For each triangle...
//

// Add the vertices that make up this triangle
pVertexArray->push_back(Vertex1);
pVertexArray->push_back(Vertex2);
pVertexArray->push_back(Vertex3);

// Set the normal vector for this triangle
pNormalsArray->push_back((Vertex3 - Vertex1) ^ (Vertex2 - Vertex1));

...

//
// Done with all triangle vertices and normals
//

// Set this as the geometry's vertex array
pGeometry->setVertexArray(pVertexArray);

// Set the geometry's normals array
pGeometry->setNormalArray(pNormalsArray);
pGeometry->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET);

...





The results were interesting (at least to me):

1) No normals set, no smoothing: A boring, ordinary, monochrome sphere
2) No normals set, with smoothing, A good looking sphere with some shine to it
3) "Good" normals set, no smoothing: A very dark, boring, ordinary, monochrome sphere
4) "Good" normals set, with smoothing: A good looking sphere with some shine to it
5) "Bad" normals set, no smoothing: A boring, ordinary, monochrome sphere
6) "Bad" normals set, with smoothing: A good looking sphere with some shine to it

Screen capture images of scenarios 1 and 5 were binary identical, so the effects were identical.
Screen capture images of scenarios 2, 4, and 6 were binary identical, so the effects were identical.

This means that when using the smoothing visitor, it doesn't matter how I set the normal vectors, or if I even set them at all. This also means that not setting any normals was, in this case, equivalent to setting bogus normals (where each normal was set to the z-axis).

I tried using setEmission on the material but all that happened was the color changed.

So, how can I achieve the kind of glow effect that I want, and do I in fact have to set any normals or is using the smoothing visitor enough? I've attached the six screenshots (I have since changed the color to a dark green 0, 153, 0 instead of red).

Thank you very much in advance!

Erik


SMesserschmidt wrote:
> Hi Erik,
> 
> Do you mean glowing like non-lit but selfillumination? Then you're maybe 
> after the setEmission property.
> If you want a glow like bloom-effect, then you'll need some image 
> postprocessing or texture tricks.
> Maybe you can send some picture which resembles what you are trying to 
> achieve.
> BTW: your geometry doesn't have any normals, so lighting will be wrong 
> in any case.
> 
> 
> Cheers
> Sebastian
> 
> > Hello everyone!
> > 
> > I'm generating a sphere geode and I'd like to add a glowing effect in any variable color. I've only found one other similar topic on these forums but there was no answer. I imagine this must be possible, I just don't know how to do it. I've posted my code that creates the geode.
> > 
> > Any and all help is very much appreciated!
> > 
> > 
> > Code:
> > 
> > // The center of my sphere
> > osg::Vec3 tSphereCenter(0.0f, 0.0f, 0.0f);
> > 
> > // Create the geode
> > osg::ref_ptr < osg::Geode > pGeode = new osg::Geode;
> > 
> > // Create the geometry
> > osg::ref_ptr < osg::Geometry > pGeometry = new osg::Geometry;
> > 
> > // The vertex array that defines the shape of the sphere
> > osg::ref_ptr < osg::Vec3Array > pVertexArray = new osg::Vec3Array;
> > 
> > //
> > // Add vertices to pVertexArray using an icosahedron approach...
> > // How this is done is not relevant to this question...
> > //
> > 
> > // Set this as the geometry's vertex array
> > pGeometry->setVertexArray(pVertexArray);
> > 
> > // Set the primitive set
> > osg::ref_ptr < osg::DrawArrays > pDrawArrays = new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, static_cast < GLsizei >(pVertexArray->size()));
> > pGeometry->addPrimitiveSet(pDrawArrays);
> > 
> > // Get the state set
> > osg::ref_ptr < osg::StateSet > pStateSet = pGeometry->getOrCreateStateSet();
> > 
> > // Create the material
> > osg::ref_ptr < osg::Material > pMaterial = new osg::Material;
> > 
> > // Set the sphere color to red
> > pMaterial->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
> > 
> > // Make the sphere shiny
> > pMaterial->setShininess(osg::Material::FRONT_AND_BACK, 128.0f);
> > 
> > // Set the material on the geometry's state set
> > pStateSet->setAttribute(pMaterial);
> > 
> > // Finish up with the geometry
> > pStateSet->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
> > pGeometry->setStateSet(pStateSet);
> > 
> > // Add this geometry to the geode
> > pGeode->addDrawable(pGeometry);
> > 
> > // Ensure the geode is visible
> > pGeode->setNodeMask(0xffffffff);
> > 
> > // Smooth out the material
> > osgUtil::SmoothingVisitor sv;
> > pGeode->accept(sv);
> > 
> > // Add the geode to the scene
> > pSceneGroup->addChild(pGeode);
> > 
> > 
> > 
> > 
> > Thank you very much!
> > 
> > Cheers,
> > Erik[/code]
> > 
> > ------------------
> > Read this topic online here:
> > http://forum.openscenegraph.org/viewtopic.php?p=65690#65690
> > 
> > 
> > 
> > 
> > 
> > _______________________________________________
> > osg-users mailing list
> > 
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> > 
> 
> _______________________________________________
> osg-users mailing list
> 
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> 
>  ------------------
> Post generated by Mail2Forum
[/img]

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=65696#65696



-------------- next part --------------
A non-text attachment was scrubbed...
Name: 06_WithBadNormals_WithSmoothing.png
Type: image/png
Size: 25048 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20151119/8190b620/attachment-0018.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 05_WithBadNormals_NoSmoothing.png
Type: image/png
Size: 3755 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20151119/8190b620/attachment-0019.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 04_WithGoodNormals_WithSmoothing.png
Type: image/png
Size: 25048 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20151119/8190b620/attachment-0020.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 03_WithGoodNormals_NoSmoothing.png
Type: image/png
Size: 3755 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20151119/8190b620/attachment-0021.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 02_NoNormals_WithSmoothing.png
Type: image/png
Size: 25048 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20151119/8190b620/attachment-0022.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 01_NoNormals_NoSmoothing.png
Type: image/png
Size: 3755 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20151119/8190b620/attachment-0023.png>


More information about the osg-users mailing list