Results 1 to 2 of 2

Thread: Normal Mapping and Lighting space confusion

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2014
    Posts
    13

    Normal Mapping and Lighting space confusion

    Hi all, I'm trying to implement normal mapping but I'm confused with which space to use.

    Up to now I'm doing all the light calculation in view space as I'm doing this:

    VERTEX SHADER
    Code :
     
    	passedPosition = modelViewMatrix*vec4(vertexPosition,1.0);

    FRAGMENT SHADER
    Code :
    ........
     
         vec3 Ldist = passedPosition .xyz - lights[i].lightPosition.xyz;
         vec3 L = normalize(Ldist); 
     
    ........

    Now, I was reading this: http://www.gamasutra.com/blogs/Rober...ed.php?print=1

    for normal mapping. For how my thing is structured I can't access (without messing something and I'll like to avoid this option) light directions in the vertex shader.
    So to actually do what is explained in the section View Space Normal Mapping of the above link I should pass onto the fragment shader the TBN matrix and then transform the light direction in there. But is this someway avoidable? Can you point me to an alternative way to do this maintaining the structure I already have (that is at the beginning of the post)? I'm a bit confused at the moment. Sorry if this topic is confusionary aswell

  2. #2
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896
    I'm not sure why your vertex shader would not have access to the light direction uniforms, after all uniforms are set on the program object not the shader object, so all shader stages should have access to the same set of uniforms (you just need to declare them in each stage) - perhaps I'm missing something?
    Other than that, I think you'll have to do one of the two things: transform the light direction to tangent space in the vertex shader or enable the fragment shader to do that transformation (i.e. pass the TBN matrix to it) - and from a performance POV it seems preferable to do the former.

Similar Threads

  1. Lighting errors with normal mapping
    By CDeniz in forum OpenGL: GLSL
    Replies: 3
    Last Post: 02-04-2015, 06:41 AM
  2. dot3 normal mapping and per-pixel lighting?
    By bansheeogl in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 06-07-2005, 04:11 AM
  3. Ambient lighting with multitexture normal mapping.
    By imported_billw in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 05-10-2005, 12:18 PM
  4. normal mapping in whatever space
    By LiquidFlare in forum OpenGL: Advanced Coding
    Replies: 27
    Last Post: 07-27-2004, 02:19 PM
  5. what is the fastest algorithm for mapping texture space to file space?
    By wildeyedboyfromfreecloud in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 03-06-2002, 08:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean