OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Mirror transformation


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Ale
User


Joined: 26 Nov 2012
Posts: 45

PostPosted: Wed Sep 13, 2017 12:52 pm    Post subject:
Mirror transformation
Reply with quote

Hi,

this is probably a trivial question but what is the most straithforward way to mirror a node?
I would like to use a MatrixTransformation so I simply set a negative scaling but the resulting node is totally black.
Is it the expected result or did I miss something?
I thought it was usefull to set GL_RESCALE_NORMAL mode but anything changed.
Any suggestion?

My scene is built as follow:

Group->ClipNode->osgShadow::ShadowedScene->Group->MatrixTransformation->Group->MatrixTransformation (MIRROR)->osgFX::Outline->Geode

The last geode is visualized completely black.
I exported the scene in osg format and opened with osgviewer and the geode is still black

Thank you. Best regards.
Ale
Back to top
View user's profile Send private message
Ale
User


Joined: 26 Nov 2012
Posts: 45

PostPosted: Wed Sep 13, 2017 2:23 pm    Post subject:
Reply with quote

I forgot to mention that the geode inherit from the root node a 2-sided lighting with different materials in front and back side.

Cheers,
Ale
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 11152

PostPosted: Wed Sep 13, 2017 3:13 pm    Post subject:
Mirror transformation
Reply with quote

Hi Ale,


You have several layers of different of effects that you are decorating your subgraph with - ClipNode, ShadowedScene, osgFX::Outline, I haven't come across anyone using such a combination before so it could be that some interaction is at play, none of these nodes are written with the others in mind so this could be something that is having an effect.


Personally I'd strip back the scene graph so it's nice and simple, try you flip of the matrix to do the mirror and apply the rescale normal and see how you get on, then add the extra layers of complexity.


I do wonder though whether all these layers are required, or even appropriate.  I know nothing about our application so can't provide an guidance on how one would normally implement what you require.


Robert.

------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Gianluca Natale
Guest





PostPosted: Wed Sep 13, 2017 3:21 pm    Post subject:
Mirror transformation
Reply with quote

IMO, it happens that, because of the mirror transformation (i.e. a negative scale factor in the global transformation),
back facets do appear as front facets on the projection plane, and viceversa.
And because of the 2-sided model lighting, normals are reverted when rendering the front facets (as they appear as back facets).
It should be fixed by reverting the front face definition for object transformed by the mirror transform.
I mean, I would apply a state set to that mirror transformation with this state attribute:

osg::FrontFace(CLOCKWISE);

It worked for me for a similar issue I had in the past.

Gianluca


-----Original Message-----
From: osg-users [mailto:] On Behalf Of Ale Maro
Sent: Wednesday, September 13, 2017 4:23 PM
To:
Subject: Re: Mirror transformation

I forgot to mention that the geode inherit from the root node a 2-sided lighting with different materials in front and back side.

Cheers,
Ale

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








------------------
Post generated by Mail2Forum
Back to top
Ale
User


Joined: 26 Nov 2012
Posts: 45

PostPosted: Wed Sep 13, 2017 3:51 pm    Post subject:
Reply with quote

Hi Robert,

thank you for the quick answer.

I use this scene graph structure to set some standard rendering features to scene objects... so it is not easy to change it for me.
Anyway I tried to export the scene in osg format and change manually all groups that can give problems (clipnode, outline, shadow) to simple "Group".
After loading the modified file with osgviewer the result is the same the object is black.
I see now that moving the object (so light intersect the object with a different angle) the object is still dark but I can see the interior material (instead of exterior one)

So I guess if the solution is to reverse vertices, normals and primitive set or do you expect it works just using transformations?

And also... you said "apply the rescale normal". I apply it using a stateset. Do I have to refresh in some way the normals or it is done automatically after set the parent transformation to the mirror?


Ale
Back to top
View user's profile Send private message
Ale
User


Joined: 26 Nov 2012
Posts: 45

PostPosted: Wed Sep 13, 2017 5:11 pm    Post subject:
Reply with quote

Hi Gianluca,

I tried your suggestion and it worked.
It is a little tricky for me becouse I need to analyze on the fly the transformation matrix and apply osg::FrontFace by consequence.... but it works.

Thank you.

Ale
Back to top
View user's profile Send private message
Gianluca Natale
Guest





PostPosted: Wed Sep 13, 2017 5:26 pm    Post subject:
Mirror transformation
Reply with quote

Happy to hear that it works.

BTW, actually the check is a bit more complicated, because you might want to apply mirroring against several axes in sequence.
Once you have the global transformation of the mirrored object, the correct check is the following.
Get the determinant of that global transformation, and check the sign:
- if < 0.0, it means that there is an odd number of negative scale factors in the matrix, so winding has to be reverted: set FrontFace mode to CLOCKWISE;
- if > 0.0, it means that there is no or an even number of negative scale factors, so winding has to be left as COUNTERCLOCKWISE.
Just for completeness.

Gianluca


-----Original Message-----
From: osg-users [mailto:] On Behalf Of Ale Maro
Sent: Wednesday, September 13, 2017 7:12 PM
To:
Subject: Re: Mirror transformation

Hi Gianluca,

I tried your suggestion and it worked.
It is a little tricky for me becouse I need to analyze on the fly the transformation matrix and apply osg::FrontFace by consequence.... but it works.

Thank you.

Ale

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








------------------
Post generated by Mail2Forum
Back to top
Ale
User


Joined: 26 Nov 2012
Posts: 45

PostPosted: Thu Sep 14, 2017 6:31 am    Post subject:
Reply with quote

Hi,

yes, I can have mirror on each axis so I have already implemented a check similar to the one you suggested.
Thank you for the clarification.

Ciao,
Ale
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 11152

PostPosted: Thu Sep 14, 2017 7:43 am    Post subject:
Mirror transformation
Reply with quote

Hi Ale,

On 13 September 2017 at 16:51, Ale Maro < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
I use this scene graph structure to set some standard rendering features to scene objects... so it is not easy to change it for me.
Anyway I tried to export the scene in osg format and change manually all groups that can give problems (clipnode, outline, shadow) to simple "Group".
After loading the modified file with osgviewer the result is the same the object is black.
I see now that moving the object (so light intersect the object with a different angle) the object is still dark but I can see the interior material (instead of exterior one)

So I guess if the solution is to reverse vertices, normals and primitive set or do you expect it works just using transformations?



I can only speculate on what the problem you are having is, it's really open ended as you've put together some many different effects.  You can see things first hand and are best place to work this out.  It could be lighting, it could be back face culling, it could be an interaction with the depth texture or shaders.


With convoluted combinations like these I generally find it's best to take a big step back and try to work out what effects you are trying to achieve and then work out what technique is most appropriate rather than try to fix and convoluted and possibly misguided approach.


I expect the best solution for your applicaton is not to combine ClipNode/osgShadow and osgFX all together, but to come up with your own custom shader and multipass approach.  This might require a bit more intial understanding of shaders and rendering techniques but will provide much greater flexibility, performance and maintainability long term.



Robert.

------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Ale
User


Joined: 26 Nov 2012
Posts: 45

PostPosted: Thu Sep 14, 2017 1:10 pm    Post subject:
Reply with quote

Hi Robert,

I tried to simplify the scene graph (no shadow, effects, textures, shaders...) and the problem was still there.
I originally disabled back face culling since I have 2-sided lighting with different material.

So I supposed it is the expected behaviour for mirrored nodes and I try add some code to adjust the result.

With mirroring the direction of face normals changes so I first tried to update all normals (hoping they are also used to distinguish front and back face) but it did not work.
I thought to revert all faces directions changing primitive sets but this means to change the geometry and it is not so straightforward.

Reverting faces using statesets works fine....
it is not ideal becouse I always need to check the matrix and also I need to recourse all children of a mirrored node to apply the FrontFace state (becouse children can have a transformation that reset the mirroring).

If you have any other suggestion please let me know.

I will also go in depth with your suggestion to use a multipass shader to avoid multiple effect groups. Thank you.
I still have some issues with multipass shaders due to interaction with Qt... but I will try to go to this direction.

Ale
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts status of git mirror scrawl General 1 Thu Nov 05, 2015 1:47 pm View latest post
No new posts How to convert osg::Node to osg::Matr... mg969 General 4 Tue Mar 17, 2015 5:24 pm View latest post
No new posts Precise world to screen space transfo... Ben Morgan General 1 Mon Sep 29, 2014 10:12 am View latest post
No new posts Weird rendering results after Matrix ... Bacttrack General 1 Wed Jul 23, 2014 6:11 am View latest post
No new posts osg's git-mirror out of sync Stephan Maximilian Huber General 0 Mon May 05, 2014 7:52 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP