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 

World space normal.


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Rowley, Marlin R
Guest





PostPosted: Wed Jul 11, 2018 1:18 pm    Post subject:
World space normal.
Reply with quote

I have a world space vertex computed as follows:

WorldVertex = osg_ViewMatrixInverse * gl_ModelViewMatrix * aVertex;

I would like to get the world space normal from this vertex. Is there an equivalent osg_* matrix that does the same thing?

I tried this:

NormalWorld = gl_NormalMatrix * gl_Normal;

But I know that is only putting the normal in view space.

----------------------------------------
Marlin Rowley
Software Engineer, Staff

Missiles and Fire Control
972-603-1931 (office)
214-926-0622 (mobile)
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)

------------------
Post generated by Mail2Forum
Back to top
shayne.tueller
Guest





PostPosted: Wed Jul 11, 2018 4:09 pm    Post subject:
World space normal.
Reply with quote

Shouldn't the normal be multiplied by the inverse transpose of the modelview matrix? (Only upper 3x3 portion)






Sent via the Samsung Galaxy S7 active, an AT&T 4G LTE smartphone



-------- Original message --------
From: "Rowley, Marlin R" <>
Date: 7/11/18 7:17 AM (GMT-07:00)
To: OpenSceneGraph Users <>
Subject: World space normal.




I have a world space vertex computed as follows:

WorldVertex = osg_ViewMatrixInverse * gl_ModelViewMatrix * aVertex;

I would like to get the world space normal from this vertex. Is there an equivalent osg_* matrix that does the same thing?

I tried this:

NormalWorld = gl_NormalMatrix * gl_Normal;

But I know that is only putting the normal in view space.

----------------------------------------
Marlin Rowley
Software Engineer, Staff
[img]content://com.samsung.android.email.attachmentprovider/1/705/RAW[/img]
Missiles and Fire Control
972-603-1931 (office)
214-926-0622 (mobile)
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)

------------------
Post generated by Mail2Forum
Back to top
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 11973

PostPosted: Wed Jul 11, 2018 4:27 pm    Post subject:
World space normal.
Reply with quote

Hi Marlin,

It can be done, but I strongly recommend that you don't go transforming vertex or normal data into world coordinates in the shader.  I know there are some published algorithms that do this but it's a really bad practice and you shouldn't follow it as precision issues on only proper dataset will cause mayhem - the do the cals in world coordinates only for datasets with a local origin, it's just a mess for any real-word datasets.


Cheers,
Robert.




  


On Wed, 11 Jul 2018 at 14:17, Rowley, Marlin R < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:

Quote:

I have a world space vertex computed as follows:
 
WorldVertex = osg_ViewMatrixInverse * gl_ModelViewMatrix * aVertex;
 
I would like to get the world space normal from this vertex.  Is there an equivalent osg_* matrix that does the same thing?
 
I tried this:
 
NormalWorld = gl_NormalMatrix * gl_Normal; 
 
But I know that is only putting the normal in view space.
 
----------------------------------------
Marlin Rowley
Software Engineer, Staff

Missiles and Fire Control
972-603-1931 (office)
214-926-0622 (mobile)
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
 

_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
gwaldron (Glenn Waldron)
Appreciator


Joined: 25 Aug 2011
Posts: 208

PostPosted: Thu Jul 12, 2018 1:22 pm    Post subject:
World space normal.
Reply with quote

Marlin,This might work:


vec3 normalWorld = mat3(osg_ViewMatrixInverse) * gl_NormalMatrix * gl_Normal;


But like Robert says, world coordinates on the GPU will lead to precision loss, so only do it if you are content with a low-precision result.
Glenn Waldron








On Wed, Jul 11, 2018 at 9:34 AM Rowley, Marlin R < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:

Quote:

I have a world space vertex computed as follows:
 
WorldVertex = osg_ViewMatrixInverse * gl_ModelViewMatrix * aVertex;
 
I would like to get the world space normal from this vertex.  Is there an equivalent osg_* matrix that does the same thing?
 
I tried this:
 
NormalWorld = gl_NormalMatrix * gl_Normal; 
 
But I know that is only putting the normal in view space.
 
----------------------------------------
Marlin Rowley
Software Engineer, Staff

Missiles and Fire Control
972-603-1931 (office)
214-926-0622 (mobile)
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
 

_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


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


Joined: 02 Nov 2011
Posts: 85

PostPosted: Thu Jul 12, 2018 1:40 pm    Post subject:
World space normal.
Reply with quote

Hi,
Was going to propose what Glenn already proposed. This should work with uniform scales on x,y,z coord. And IMHO that formula is more precise when dealing with normals than vertices. Thats because the precision issues are somewhat related to huge earth translation offsets in ModelView matrix. NormalMatrix and mat3(osg_ViewMatrixInvers) not include the translation offset part.



Cheers,
Wojtek Lewandowski


czw., 12 lip 2018 o 15:22 Glenn Waldron < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> napisał(a):

Quote:
Marlin,This might work:


vec3 normalWorld = mat3(osg_ViewMatrixInverse) * gl_NormalMatrix * gl_Normal;


But like Robert says, world coordinates on the GPU will lead to precision loss, so only do it if you are content with a low-precision result.
Glenn Waldron








On Wed, Jul 11, 2018 at 9:34 AM Rowley, Marlin R < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:

Quote:

I have a world space vertex computed as follows:
 
WorldVertex = osg_ViewMatrixInverse * gl_ModelViewMatrix * aVertex;
 
I would like to get the world space normal from this vertex.  Is there an equivalent osg_* matrix that does the same thing?
 
I tried this:
 
NormalWorld = gl_NormalMatrix * gl_Normal; 
 
But I know that is only putting the normal in view space.
 
----------------------------------------
Marlin Rowley
Software Engineer, Staff

Missiles and Fire Control
972-603-1931 (office)
214-926-0622 (mobile)
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
 

_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


------------------
Post generated by Mail2Forum
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 EXTERNAL: Re: World space normal. Rowley, Marlin R General 1 Wed Jul 11, 2018 4:30 pm View latest post
No new posts problem with picking/intersecting in ... mue General 1 Sat Jun 09, 2018 11:18 am View latest post
No new posts VBO Bug with 3.6.1 and Normal Arrays Daniel Emminizer, Code... General 21 Fri Jun 01, 2018 3:01 pm View latest post
No new posts How to get the normal of every triangle? Wangbingqian General [forum] 2 Mon Mar 19, 2018 1:53 am View latest post
No new posts How to get the triangle normal vector? Wangbingqian General 0 Fri Mar 16, 2018 1:07 pm 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