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 6797765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:38:57+00:00 2026-05-26T18:38:57+00:00

So, it helps to transform everything to eye space before doing lighting calculations? I’m

  • 0

So, it helps to transform everything to eye space before doing lighting calculations? I’m having trouble with the transforming part. I’ve got the normals transformed right, but when I apply translations (when the object is not in the center of the world coordinate system), the lighting remains exactly the same.

I have confirmed that there are no problems with any C++ code.
I will paste my shaders…

QUESTION: I would like to know what I’m not transforming right, and how I’m supposed to transform it.

vertex shader…

const int MAXLIGHTS = 4;

uniform int lightcount;
uniform vec4 lPositions[MAXLIGHTS];

//V = transformed vertex
//N = transformed normal
//E = eye vector
//L = vector from vertex to light
varying vec3 V, N, E, L[MAXLIGHTS];

void main()
{
    int lcount = lightcount > MAXLIGHTS ? MAXLIGHTS : lightcount;

    V = vec3(gl_ModelViewMatrix * gl_Vertex);

    N = gl_NormalMatrix * gl_Normal;

    E = normalize(-V);

    for(int i = 0; i < lcount; i++)
    {
        L[i] = gl_NormalMatrix * normalize(vec3(lPositions[i] - gl_Vertex));
    }

    gl_FrontColor = gl_Color;
    gl_Position = ftransform();
}

fragment shader…

const int MAXLIGHTS = 4;

uniform int lightcount;
uniform vec4 lDiffuses[MAXLIGHTS];
uniform vec4 lAmbients[MAXLIGHTS];

varying vec3 V, N, E, L[MAXLIGHTS];
uniform bool justcolor;

void main()
{
    if(justcolor)
    {
        gl_FragColor = gl_Color;
        return;
    }
    int lcount = lightcount > MAXLIGHTS ? MAXLIGHTS : lightcount;

    vec4 ambient;
    vec4 diffuse;
    vec4 specular = vec4(0.0, 0.0, 0.0, 0.0);
    vec4 color = vec4(0.0, 0.0, 0.0, 1.0);

    vec3 H;
    float NL;
    float NH;

    for(int i = 0; i < lcount; i++)
    {
        specular = vec4(0.0, 0.0, 0.0, 0.0);

        ambient = lAmbients[i];

        NL = dot(N, L[i]);
        diffuse = lDiffuses[i] * max(NL, 0.0);

        if(NL > 0.0)
        {
            H = normalize(E + L[i]);
            NH = max(0.0, dot(N, H));
            specular = pow(NH, 40.0) * vec4(0.3, 0.3, 0.3, 1.0);
        }

        color += gl_Color * (diffuse + ambient) + specular;
    }

    gl_FragColor = color;
}
  • 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-26T18:38:58+00:00Added an answer on May 26, 2026 at 6:38 pm
    L[i] = gl_NormalMatrix * normalize(vec3(lPositions[i] - gl_Vertex));
    

    This code only makes sense if lPositions is in model space. And that’s highly unlikely.

    The general way this works is that you pass light positions in eye space, so there’s no need to transform them.

    Also, L and E are entirely superfluous. You will get more accurate results by computing these in the fragment shader. The computations are quite simple and cheap, and since you need to renormalize them (which you don’t do) in the fragment shader anyway, you’re not really getting anything.

    L is just the eye-space light position – the eye-space surface position. E is just the direction from the eye to the position, which is the normalized negation of the eye-space surface position.

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

Sidebar

Related Questions

Before I go into doing everything by hand I would like to ask if
I am having some problems with an XML transform and need some help. The
I have trouble transforming the following code into the new django 1.3 class-based generic
Please help me figure a single query that will transform the data below... |id
This only helps kills processes on the local machine. How do I kill processes
What tools helps designing sites which would be mobile phone friendly ? Something that
which framework helps in reducing the number of lines of code needed to create
I am writing a Java utility that helps me to generate loads of data
I maintain an applet that helps users to upload photos to our service. The
I have an interface in C# that helps retrieving of data from a custom

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.