Normal Map, Tangent Binormal on Mirrored Objects
1 Attachment(s)
Dear Support,
I had a question regarding your calculation of tangent and binormal attributes for shaders. On my 3ds objects, to conserve texture space I am using symmetries. This causes the UV coordinates to be shared, but mirrored. When I bring the object into Vizard and use a Normal Map shader, I get every other symmetry (mirrored) element with reversed tangent and binormal attributes. I was wondering if you know of a fix for reversing the orientation of the tangent attribute, or if there might be a way for you to check in your automatic calculation ( I am guessing you use the texture coordinates for this) to determine if the sign of the normal is in the proper direction? Attached is an image of the problem, if I go into max and mirror the UVs back, it fixes the alternating problem. However, there are some assets that can not be mirrored (not symmetrical). Thanks, George |
How are you mirroring the UVs in Max? Are you using the Coordinates rollout in the material properties or are you mirroring the actual coordinates through the Edit UVWs dialog of the mesh?
The tangent/binormal calculation is based on the raw UV values, and does not take the texture tiling mode into account. So you should try to use the second method if you are not already doing so. |
1 Attachment(s)
The mirroring takes place when I use the symmetry modifier on the polygonal mesh. In this case, I created a high resolution mesh for 1/8th the roof of a cylindrical building.
I then use the symmetry modifier 3 times (rotating the modifier pivot each time), the first creates 1/4 of the roof, and then 1/2 and finally the entire roof. I had already UV Mapped the roof so that each symmetry would have the same UV coordinates, increasing the space available in the texture map. There is no tiling actually occurring, all UVs are within the 0 to 1 area. Attached is an image of the UVs, with a selection made to show how they are mirrored across the 3D object. |
After reading a while on Normal maps for other engines, I found that this is a common problem when the attributes do not contain a 4th 'W' component indicating mirrored portions of the mesh. Apparently, other engines such as Unreal and CryEngine are able to determine the flipped normals and have them flipped by multiplying by the W coordinate ( +1 or -1).
Fixes for other engines (Unity in this case) referred to exporting the binormal and tangent vectors through the FBX file format. In this case, I don't see anything that can be similarly done with the OSG exporter. |
Do you mind posting your vertex/fragment shader code? I tried applying a normal map to a model with mirrored UVs and it seemed to work correctly.
|
1 Attachment(s)
I went ahead and attached the model and textures.
Thanks, George Vertex: Code:
#version 120 Code:
#version 120 |
Thanks. I think the problem is with your normal map lookup code. The texture color values range from 0 to 1. However, the normals need to range from -1 to 1. Also, it appears the green channel in your normal map is flipped. Try modifying your normal map lookup to the following:
Code:
vec3 texNormal = normalize(texture2D(NormalMap, gl_TexCoord[0].xy).rgb * 2.0 - 1.0) * vec3(1.0,-1.0,1.0); |
Wow, I must have hit undo at some point in my code because I remember renormalizing the normal map from -1 to +1 ... but it sure isn't in that code...
I'll give your tips a try. Not sure why the green channel is flipped, I'll look into that as well. Thanks for your great support, ~George |
All times are GMT -7. The time now is 08:16 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC