Options

12gauge
Registered User regular

Hi, I want to recreate a nvidia shader in glsl but I just can't seem to get the uniform variables in my shader. Here is my vertex shader:

And here is my code to update the prevModelView (in opengl it is an float[16] array, same as modelView)

and in the drawBlurredScene()

I can see from the result, that all vertices affected by the prevModelView-Matrix in the shader get translated to 0,0,0 modelspace and when I query the variable, I also only get zeros on all 16 positions. What the fuck am I doing wrong?

Edit: Here is the getUniLoc-Function

varying vec3 velocity; uniform mat4 prevModelView; void main() { float blurScale = 1.0; gl_TexCoord[0] = gl_MultiTexCoord0; //transforming the positions to eyespace vec3 hWS = vec3(256.0, 256.0, 0.0);//halfWindowSize; vec4 P = gl_ModelViewMatrix * gl_Vertex; vec4 Pprev = prevModelView * gl_Vertex; //transfrom the normals vec3 normal = normalize(gl_NormalMatrix * gl_Normal); //now, the motion vector vec3 motionVector = P.xyz - Pprev.xyz; //calculate the previous MODELVIEW_PROJECTION_MATRIX mat4 prevModelViewProj = gl_ProjectionMatrix * prevModelView; //get the clip space motion vector P = gl_ModelViewProjectionMatrix * gl_Vertex; Pprev = prevModelViewProj * gl_Vertex; Pprev = mix(P, Pprev, 1.0); //choose current or previous position //bool flag = dot(motionVector, normal) > 0.0; vec4 Pstretch; float flag = sign(dot(motionVector, normal)); if (flag > 0.0) { Pstretch = P; } else{ Pstretch = Pprev; } P.xyz = P.xyz / P.w; Pprev.xyz = Pprev.xyz / Pprev.w; //Pstretch.xyz = Pstretch.xyz / Pstretch.w; vec3 dP = (P.xyz - Pprev.xyz) * hWS; velocity = dP; gl_Position = Pstretch; //gl_ClipVertex = Pstretch; }

And here is my code to update the prevModelView (in opengl it is an float[16] array, same as modelView)

void renderScene(void) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0, 0.0, -30.0); //glRotatef(yrot, 1.0, 0.0, 0.0); glRotatef(yrot, 0.0, 1.0, 0.0); //glRotatef(yrot, 0.0, 0.0, 1.0); glGetFloatv(GL_MODELVIEW_MATRIX, modelView); //drawModel(); drawScene(); drawBlurredScene(); yrot+=1.0f; for(int i = 0; i < 16; i++) { prevModelView[i] = modelView[i]; } GLfloat tester[20]; glutSwapBuffers(); glGetUniformfv(mblur_p, glGetUniformLocation(mblur_p, "prevModelView"), tester); for(int i = 0; i < 20; i++) { printf("Number %i :%f\n",i, tester[i]); } glutSwapBuffers(); }

and in the drawBlurredScene()

[...] glUniformMatrix4fv(getUniLoc(mblur_p, "prevModelView"), 0, GL_TRUE, prevModelView); glUseProgram(mblur_p); drawModel(); glUseProgram(0); }

I can see from the result, that all vertices affected by the prevModelView-Matrix in the shader get translated to 0,0,0 modelspace and when I query the variable, I also only get zeros on all 16 positions. What the fuck am I doing wrong?

Edit: Here is the getUniLoc-Function

GLint getUniLoc(GLuint program, const GLchar *name) { GLint loc; loc = glGetUniformLocation(program, name); if (loc == -1) printf("No such uniform name \"%s\"\n", name); //printOpenGLError(); return loc; }

0

## Posts

Let me know if that helps. I'll be mostly away from the internet for the next week or so (moving to California) but I'll try to poke my head in when I find some time.

ziloonYeah, the glUniformMatrix4fv parameters where me just trying around to see if I can get different results - good catch with the linking, got me on the right lead - uniforms have not to be initialized before linking, but after the shader program is used - as you can see, I defined the variable *before* I used the shader:|

Thanks a lot and good luck on your way to california!

12gaugeonGlad to see it works. Post screens ;-)

ziloonWell, after some more work on the fragment part, here you can see a comparison - guess which one has the motion blur... :P

12gaugeonThat looks great. How's the framerate hit?

ziloon