Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7511175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:27:59+00:00 2026-05-29T23:27:59+00:00

I have a normal map in my OpenGL game engine and I realized that

  • 0

I have a normal map in my OpenGL game engine and I realized that my normal map shader (and parallax map shader for that matter) have a problem with the lighting. Regardless of where the light is,the light always comes from the right. I am using a tangent space shader and I’m not sure if what I am passing in is correct.

This is the Normal Map That I Am Using:
The Normal Map I am using

And here is the render:

Rendered Image

The light appears to be coming from the coordinate 3,0,3 but its actual location is -3,0,3

Any Ideas.

Shaders:

[vert]

attribute vec3 intan;

varying vec3 lightDir;
varying vec3 viewDir;

void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;

vec3 vertexPos = vec3(gl_ModelViewMatrix * gl_Vertex);

vec3 n = normalize(gl_NormalMatrix * gl_Normal);
vec3 t = normalize(gl_NormalMatrix * intan);
vec3 b = cross(n, t) ;

mat3 tbnMatrix = mat3(t.x, b.x, n.x,
                      t.y, b.y, n.y,
                      t.z, b.z, n.z);

lightDir = (gl_LightSource[1].position.xyz - vertexPos) / 1000.;
lightDir = tbnMatrix * lightDir;

viewDir = -vertexPos;
    //viewDir = 
viewDir = tbnMatrix * viewDir;
}

[frag]

uniform sampler2D tex;
uniform sampler2D nor;

varying vec3 lightDir;
varying vec3 viewDir;

const vec4 d = vec4(0.19225,0.19225,0.19225,1.0);
const vec4 a = vec4(0.50754,0.50754,0.50754,1.0);
const vec4 s = vec4(0.508273,0.508273,0.508273,1.0);

void main()
{
vec3 l = lightDir;
float atten = max(0.0, 1.0 - dot(l, l));

l = normalize(l);

vec3 n = normalize(texture2D(nor, gl_TexCoord[0].st).xyz * 2.0 - 1.0);
vec3 v = normalize(viewDir);
vec3 h = normalize(l + v);

float nDotL = max(0.0, dot(n, l));
float nDotH = max(0.0, dot(n, h));
float power = (nDotL == 0.0) ? 0.0 : pow(nDotH, gl_FrontMaterial.shininess);

vec4 ambient = a * atten;
vec4 diffuse = d * nDotL * atten;
vec4 specular = s * power * atten;
vec4 color = ambient + diffuse + specular;

gl_FragColor = color * texture2D(tex, gl_TexCoord[0].st);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:28:01+00:00Added an answer on May 29, 2026 at 11:28 pm
    vec3 n = normalize(gl_NormalMatrix * gl_Normal);
    vec3 t = normalize(gl_NormalMatrix * intan);
    vec3 b = cross(n, t) ;
    

    I suppose intan designates the direction in which the normal map “right” points. Then that cross product is wrong. If n points out of the surface and intan to the right, then b(inormal) points downwards.

    Note that it makes no difference if you transform normal and tangent and then do the crossproduct of the result or do the crossproduct first and transform the result.

    lightDir = (gl_LightSource[1].position.xyz – vertexPos) / 1000.;

    Why don’t you just normalize that? That division by 1000 doesn’t make sense.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a normal map in opengl that I can load
While developing a game I have designed a class that in normal operation has
If I have a texture, is it then possible to generate a normal-map for
I have a normal asp.net page containing some code that I want to measure
I have read that 'Normal' ARM instructions are fixed length - 32 bits. And
Is it normal to have tests that are way bigger than the actual code
I have been looking to map a new operator in Vim that takes an
I have a static std::map<std::string, CreateGUIFunc> in a class that basically holds strings identifying
I have a map that is not displaying. The page loads all the controls
I have a normal joining table with two columns that are keys to other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.