我遇到了一些调试程序的困难。我试图使用数组作为查找表,在我的顶点着色器中偏移顶点位置,但是我甚至无法确定我是否正确地链接了我的数组。偏移因子总是结束为零(使我的向量变平,而不是给它们一个形状),所以要么我访问texture1D坐标有误,要么数组没有正确绑定到纹理上。
坦率地说,我不知道我应该使用哪些坐标来从1D纹理中获取值...但我已经尝试了所有组合。
在这里,我设置了数组并将其绑定到着色器:
坦率地说,我不知道我应该使用哪些坐标来从1D纹理中获取值...但我已经尝试了所有组合。
在这里,我设置了数组并将其绑定到着色器:
//FISH
GLfloat fish_coords[100];
for (int i = 0; i < 50; i++){fish_coords[i] = 0;}
for (int i = 50; i < 100; i++){fish_coords[i] = 1;}
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glGenTextures(1, &fishtexture);
glBindTexture(GL_TEXTURE_1D, fishtexture);
glTexImage1D(GL_TEXTURE_1D, 0, 1, 128,0,GL_RGBA, GL_UNSIGNED_BYTE, &fish_coords);
switch(shadow_selection){
case 0:
vertexShader = "fish.vert";
fragmentShader = "fish.frag";
setShaders();
GLint loc1;
loc1 = glGetUniformLocation(shaderProgram,"fish_coords");
glUniform1i(loc1,0);
我的顶点着色器:
uniform float spec_factor;
uniform sampler1D fish_coords;
varying vec3 lightDir,normal;
void main()
{
vec4 v_pos;
vec3 ldir;
gl_TexCoord[0] = gl_MultiTexCoord0;
v_pos = gl_ModelViewMatrix * gl_Vertex;
ldir = vec3(gl_LightSource[0].position-v_pos);
lightDir = normalize(ldir);
normal = normalize(gl_NormalMatrix * gl_Normal);
vec4 offset;
offset = texture1D(fish_coords, gl_TexCoord[0].r);
vec4 fish_shape;
fish_shape.xz = gl_Vertex.xz;
fish_shape.y = gl_Vertex.y * offset.x;
fish_shape.w = 1;
gl_Position = gl_ModelViewProjectionMatrix * fish_shape;
}