Results 1 to 9 of 9

Thread: Normal mapping

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2017
    Posts
    9

    Question Normal mapping

    So i have a vector, a surface normal, pointing away from the surface. i also have a vector, sampled from a normal map, indicating the normal vector of that fragment.
    now i want the normal map vectors y axis to go along the surface normal.
    for example: i have up-pointing normal map vector vec3(0.0, 0.8, 0.3) and my surface normal vec3(0, 0, 1). now i want to "rotate" my mapped vector, so it would result in vec3(0.0, 0.3, 0.8).
    how would i have to calculate it, that it works with any two vectors???

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,105
    To use a normal map, you need a tangent vector for each point on the surface, as well as a normal vector. Otherwise, there's simply no way to interpret the normals from the normal map. E.g. consider the vectors (0,0.5,0.866) and (0.5,0,0.866). Each of those deviates from the normal by 30 degrees, but one deviates along the X axis, the other along the Y axis. What does that mean in terms of the final normal vector?

    Once you have a surface normal vector N and tangent vector T, you can derive a bitangent vector B=NT, which is guaranteed to be perpendicular to N, and regenerate the tangent T'=BN, which is guaranteed to be perpendicular to both, so T,B,N form an orthogonal basis. Then, given a surface-space (tangent-space) vector V from the normal map, the object-space vector V'=Vx*T+Vy*B+Vz*N (i.e. V'=M*V, where M is a matrix whose columns are T,B,N).

    If you're generating the normal map for a specific surface e.g. based upon a higher-detail version of the surface, it doesn't particularly matter how you assign tangents. If you're tiling a normal map as a pattern, then you typically want the tangents to have a constant direction in texture space, so you'd use the tangent to lines of constant S or T. In the latter case, you can determine the tangent vector at a vertex by considering the difference in texture coordinates between that vertex and adjacent vertices.

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2017
    Posts
    9
    I have tried using tangent vectors before, and doing all my calculations in tangent space. allthough this just causes problems with my code, and wont work for what i am doing.
    i have thought of getting the x, y and z rotation values between the surface vector, and an uppointing vector. this would give me values to rotate the normal map vector by, beacuse a normap map vector is aligned to the y axis.
    so:
    i take the x, y and z rotational difference between surface and vec3(0,1,0) to get the rotations i need
    then use rotation matrices to rotate the normal map vector according to the values i have.
    use that as normal vector.

    my problem is:
    how would i get these rotation values?

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,105
    You need more than one vector. Three coordinates require three axes, which requires at least two vectors (their cross product gives you a third which is guaranteed to be perpendicular to the other two).

    If you're trying to navigate using coordinates, knowing which way is up doesn't help. You also need to know which direction is north (or east, or whatever).

  5. #5
    Junior Member Newbie
    Join Date
    Mar 2017
    Posts
    9
    Quote Originally Posted by GClements View Post
    You need more than one vector. Three coordinates require three axes, which requires at least two vectors (their cross product gives you a third which is guaranteed to be perpendicular to the other two).
    i have two vectors: the y-axis vector(0, 1, 0), and the surface normal. now i want to determine the angles on x y and z between those. maybe you are meaning something else with
    Quote Originally Posted by GClements View Post
    You need more than one vector.

  6. #6
    Junior Member Newbie
    Join Date
    Mar 2017
    Posts
    9
    still not working! help!

  7. #7
    Junior Member Newbie
    Join Date
    Mar 2017
    Posts
    9

    Unhappy help

    I now have this:
    Code :
            vec3 u = vec3(0, 0, 1);
    	vec3 v = unit_surface;
    	float xangle = acos(dot(u.yz, v.yz));
    	float yangle = acos(dot(u.xz, v.xz));
    	float zangle = acos(dot(u.xy, v.xy));
     
    	mat3 xrot;
    	mat3 yrot;
    	mat3 zrot;
    	RotMatX(xangle, xrot);
    	RotMatY(yangle, yrot);
    	RotMatZ(zangle, zrot);
     
    	vec3 normal_mapped = unit_normalmap * xrot * yrot * zrot;

    i noticed that the x, y and zangle variables represent incorrect values!
    how do i get these?!?!?!?
    please help!!!!!!

  8. #8
    Senior Member Regular Contributor
    Join Date
    May 2016
    Posts
    112
    Not sure if this is helpful. I only briefly read through the thread and I haven't done any normal mapping code in over a year and don't have any code examples handy I can show. So, I didn't have really anything helpful to add. But there might be some articles out there that explain the whole process and shed some light on the issue.

    https://learnopengl.com/#!Advanced-L...Normal-Mapping

    I think you have to calculate a tangent and a bitangent that align with the texture's UV coordinates on the surface of the triangle you are drawing, from what I can recall. I believe the normal map itself is an offset from the triangle's face normal for each pixel. At least, that's what I recall off the top of my head.

  9. #9
    Junior Member Newbie
    Join Date
    Mar 2017
    Posts
    9
    Quote Originally Posted by BBeck1 View Post
    Not sure if this is helpful. I only briefly read through the thread and I haven't done any normal mapping code in over a year and don't have any code examples handy I can show. So, I didn't have really anything helpful to add. But there might be some articles out there that explain the whole process and shed some light on the issue.

    https://learnopengl.com/#!Advanced-L...Normal-Mapping

    I think you have to calculate a tangent and a bitangent that align with the texture's UV coordinates on the surface of the triangle you are drawing, from what I can recall. I believe the normal map itself is an offset from the triangle's face normal for each pixel. At least, that's what I recall off the top of my head.
    this is indeed a way of doing it. but in my case, tangent vectors wont work. that is why i am trying to rotate the vector by the amount the surface vector if off by the z axis.

Similar Threads

  1. opengl bump mapping (normal mapping) problem with VBO and GLSL
    By emrekaya413 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-29-2018, 03:52 AM
  2. Is this normal mapping done right?
    By mantilope in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 06-28-2015, 02:27 PM
  3. help with normal mapping
    By Bonanza in forum OpenGL: GLSL
    Replies: 3
    Last Post: 04-30-2008, 12:42 AM
  4. normal mapping
    By nk in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 09-29-2004, 05:11 AM
  5. normal mapping
    By imported_titan in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 01-08-2004, 03:06 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