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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:01:16+00:00 2026-05-23T07:01:16+00:00

I am trying to make a custom light shader and was trying a lot

  • 0

I am trying to make a custom light shader and was trying a lot of different things over time.
Some of the solutions I found work better, others worse. For this question I’m using the solution which worked best so far.

My problem is, that if I move the “camera” around, the light positions seems to move around, too. This solution has very slight but noticeable movement in it and the light position seems to be above where it should be.

Default OpenGL lighting (w/o any shaders) works fine (steady light positions) but I need the shader for multitexturing and I’m planning on using portions of it for lighting effects once it’s working.

Vertex Source:

varying vec3 vlp, vn;

void main(void)
{
    gl_Position = ftransform();

    vn = normalize(gl_NormalMatrix * -gl_Normal);
    vlp = normalize(vec3(gl_LightSource[0].position.xyz) - vec3(gl_ModelViewMatrix * -gl_Vertex));

    gl_TexCoord[0] = gl_MultiTexCoord0;
} 

Fragment Source:

uniform sampler2D baseTexture;
uniform sampler2D teamTexture;
uniform vec4 teamColor;

varying vec3 vlp, vn;

void main(void)
{
    vec4 newColor = texture2D(teamTexture, vec2(gl_TexCoord[0]));
    newColor = newColor * teamColor;
    float teamBlend = newColor.a;

    // mixing the textures and colorizing them. this works, I tested it w/o lighting!
    vec4 outColor = mix(texture2D(baseTexture, vec2(gl_TexCoord[0])), newColor, teamBlend);

    // apply lighting
    outColor *= max(dot(vn, vlp), 0.0);
    outColor.a = texture2D(baseTexture, vec2(gl_TexCoord[0])).a;

    gl_FragColor = outColor;
}

What am I doing wrong?

  • 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-23T07:01:17+00:00Added an answer on May 23, 2026 at 7:01 am

    I can’t be certain any of these are the problem, but they could cause one.

    First, you need to normalize your per-vertex vn and vlp (BTW, try to use more descriptive variable names. viewLightPosition is a lot easier to understand than vlp). I know you normalized them in the vertex shader, but the fragment shader interpolation will denormalize them.

    Second, this isn’t particularly wrong so much as redundant. vec3(gl_LightSource[0].position.xyz). The “position.xyz” is already a vec3, since the swizzle mask (“.xyz”) only has 3 components. You don’t need to cast it to a vec3 again.

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

Sidebar

Related Questions

I'm trying to make my custom filter work... I have the following code in
I'm trying to make some custom Google maps info windows, but I'm getting the
I was trying to make a custom application form. I've added some control like
I am trying to make a custom Gallery widget. I found that I wanted
I'm trying to make a custom report. I've just put some test code on
I'm trying to make a custom SIP software work on an EC2 instance. My
I've been trying to make a custom lockscreen work with the iPod Touch 4G.
I have been trying to make custom radio buttons using HTML, CSS, and JavaScript.
I am trying to make Custom RelativeLayout which can scale and scroll. Right now
Trying to make a custom :confirm message for a rails form that returns data

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.