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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:50:44+00:00 2026-06-14T01:50:44+00:00

When I use my shaders I get following results: One problem is that specular

  • 0

When I use my shaders I get following results:
enter image description here

enter image description here

One problem is that specular light is sort of deformed and you could see sphere triangles, another is, that I can see specular where I shouldn’t (second image). One spehere light is done in vertex shader, other in fragment.

Here is how my vertex light shader looks like:
Vertex:

// Material data.
uniform vec3 uAmbient;
uniform vec3 uDiffuse;
uniform vec3 uSpecular;
uniform float uSpecIntensity;
uniform float uTransparency;

uniform mat4 uWVP;
uniform mat3 uN;
uniform vec3 uSunPos;
uniform vec3 uEyePos;
attribute vec4 attrPos;
attribute vec3 attrNorm;
varying vec4 varColor;

void main(void)
{
    vec3 N = uN * attrNorm;
    vec3 L = normalize(uSunPos);
    vec3 H = normalize(L + uEyePos);
    float df = max(0.0, dot(N, L));
    float sf = max(0.0, dot(N, H));
    sf = pow(sf, uSpecIntensity);

    vec3 col = uAmbient + uDiffuse * df + uSpecular * sf;
    varColor = vec4(col, uTransparency);
    gl_Position = uWVP * attrPos;
}

Fragment:

varying vec4 varColor;

void main(void)
{

    //vec4 col = texture2D(texture_0, varTexCoords);
    //col.r += uLightDir.x;
    //col.rgb = vec3(pow(gl_FragCoord.z, 64));
    gl_FragColor = varColor;

}

It is possible, that my supplied data from code is wrong.
uN is world matrix (not inverted and not transposed, even though doing that didn’t seem to do anything different).
UWVP – world view projection matrix.

Any ideas, as to where the problem might be, would be appreciated.

[EDIT] Here is my light calculations done in fragment:
Vertex shader file:

uniform mat4 uWVP;
uniform mat3 uN;
attribute vec4 attrPos;
attribute vec3 attrNorm;
varying vec3 varEyeNormal;

void main(void)
{
    varEyeNormal = uN * attrNorm;
    gl_Position = uWVP * attrPos;
}

Fragment shader file:

// Material data.
uniform vec3 uAmbient;
uniform vec3 uDiffuse;
uniform vec3 uSpecular;
uniform float uSpecIntensity;
uniform float uTransparency;

uniform vec3 uSunPos;
uniform vec3 uEyePos;
varying vec3 varEyeNormal;

void main(void)
{
    vec3 N = varEyeNormal;
    vec3 L = normalize(uSunPos);
    vec3 H = normalize(L + uEyePos);

    float df = max(0.0, dot(N, L));
    float sf = max(0.0, dot(N, H));
    sf = pow(sf, uSpecIntensity);

    vec3 col = uAmbient + uDiffuse * df + uSpecular * sf;

    gl_FragColor = vec4(col, uTransparency);
}

[EDIT2] As Joakim pointed out, I wasn’t normalizing varEyeNormal in fragment shader. After fixing that, the result is much better in fragment shader. I also used normalize function on uEyePos, so specular no longer goes to dark side. Thanks for all the help.

enter image description here

  • 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-06-14T01:50:45+00:00Added an answer on June 14, 2026 at 1:50 am

    Short answer: You need to normalize varEyeNormal in the fragment shader, instead of in the vertex shader.

    Longer answer:
    In order to get smooth lighting you will need to calculate the normals per pixel instead of per vertex. Varyings computed in the vertex shader are linearily interpolated before passed to the fragment shader, which works great as a shortcut in some cases but worse in others.

    The reason you are seeing the triangle edges is because of the interpolation between normals result in shorter than 1.0 normals in all pixels between the vertices.

    To correct this you will need to normalize the normals in the fragment shader instead of in the vertex shader.

    The Normal matrix should be upper 3×3 of the transpose of the inverse of the Modelview matrix, which is equivalent to the upper 3×3 of of the Modelview matrix if the Modelview contains only rotations and translations (no scaling)

    For more about the Normal matrix, see: http://www.lighthouse3d.com/tutorials/glsl-tutorial/the-normal-matrix/

    (Edited for correctness according to comment below.)

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

Sidebar

Related Questions

I am trying to use geometry shaders in my OpenGL application that is currently
In order to use normal mapping in GLSL shaders, you need to know the
Is anybody using OpenGLES2.0 shaders (GLSL) successfully for audio synthesis? I already use vDSP
The Problem (TL;DR) My problem, fundamentally, is that I do not know how OpenGL
I am trying to use a String.Format to create the following string 2MSFX.exe C:\Users\Avidan\Documents\Visual
I have some GLSL shaders that are compiling correctly, and being successfully attached to
I've begun switching my rendering code to support shaders, and that all works fine
So im having problems rendering using 2 different shaders. Im currently rendering shapes that
I want to use coverflow view in my app. To get the reflection image
I am learning to use shaders in OpenGL ES. As an example: Here's my

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.