Shortest version of the question:
**I have matrix A that I'd like to apply to a model, but I'd like to apply it at the angle represented by matrix B. How do I do that? Right now I'm using:
x = B.inverse() * x
x = A * x
x = B * x
And it's not really working.
**
Now, the long version. My goal is to use a shader to apply perspective to each model independently to imitate an old school "perspective rendered sprites in an ortho world" look.
I've got a matrix which "scrunches" (apply perspective) to a mesh, which turns out to be pretty simple. But it applys it in the wrong direction. Here it is just applied in a shader, note that it's applied in mesh space so it just spins around as the mesh spins:
To move that transform into world space, I tried applying the inverse rotation before the scrunch, then the inverse of that inverse afterwards.
Now, this is the closest I've gotten to achieving the right rotation, by stacking on even more "inverse before, apply after" combinations, including the camera's basis and an "offset" where I try to fudge it:
That is the best impression of what I'm trying to achieve, but notice that the rotation is now along the wrong axis, which means it's not really usable.
I figure I'm doing something wrong with matrixes here:
void vertex() {
//https://discord.com/channels/212250894228652034/408555922349359105/988915027035693186
mat4 projection = mat4(
vec4(1,0,0,0),
vec4(0,1,0,0),
vec4(0,0,1,-S),
vec4(0,0,0,1)
);
vec4 tmpvertex = vec4(VERTEX, 1);
tmpvertex = offset * tmpvertex;
tmpvertex = inv_xform * tmpvertex;
tmpvertex = inv_cam_xform * tmpvertex;
tmpvertex = projection * tmpvertex;
tmpvertex = cam_xform * tmpvertex;
tmpvertex = inv_xform * tmpvertex;
tmpvertex = inv_offset * tmpvertex;
VERTEX = tmpvertex.xyz / tmpvertex.w;
}
I'm trying to figure out a general approach to replace my janky trial and error. Anyone have any insight?
My project is here: https://github.com/eamonnmr/25d_shader_test