[osg-users] Glowing Sphere Effect

Sebastian Messerschmidt sebastian.messerschmidt at gmx.de
Fri Nov 20 01:27:51 PST 2015


Hi Erik,
> 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.
Ok, basically this not related to OSG directly.
One option is to render the scene to texture and run a separable blur 
filter on the pixels you want to "glow". The osgPPU might help here.
The use of the infamous search device might reveal other options tough.

>
> 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...

I didn't catch the visitor, but in general should provide at least face 
normals. The smoothing visitor will fail with more complex geometry if 
you don't provide enough topological information I guess.
For more complex models you should use assets out of modelling programs 
anyway.

Cheers
Sebastian
>
> 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
>
>
>
>
>
> _______________________________________________
> 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/20151120/7b47ff1e/attachment-0003.htm>


More information about the osg-users mailing list