[osg-users] Rendering double-sided surfaces.

1 view
Skip to first unread message

alessandro terenzi

unread,
Jan 26, 2009, 7:09:26 AM1/26/09
to OpenSceneGraph Users
Sometimes my application has to load models that have normals not always oriented in the same coherent way, so it is not always possible to say that a surface is oriented in a way or in another and my renderings do not look correct. 
 
I'd like to fix this problem in some way...so I was thinking about rendering both front and back faces, but how do I ask OSG do this? Or perhaps, is there another way/technique to achive the same result? (ie. orient a surface in a coherent way: all faces inward XOR outward)
 
Thank you.
Alessandro

Tomlinson, Gordon

unread,
Jan 26, 2009, 7:37:54 AM1/26/09
to OpenSceneGraph Users
your triangles all need to be wound the same way (anticlockwise by default for OSG & Opengl), whether or not your normal's are correct
 
The easiest fix would be to ensure that your modeling package sets up correct normal's before you get to OSG
 
Assuming your triangles are wound the same way ( if not you will have to fix that ) try using the SmoothingVistor on the data see
 
include\osgUtil\SmoothingVisitor
 

Gordon

__________________________________________________________
Gordon Tomlinson

Product Manager 3D
Email  : gtomlinson @ overwatch.textron.com
__________________________________________________________
(C): (+1) 571-265-2612
(W)
: (+1) 703-437-7651

"Self defence is not a function of learning tricks
but is a function of how quickly and intensely one
can arouse one's instinct for survival"
- Master Tambo Tetsura

 
 


From: osg-user...@lists.openscenegraph.org [mailto:osg-user...@lists.openscenegraph.org] On Behalf Of alessandro terenzi
Sent: Monday, January 26, 2009 7:09 AM
To: OpenSceneGraph Users
Subject: [osg-users] Rendering double-sided surfaces.

alessandro terenzi

unread,
Jan 26, 2009, 10:21:41 AM1/26/09
to OpenSceneGraph Users
Problem is that the models that come to my application are already prepared by people that do not (and unfortunately won't) think about normals issues, so maybe the best thing to do would be to really render both front and back faces, I'm not an expert, but the only approach I can think is to double the geometry so to have both faces, but it would be really a waste (not to mention performace problems that may arise..and other unexpected visualization problems I cannot think of..)

Regards.
Alessandro

_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


frank...@jhmi.edu

unread,
Jan 26, 2009, 10:44:27 AM1/26/09
to OpenSceneGraph Users
For sure the best thing to do would be to process the incoming data as
suggested. However, you might be able to get OpenGL to do what you want
by setting all material properties for both sides of the polygon and
enabling two sided lighting. Something like this.

osg::ref_ptr< osg::LightModel > pLightModel = new osg::LightModel();
pLightModel->setTwoSided( true );
pState->setAttributeAndModes( pLightModel.get(), osg::StateAttribute::ON );

osg::ref_ptr<osg::Material> pMaterial = new osg::Material();
pMaterial->setColorMode( osg::Material::DIFFUSE );
pMaterial->setAmbient( osg::Material::FRONT_AND_BACK, osg::Vec4( 0.0, 0.0, 0.0, 1.0 ) );
pMaterial->setSpecular( osg::Material::FRONT_AND_BACK, osg::Vec4( 1.0, 1.0, 1.0, 1.0 ) );
pMaterial->setShininess( osg::Material::FRONT_AND_BACK, 64.0f );
pState->setAttributeAndModes( pMaterial.get(), osg::StateAttribute::ON );

I have never tried this for data like you have but it seems to me like
it should work.

Frank

On Mon, Jan 26, 2009 at 04:21:41PM +0100, alessandro terenzi wrote:
> Problem is that the models that come to my application are already prepared
> by people that do not (and unfortunately won't) think about normals issues,
> so maybe the best thing to do would be to really render both front and back
> faces, I'm not an expert, but the only approach I can think is to double the
> geometry so to have both faces, but it would be really a waste (not to
> mention performace problems that may arise..and other unexpected
> visualization problems I cannot think of..)
> Regards.
> Alessandro
>
> On Mon, Jan 26, 2009 at 1:37 PM, Tomlinson, Gordon <
> GTOML...@overwatch.textron.com> wrote:
>
> > your triangles all need to be wound the same way (anticlockwise by
> > default for OSG & Opengl), whether or not your normal's are correct
> >
> > The easiest fix would be to ensure that your modeling package sets up
> > correct normal's before you get to OSG
> >
> > Assuming your triangles are wound the same way ( if not you will have to
> > fix that ) try using the SmoothingVistor on the data see
> >
> > include\osgUtil\SmoothingVisitor
> >
> >

> > *Gordon*
> >
> > __________________________________________________________
> > *Gordon Tomlinson*
> >
> > *Product Manager 3D
> > **Email * : gtomlinson @ overwatch.textron.com
> > __________________________________________________________
> > *(C): (+1) 571-265-2612
> > (W)**: (+1) 703-437-7651*


> >
> > "Self defence is not a function of learning tricks
> > but is a function of how quickly and intensely one
> > can arouse one's instinct for survival"

> > - *Master Tambo Tetsura*
> >
> >
> >
> > ------------------------------
> > *From:* osg-user...@lists.openscenegraph.org [mailto:
> > osg-user...@lists.openscenegraph.org] *On Behalf Of *alessandro
> > terenzi
> > *Sent:* Monday, January 26, 2009 7:09 AM
> > *To:* OpenSceneGraph Users
> > *Subject:* [osg-users] Rendering double-sided surfaces.

Tomlinson, Gordon

unread,
Jan 26, 2009, 10:42:26 AM1/26/09
to OpenSceneGraph Users
Have you tried using the osgUtil::SmoothingVistor on the model when its loaded ?
 
to see if this will solve your problem ?
 
rendering both sides will lead to a different set of unwanted artifacts
 
 
 
 

Gordon

__________________________________________________________
Gordon Tomlinson

Product Manager 3D
Email  : gtomlinson @ overwatch.textron.com
__________________________________________________________
(C): (+1) 571-265-2612
(W)
: (+1) 703-437-7651

"Self defence is not a function of learning tricks
but is a function of how quickly and intensely one
can arouse one's instinct for survival"
- Master Tambo Tetsura

 
 

From: osg-user...@lists.openscenegraph.org [mailto:osg-user...@lists.openscenegraph.org] On Behalf Of alessandro terenzi
Sent: Monday, January 26, 2009 10:22 AM
To: OpenSceneGraph Users
Subject: Re: [osg-users] Rendering double-sided surfaces.

Paul Martz

unread,
Jan 26, 2009, 11:42:49 AM1/26/09
to OpenSceneGraph Users
Yes, two sided lighting was what I was going to suggest, but you beat me to
it.

Note that two sided lighting is deprecated in OpenGL 3.0, so you should
consider looking for a shader-based solution instead. In the shader, if the
dot product of the normal and eye vector is negative, just negate it, then
calculate lighting as usual.

Paul Martz
Skew Matrix Software LLC
http://www.skew-matrix.com
+1 303 859 9466

-----Original Message-----
From: osg-user...@lists.openscenegraph.org
[mailto:osg-user...@lists.openscenegraph.org] On Behalf Of
frank...@jhmi.edu
Sent: Monday, January 26, 2009 8:44 AM
To: OpenSceneGraph Users

Subject: Re: [osg-users] Rendering double-sided surfaces.

alessandro terenzi

unread,
Jan 27, 2009, 2:45:31 PM1/27/09
to OpenSceneGraph Users
Thank you all for suggestions, I'll try them as soon as possible and will let you know.
Regards.
 
Alessandro

alessandro terenzi

unread,
Jan 28, 2009, 5:48:48 AM1/28/09
to OpenSceneGraph Users
My first try:
 
I created a SmoothingVistor and let it be accepted by my models, but every model looks always black, even if it is a 'correct' model (ie with all the faces oriented in the right way).
 
Maybe I need to 'normalize' normals after that visitor? Just a guess...I keep trying...
Alessandro


 

On Mon, Jan 26, 2009 at 1:37 PM, Tomlinson, Gordon <GTOML...@overwatch.textron.com> wrote:

alessandro terenzi

unread,
Jan 28, 2009, 6:37:24 AM1/28/09
to OpenSceneGraph Users
My second try:
 
I got/created a StateSet from my model root and then, as suggested by Frank, I did:
 
 osg::ref_ptr< osg::LightModel > pLightModel = new osg::LightModel();
 pLightModel->setTwoSided( true );
 pState->setAttributeAndModes( pLightModel.get(), osg::StateAttribute::ON );
 
Doing this solved the problem. I did not added also the material setting as in the Frank's example because my models already have materials and textures applied.
 
Paul said that this way to solve the problem is deprecated in OpenGL 3.0, but will it keep working anyway?
Thank you very much for helping.
Alessandro

Paul Martz

unread,
Jan 28, 2009, 12:18:51 PM1/28/09
to OpenSceneGraph Users
OpenGL features deprecated in 3.0 will still work in 3.0, but:
 * They might not be the optimal mechanism for what you are trying to accomplish -- better techniques exist. That's why it's deprecated; and...
 * Deprecated features might not work correctly when combined with new functionality; and finally...
 * Deprecated features might be removed in a future rev of OpenGL. At that point, the features might -- or might not -- still be available as an extension.
 
Paul Martz
Skew Matrix Software LLC
 

From: osg-user...@lists.openscenegraph.org [mailto:osg-user...@lists.openscenegraph.org] On Behalf Of alessandro terenzi
Sent: Wednesday, January 28, 2009 4:37 AM
To: OpenSceneGraph Users

Subject: Re: [osg-users] Rendering double-sided surfaces.

yann le paih

unread,
Jan 28, 2009, 1:18:29 PM1/28/09
to OpenSceneGraph Users
Hi,
       An other technique, if you don't have normals of the model :
                http://c0de517e.blogspot.com/2008/10/normals-without-normals.html
    
     I have the same probleme with CAO file.

yann,

   

_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




--
Yann Le Paih
Keraudrono
56150 BAUD
Portable: +33(0)610524356
lepai...@gmail.com
Reply all
Reply to author
Forward
0 new messages