Recently, I've been making a 3D game, and I have more progress! I am trying to implement lighting, but when I want to change the directional light uniform manually, it gets weird.

Here's an example

When I dont use uniforms:

enter image description here


enter image description here

Its like the faces don't register the Z value, or something. I have no idea.

Heres my shader code:


#version 120

varying vec4 v_Vertex;

varying vec2 v_TexCoord;

varying vec4 v_Position;

uniform float f = 0.0;

varying vec4 v_Normal;

vec4 n_Normal;

varying vec4 v_Color;

uniform sampler2D u_Texture;

uniform float fac = 16;

in vec4 color;

vec4 texture;

uniform float x1;
uniform float y1;
uniform float z1;

float rand2D(in vec2 co){
    return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
float rand3D(in vec3 co){
    return fract(sin(dot(co.xyz ,vec3(12.9898,78.233,144.7272))) * 43758.5453);

vec4 directLight(in sampler2D tex, in vec2 coords, in vec3 lightCol) 

    float amb = 0.3f;
    vec3 normal = normalize(v_Normal.xyz);
    vec3 lightDir = normalize(vec3(x1, y1, z1));
    float diffuse = max(dot(normal, lightDir), 0.0f);
    return (texture2D(tex, coords) * (diffuse + amb) * lightCol);


void alphaTransparency()

    texture = texture2D(u_Texture, v_TexCoord);

    if (texture.rgb == vec3(1.0, 0.0, 1.0))


void main(void) {

    vec4 fakeshading = vec4(1.0);
    float fac = 0.0;


    n_Normal = normalize(v_Normal);
    // gl_FragColor = texture;
    // gl_FragColor = texture;
    gl_FragColor = directLight(u_Texture, v_TexCoord, vec3(1.0, 1.0, 1.0));

and the code where I change the uniforms:

... code above irrelavant

            GL20.glUniform1f(GL20.glGetUniformLocation(shader.getProgID(), "x1"), 2);
            GL20.glUniform1f(GL20.glGetUniformLocation(shader.getProgID(), "y1"), 3);
            GL20.glUniform1f(GL20.glGetUniformLocation(shader.getProgID(), "x1"), 1);

Thank you for your help

  • 1
    \$\begingroup\$ Your code sets x1 twice. Did you mean to assign the z1 uniform there? \$\endgroup\$
    – DMGregory
    Commented Jun 27, 2021 at 20:41
  • \$\begingroup\$ @DMGregory ah yes forgot that variable \$\endgroup\$
    – Pale_Gray
    Commented Jun 27, 2021 at 21:43
  • \$\begingroup\$ @DMGregory thanks so much that little error made the whole lighting system wonky \$\endgroup\$
    – Pale_Gray
    Commented Jun 27, 2021 at 21:44
  • \$\begingroup\$ Do you still need help, or would you like to delete the question if it was just that typo? \$\endgroup\$
    – DMGregory
    Commented Jun 27, 2021 at 21:46


You must log in to answer this question.

Browse other questions tagged .