OpenGL,片段着色器:没有这样的统一命名
OpenGL, fragment shader : No such uniform named
我有一个问题,我想让我的光来自我的物体,我设法将它的位置作为统一传递,但我无法传递它的旋转矩阵。
我的片段着色器:
#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;
}
在我的函数中 display_callback 在我的 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();
}
但我有这个问题:没有这样的制服名为 "rot_lamp"
这是唯一使用rot_lamp
制服的地方:
mat4 test = rot_lamp;
由于 test
没有在其他地方使用,因此不会影响着色器的输出,GLSL 编译器已经删除了 rot_lamp
uniform。这是预期的,并且不是错误(除非您打算在输出计算中实际使用制服)。
根据评论,您有...
uniform sampler2D texture;
// ...
mat4 test = rot_lamp;
所以 rot_lamp
只在 test
的赋值中使用,而 test
永远不会在这个语句之后使用。由于设置 rot_lamp
不能影响片段着色器的输出,因此它将从着色器程序中删除。
我有一个问题,我想让我的光来自我的物体,我设法将它的位置作为统一传递,但我无法传递它的旋转矩阵。 我的片段着色器:
#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;
}
在我的函数中 display_callback 在我的 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();
}
但我有这个问题:没有这样的制服名为 "rot_lamp"
这是唯一使用rot_lamp
制服的地方:
mat4 test = rot_lamp;
由于 test
没有在其他地方使用,因此不会影响着色器的输出,GLSL 编译器已经删除了 rot_lamp
uniform。这是预期的,并且不是错误(除非您打算在输出计算中实际使用制服)。
根据评论,您有...
uniform sampler2D texture;
// ...
mat4 test = rot_lamp;
所以 rot_lamp
只在 test
的赋值中使用,而 test
永远不会在这个语句之后使用。由于设置 rot_lamp
不能影响片段着色器的输出,因此它将从着色器程序中删除。