1

I have an issue, I want my light to come from my object, I managed to pass its position as uniform but I can't pass its rotation matrix. My fragment shader:

#version 120

varying vec3 coordonnee_3d;
varying vec3 coordonnee_3d_locale;
varying vec3 normale;
varying vec4 color;

uniform sampler2D texture;

// vec3 light=vec3(0.5,0.5,5.0);
uniform vec4 pos_lamp;
uniform mat4 rot_lamp;
vec3 light = vec3(pos_lamp.x, pos_lamp.y, pos_lamp.z);


void main (void)
{
    vec3 n = normalize(normale);
    vec3 d = normalize(light-coordonnee_3d_locale);
    mat4 test = rot_lamp;
    vec3 r = reflect(d,n);
    vec3 o = normalize(-coordonnee_3d_locale);

    float diffuse  = 0.7*clamp(dot(n,d),0.0,1.0);
    float specular = -0.2*pow(clamp(dot(r,o),0.0,1.0),128.0);
    float ambiant  = 0.2;

    vec4 white = vec4(1.0,1.0,1.0,0.0);

    vec2 tex_coord     = gl_TexCoord[0].xy;
    vec4 color_texture = texture2D(texture,tex_coord);
    vec4 color_final   = color*color_texture;

    gl_FragColor = (ambiant+diffuse)*color_final+specular*white;

}

And in my function display_callback in my main.cpp

static void display_callback(){
    glUniformMatrix4fv(get_uni_loc(shader_program_id, "rotation_view"), 1, false, pointeur(transformation_view.rotation));
    PRINT_OPENGL_ERROR();

    vec3 cv = transformation_view.rotation_center;
    glUniform4f(get_uni_loc(shader_program_id, "rotation_center_view"), cv.x, cv.y, cv.z, 0.0f);
    PRINT_OPENGL_ERROR();

    vec3 tv = transformation_view.translation;
    glUniform4f(get_uni_loc(shader_program_id, "translation_view"), tv.x, tv.y, tv.z, 0.0f);
    PRINT_OPENGL_ERROR();

    glUniform4f(get_uni_loc(shader_program_id, "pos_lamp"), transformation_model_1.translation.x, transformation_model_1.translation.y, transformation_model_1.translation.z, 0.0f);
    PRINT_OPENGL_ERROR();

    glUniformMatrix4fv(get_uni_loc(shader_program_id, "rot_lamp"), 1, false, pointeur(transformation_model_1.rotation));
    PRINT_OPENGL_ERROR();
}

But I have this issue: No such uniform named "rot_lamp"

2
  • Please show the complete code for the fragment shader. If the glsl compiler/linker can deduce that the uniform isn't used (or that it's apparent use doesn't actually affect the results) then it is free to elide the uniform completely. Commented Dec 12, 2019 at 10:01
  • It's done, excuse me. Commented Dec 12, 2019 at 10:17

2 Answers 2

3

Following on from the comment, you have...

uniform sampler2D texture;

// ...

mat4 test = rot_lamp;

So rot_lamp is only ever use in the assignment to test and test is never used after this statement. Since setting rot_lamp cannot, therefore, affect the output of the fragment shader it will be removed from the shader program.

Sign up to request clarification or add additional context in comments.

Comments

2

This is the only place where the rot_lamp uniform is used:

mat4 test = rot_lamp;

Since test is used nowhere else, thus doesn't affect the output of the shader, the GLSL compiler has elided rot_lamp uniform. It's expected, and is not an error (unless you intended the uniform to be actually used in the calculation of the output).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.