Re: [osg-users] TBN Matrix for Normal Mapping - OSG and GLSL
Hi Rômulo, On 8 November 2017 at 21:46, Rômulo Cerqueira wrote: > thanks for your replies. I will have a look on osg::TangentSpaceVisitor, > however I have a question: I will have in my OSG scene a lot of objects > with/without normal mapping. How can I handle different normal textures using > the same osg::TangentSpaceVisitor? To tailor the behavior to suit your scene graph usage case you could subclass from the TengentSapceVisitor and add your own checks for traversal. Robert. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] TBN Matrix for Normal Mapping - OSG and GLSL
Hi Jordi and Sebastian, thanks for your replies. I will have a look on osg::TangentSpaceVisitor, however I have a question: I will have in my OSG scene a lot of objects with/without normal mapping. How can I handle different normal textures using the same osg::TangentSpaceVisitor? ... Thank you! Cheers, Rômulo -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=72339#72339 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] TBN Matrix for Normal Mapping - OSG and GLSL
Ouch bad link: https://github.com/openscenegraph/OpenSceneGraph/blob/master/src/osgPlugins/gles/TangentSpaceVisitor.cpp#L46 this one is the right one! 2017-11-08 9:19 GMT+01:00 Jordi Torres : > Hi Romulo, > > You can use TangentSpaceGenerator to get the values of the T B and N. Here > you have a code example: https://github.com/sketchfab/osg/blob/ > 5d35b2a2d55e92b4c736ea5edcd9eeedf9ea6786/src/osgPlugins/ > gles/TangentSpaceVisitor.cpp#L46 > > Cheers. > > 2017-11-07 21:48 GMT+01:00 Rômulo Cerqueira : > >> Hi, >> >> I have used normal mapping using GLSL and OSG for my application (an >> imaging sonar simulation) and I got problems by calculating the TBN matrix >> on shaders. The normal vectors contain lower resolution on border in >> comparison with the center of image. >> >> Follows my vertex code: >> >> Code: >> >> #version 130 >> >> out vec3 pos; >> out vec3 normal; >> out mat3 TBN; >> >> void main() { >> pos = (gl_ModelViewMatrix * gl_Vertex).xyz; >> normal = gl_NormalMatrix * gl_Normal.xyz; >> >> vec3 n = normalize(normal); >> vec3 t = normalize(cross(normal, vec3(-1,0,0))); >> vec3 b = cross(t, n) + cross(n, t); >> TBN = transpose(mat3(t,b,n)); >> >> gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; >> gl_TexCoord[0] = gl_MultiTexCoord0; >> } >> >> >> >> >> Part of my fragment code: >> >> Code: >> >> #version 130 >> >> in vec3 pos; >> in vec3 normal; >> in mat3 TBN; >> uniform sampler2D normalTexture; >> >> void main() { >> vec3 newNormal = (texture2D(normalTexture, gl_TexCoord[0].st).rgb * >> 2.0 - 1) * TBN; >> newNormal = normalize(newNormal); >> ... >> } >> >> >> >> >> The resulting figure is attached. >> >> How can I calculate the TBN matrix to compute the normal mapping properly? >> >> Thanks in advance, >> >> >> ... >> >> Thank you! >> >> Cheers, >> Rômulo[/img] >> >> -- >> Read this topic online here: >> http://forum.openscenegraph.org/viewtopic.php?p=72324#72324 >> >> >> >> >> Attachments: >> http://forum.openscenegraph.org//files/screenshot_from_2017_ >> 11_06_23_00_48_832.png >> >> >> ___ >> osg-users mailing list >> osg-users@lists.openscenegraph.org >> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org >> > > > > -- > Jordi Torres > > > -- Jordi Torres ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] TBN Matrix for Normal Mapping - OSG and GLSL
Hi Romulo, You can use TangentSpaceGenerator to get the values of the T B and N. Here you have a code example: https://github.com/sketchfab/osg/blob/5d35b2a2d55e92b4c736ea5edcd9eeedf9ea6786/src/osgPlugins/gles/TangentSpaceVisitor.cpp#L46 Cheers. 2017-11-07 21:48 GMT+01:00 Rômulo Cerqueira : > Hi, > > I have used normal mapping using GLSL and OSG for my application (an > imaging sonar simulation) and I got problems by calculating the TBN matrix > on shaders. The normal vectors contain lower resolution on border in > comparison with the center of image. > > Follows my vertex code: > > Code: > > #version 130 > > out vec3 pos; > out vec3 normal; > out mat3 TBN; > > void main() { > pos = (gl_ModelViewMatrix * gl_Vertex).xyz; > normal = gl_NormalMatrix * gl_Normal.xyz; > > vec3 n = normalize(normal); > vec3 t = normalize(cross(normal, vec3(-1,0,0))); > vec3 b = cross(t, n) + cross(n, t); > TBN = transpose(mat3(t,b,n)); > > gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; > gl_TexCoord[0] = gl_MultiTexCoord0; > } > > > > > Part of my fragment code: > > Code: > > #version 130 > > in vec3 pos; > in vec3 normal; > in mat3 TBN; > uniform sampler2D normalTexture; > > void main() { > vec3 newNormal = (texture2D(normalTexture, gl_TexCoord[0].st).rgb * > 2.0 - 1) * TBN; > newNormal = normalize(newNormal); > ... > } > > > > > The resulting figure is attached. > > How can I calculate the TBN matrix to compute the normal mapping properly? > > Thanks in advance, > > > ... > > Thank you! > > Cheers, > Rômulo[/img] > > -- > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=72324#72324 > > > > > Attachments: > http://forum.openscenegraph.org//files/screenshot_from_ > 2017_11_06_23_00_48_832.png > > > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > -- Jordi Torres ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] TBN Matrix for Normal Mapping - OSG and GLSL
Hi Rômulo, Hi, I have used normal mapping using GLSL and OSG for my application (an imaging sonar simulation) and I got problems by calculating the TBN matrix on shaders. The normal vectors contain lower resolution on border in comparison with the center of image. You cannot get a valid Co-TangentSpace by taking only the normal into account considering arbitrary geometries. There are multiple ways to tackle this however: First is to calculate the mesh's tangentspace beforehand and pass the tangent and binormal via vertex attributes. See the osgUtil::TangentSpaceGenerator (example in the osg::CookBook AFAIK). Second one is to calculate it in the view-space. Beware of dragons, since the precision will be awful for big coordinates: http://www.thetenthplanet.de/archives/1180 hth Sebastian Follows my vertex code: Code: #version 130 out vec3 pos; out vec3 normal; out mat3 TBN; void main() { pos = (gl_ModelViewMatrix * gl_Vertex).xyz; normal = gl_NormalMatrix * gl_Normal.xyz; vec3 n = normalize(normal); vec3 t = normalize(cross(normal, vec3(-1,0,0))); vec3 b = cross(t, n) + cross(n, t); TBN = transpose(mat3(t,b,n)); gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; gl_TexCoord[0] = gl_MultiTexCoord0; } Part of my fragment code: Code: #version 130 in vec3 pos; in vec3 normal; in mat3 TBN; uniform sampler2D normalTexture; void main() { vec3 newNormal = (texture2D(normalTexture, gl_TexCoord[0].st).rgb * 2.0 - 1) * TBN; newNormal = normalize(newNormal); ... } The resulting figure is attached. How can I calculate the TBN matrix to compute the normal mapping properly? Thanks in advance, ... Thank you! Cheers, Rômulo[/img] -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=72324#72324 Attachments: http://forum.openscenegraph.org//files/screenshot_from_2017_11_06_23_00_48_832.png ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org