Setting up matrixes

Hey there. I’m having a hard time with one of my projects. I’m using ARB assembly shaders to render my character models, very simple effects, and in fact I’m only using a vertex shader and passing off data to the fixed pipeline.

My problem is that when I try to use built-in states like state.matrix.mvp, state.matrix.texture[0], or anything alike, it seems to cause problems on certain graphics cards, like on latest nVidia cards state.matrix.mvp seems to be completely empty, or on ATI cards using the texture matrix also produces odd results.

I tried to use my own uniforms, sending the modelview, projection and texture matrixes to the program.local values, but while things like my point lights, the texture matrix and the global illumination work fine, I just can’t upload the modelview and the projection matrix. Basically every time I bind the shader I get those two using glGetFloatv and input them into the shader using LocalParameter4fvARB, but the results are either weird, or I don’t see anything.

Has anyone had anything like this? I’ve been messing with this for a whole day and I feel like tearing my hair out. ARB shaders are my last hope for smooth lighting effects, wich I won’t get with GL_LIGHTING.

Thanks for your help.

Are you using the depreciated in built OpenGL matrix functions and trying to copy and pass those?

What version of GLSL are you using? Versions 140+ don’t have things like the mvpMatrix passed to them by default anymore, you have to do your own matrixes/quaternions/euler transformations and pass those yourself now with version 140+

What version of GLSL are you using?

He’s using ARB assembly shaders, not GLSL.

Ah whoops.

“but the results are either weird, or I don’t see anything”
Maybe you’re multiplying gl_Vertex by the matrix in the wrong order:

gl_Position = gl_Vertex * mvp; // wrong, if mvp is not transposed.

So, if you’re using DP4, try the MUL+MADD way, or vice-versa.

Well I don’t try to transform with mvp, I upload modelview and projection individually. I’m not good at matrix maths, so I didn’t try and transform it yet on the CPU.

Anyway I did some testing. I still run my water shader using Cg, and I fetched the projection and modelview matrixes that Cg sets up if you call cgGLSetStateMatrixParameter, and the two differ a lot. As I said I’m not very good at matrix maths, so I’m not sure what’s how, but is it because the modelview and projection matrixes in Cg are transposed by default?

This is how I did it in Cg, and it worked fine:
float4 vMV = mul(ModelView, vin.pos);
vout.pos = mul(Projection, vMV);

Oh, now I think I know how this goes now that I inspected it closer. I’ll come back with results.

Basically the mat4*vec4 /GL style/ is:

MUL   R0, v[0].y, c[1];
MAD   R0, v[0].x, c[0], R0;
MAD   R0, v[0].z, c[2], R0;
MAD   o[HPOS], v[0].w, c[3], R0;

and vec4*mat4 /DX style/ is:

DP4   o[HPOS].w, v[0], c[3];
DP4   o[HPOS].z, v[0], c[2];
DP4   o[HPOS].y, v[0], c[1];
DP4   o[HPOS].x, v[0], c[0];

v[0] = vec4
c[0…3] = mat4

Thanks, though I realised this eventually, and got matrixes working, but after I finally had my shaders set up, I ran into another problem. On the bloody ATI card of my friend, texture coordinates kept being jarbled up, plus when I had lights turned on certain models kept disappearing.

I moved back to Cg, and eventually found out how I can get rid of having to use a pixel shader, thanks to the FOGC parameter, however now I have another problem.
I don’t know if its related to me not using a pixel shader, but on my friend’s ATI card, some of the models’ texture coordinates keep being messed up, while on others they render fine. The rendering code is mostly the same for both, the only difference is that the ones that work normally are VBOs, and are drawn after the ones that are messed up. I’m really getting tired of having to mess with these compatibility issues. Right now I’m trying to find what causes this difference.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.