GLSL equivalent of trans_x_to_y

Am I correct that “trans_x_to_y” inputs are not supported in GLSL (as of panda 1.8.1)?

I need to send a transformation matrix to my shader that converts model coordinates into another node’s coordinates.

If I was using Cg I am pretty sure I would do:

<python>
node.setShaderInput("othernode", othernode)

<shader>
uniform float4x4 trans_model_to_model_of_othernode;

Is that correct?
What is the best way to achieve the same in GLSL?

Thanks for the help!

Either pass a custom matrix input with as value me.getMat(you) which is basically the same as trans_me_to_you, or use the latest devel version and use trans_x_to_y directly in the shader.

Thanks for the quick response!

I was kind of afraid that would be your answer. I was hoping the others who posted how they were doing their transforms in GLSL were missing something.

So to make sure I understand, you would do something like this:

<python, in task run each frame>
node.setShaderInput("transform_mat", node.getMat(othernode))

<shader>
uniform mat4 transform_mat;

I tried that, but it gives me an error:

AssertionError: Shader input transform_mat is not a nodepath.

Upon further research, it looks like I would get around that by putting that mat into a dummy node and passing that? Like:

dummy = node.attachNewNode("dummy")
dummy.setMat(node.getMat(othernode))
node.setShaderInput("transform_mat", dummy)

Is that the idea? I will give it a try.

As far as using the devel version…

Do you know if there are plans to roll the addition of those GLSL inputs into a standard release anytime soon? From the dates on some forum posts, it appears they were available in the devel version before the release of 1.8.1, but then 1.8.1 didn’t include that change. Maybe I am mistaken?

I understand the reasoning behind not wanting to include a hard-coded variable name solution that you might want to phase out, but despite it’s rigidness, it is incredibly powerful and easy to use.

A longer term solution might be something like this:

node.setShaderInput(“a_transform_mat4”, (from_node, to_node))

where from_node and/or to_node could also be a keyword or const like “world” or “view” etc. which could allow all the functionality of the old Cg method without hard coding variable names.

node.setShaderInput(“trans_model_to_view”, (node, “view”))

would be an example of how you would recreate a trans_x_to_y input using that suggested syntax

just an idea

For now, just having the fixed named inputs in GLSL would be awesome. But I wouldn’t want to do that unless it was probably going to be rolled into an official release. Any idea on that?

Thanks again for your help.

Yes, the idea is that you put it in a NodePath.

The trans_x_to_y support for GLSL will be in the next major release of Panda3D, ie. 1.9.0, not 1.8.2. Version 1.8.2, like 1.8.1, will only be a bugfix release. I still don’t like the system and would prefer not to have it, but I won’t remove it until there’s a good replacement. (In any case, there would be at least a bunch of releases during which it’d be maintained for backward compatibility.)

Your suggestions are sound. I’ve been thinking of something similar for a future overhaul of the shader system. But I can’t give any guarantees about when that will be implemented.

Ok, well I got it working.

Thanks for the help and info.

One small follow up question.

The node I am rending with a shader is using the BillboardEffect to always turn an image object towards the camera so I can use the quad for drawing on. If I call getMat or getTrans on the node being billboarded, it always returns identity. I presume this is because the billboard effect doesnt actually change its standard Hpr, but instead just is a transformation during the render operation.

So, I ended up using a manual each frame lookAt call to have it face the camera instead, so I can query the transformation matrix of the billboard to my other node.

I don’t suppose you know a way to get the transform of a billboard between frames? Or possibly a way to get a transformation matrix of a second node into the apiview, so I could then go trans_view_to_othernode * gl_ModelView * billboard.

Or do you figure how I am doing it now is probably the best bet?

Thanks again.

Good question. There’s an adjust_transform method on BillboardEffect, but it’s not exposed to Python. There might be another way, but I wouldn’t know.