Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Assimp and adventures in calculating tangent space - strange "seams" visible

This topic is 1353 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I've been experimenting with and trying to render the dubrovnik/crytek sponza using opengl and assimp 3.0. I load the mesh with the aiProcess_CalcTangent space flag to create tangents and bitangents for normal maps. However there seem to be odd "seams" in some of the meshes' calculated tangents and bitangents.


When debugging by using the bitangent or tangent value at the rendered pixel the seams can be seen. Outputting normals produces no seams.


Of course, when creating the tangent space matrix and multiplying the normals from the normal map this means the seam still appears - here is a screenshot of the mesh being coloured using the transformed normal from the normal map. You can see the seam in the top-middle of the image.

The walls are both facing the same direction but have different normals.


Some code, in case that's the problem. I feel I must be doing something wrong with the process flags for importing the mesh though.


//The Flags used for the assimp import are the right most parameters InitStaticMesh(m_sponzaMesh, "sponza.obj", "meshes\\sponza_obj\\", aiProcess_Triangulate | aiProcess_CalcTangentSpace);


And the glsl (to output transformed normals)

in vec3  normal;
in vec3  tangent;
in vec3  bitangent;
in vec3  eyeVec;
in vec2  UVs;
out vec4 color;

void main(){
    //create TBN matrix
    mat3 TBNMatrix = mat3(normalize(tangent),normalize(bitangent),normalize(normal));

    vec3  norm;	

    //if normalmap used, read the normal value and transform it
    //otherwise just use the normal read in from the mesh			  
        norm = normalize(TBNMatrix * texture2D(bumpMap,UVs).xyz);
        norm = normalize(normal);

    //lighting stuff
    vec3  normalizedLight = normalize(-lightDir);
    vec3  halfVec         = normalize((normalizedLight + normalize(eyeVec)));
    vec3  spec	          = pow(max(dot(halfVec,norm),0.0),materialShininess) * texture2D(specMap,UVs).xyz;
    vec3  diffCon	  = max(dot(norm,normalizedLight),0.0) * materialDiffuse;

    vec3 lighting =  lightCol * ( diffCon  + spec + 0.5 * materialAmbient);

    vec3 newCol   =   lighting * texture2D(tex,UVs).xyz;

    //if mask being used look up the val - discard fragment if not needed
    if(useAlphaMap &&  texture2D(alphaMap,UVs).r < 0.2){

    color = vec4(newCol,1.0);

Share this post

Link to post
Share on other sites
You didn’t unpack the normals from the normal map.
vec3 vUnpacked = texture2D(bumpMap,UVs).xyz;
vUnpacked.xy = vUnpacked.xy * 2.0 - 1.0;

L. Spiro Edited by L. Spiro

Share this post

Link to post
Share on other sites

As a post-script to this issue, I am now doing a deferred render of the sponza with many point lights. When creating my gbuffer and writing the normals to a render target, I unpack the normal map, multiply by the TBN matrix, and then pack it again before writing to the g buffer like so


mat3 TBN = mat3(tangents,biTangents,normals);
  vec3 normalMapNormal =  texture2D(normalMap,UVs).xyz; 
  normalMapNormal = 2.0 * normalMapNormal - 1.0;
  //normalsOut writes to the rendertarget
  normalsOut.xyz   = (normalize(TBN * normalMapNormal) + 1.0) * 0.5;


Then in the lighting pass I do the following, but it seems the seams are back when I debug using the fragment output

vec3 norm     = normalize(texture2D(normal,texCoord).xyz * 2.0 - 1.0);

Share this post

Link to post
Share on other sites

^ The above has been sorted, there were surfaces without normal maps that were having garbage written to the normal buffer. To fix it I just tested if there was a normalMap for the mesh and if not just pack + use the vertex normal

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!