Cg matrices

Problems building or running the engine, queries about how to use features etc.
User avatar
captainstan
Halfling
Posts: 94
Joined: Thu Nov 04, 2004 12:46 pm
Location: france

Cg matrices

Post by captainstan »

I'm trying to transmit to my Cg program the worldlview_matrix, and the projection_matrix, but it doesn't seem to work...
I noticed multiplying the world_matrix and the viewproj_matrix is equivalent to the worldviewproj_matrix, but not to the world_matrix multiplicated by the viewproj_matrix.
Weird isn't it ? Am I (again) missing something ?
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67

Post by sinbad »

Why don't you just use the autobindings that Ogre gives you?

Matrix multiplication is not commutative, so M * N != N * M.
User avatar
captainstan
Halfling
Posts: 94
Joined: Thu Nov 04, 2004 12:46 pm
Location: france

Post by captainstan »

inside my shader, I don't want all my vertices to be treated the same, so I need to separate the modelview matrix from the projection matrix.
When you say autobindings, do you mean to use param_named_auto in my material script ? that's what I do but it just doesn't seem to work...
And I take care of the non-commutativity of the matrices, of course.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67

Post by sinbad »

You'd need to give us a specific example, we use a variety of auto bindings all the time (separate and combined) and they work fine.
User avatar
captainstan
Halfling
Posts: 94
Joined: Thu Nov 04, 2004 12:46 pm
Location: france

Post by captainstan »

I'm not on my work PC, so it may not be exactly it..
in my material script, I have my vertex program reference containing

Code: Select all

param_indexed_auto 0 worldview_matrix
param_indexed_auto 4 projection_matrix
param_indexed_auto 8 77 //must be something like that, well it references the morphfactor for terrain shading, anyway it works
and for the moment, in my vertex shader :

Code: Select all

vertout main(float4x4 worldview, 
           float4x4 projection, 
           float morphfactor,
           ...)
{
  position.y = //something with delta and morphfactor
  out_position = mul(worldview, position);
  out_position = mul(projection, out_position);
.....
}
if I pass in world_matrix and viewproj_matrix, it works allright.
I wanna pass the projection matrix separatly, basically because I wanna see if I can obtain some weird effects modifying it.
I've also tried to use param_named_auto with the same results (I don't see anything at all when separating projection from other matrices).
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67

Post by sinbad »

Ok, it's a bug in the MaterialSerializer, it doesn't have a case statement for projection_matrix. The auto binding is there, and I'm sure it works (since it's derived the same way for viewproj and worldviewproj), it was just missed in the script parser. I'll fix it.

[Edit]Fixed in Hastur, once anon is up to date this should work[/Edit]
User avatar
captainstan
Halfling
Posts: 94
Joined: Thu Nov 04, 2004 12:46 pm
Location: france

Post by captainstan »

As always, thanks a lot for taking so much time and dig into your code for me. Anyway, it's not my mistake so I'm happy not to feel too dumb with my questions :)
Don't worry, even genious sometimes forget somethings ;)