Mapping Quaternion Rotations to Sprites: Questions and Concerns

Started by
4 comments, last by DrDeath3191 4 years, 8 months ago

Hello everyone;

I had a bit of trouble deciding where this needed to be posted; although there is quite a bit of math involved, in the end this is about graphics, and some aesthetic concerns need to be taken into account. If this is in the wrong place, I apologize. There's quite a bit to this topic and quite a few questions, so please forgive the length.

So, what I am attempting to do is take a 3D rotation represented as a quaternion and use that to pick an appropriate sprite from a sheet. Think of it as a more complicated form of what was done in the original DOOM: I want to use the y rotation and x rotation to pick the corresponding sprite, then use the remaining z rotation to orient that sprite appropriately. I'm not sure if this has been done before, but if someone has, I'd love to see it.

I currently have a system that works, but I think it could be better. I currently have a simple sprite that is rotated in the x and y axes in 45 degree increments. I calculate the appropriate quaternion, and rotate the unit Z vector by it, and store this away. When I render the sprite in question, I get its current rotation, rotate the unit Z vector by it and compare the dot products of it and the vectors I stored away. I use the texture coordinates corresponding the the vector with the highest dot product. I then take the difference between the closest rotation quaternion and the actual rotation and find the component around the respective stored vector using swing twist decomposition. I extract the angle of this quaternion from its w component, giving me the z rotation of the sprite.

As I said, I think it could be better; it seems kind of silly to me to need to store those rotated Z vectors when I should just be able to compare the quaternions directly. There is a reason for them however; certain rotations are completely equivalent barring a rotation around z, which I'm hoping to extract separately regardless. Thus, I actually want to find the closest rotation irrespective of Z. However, I am struggling to find a way to make this work with only quaternions, as different rotations could wind up with the same orientation. I'm sure I just need to take the portion of the actual rotation around a certain axis before comparing with the stored ones, but I'm struggling to know what axis that is. No matter what I seem to do, it seems to pick the wrong sprite at certain times.

Another concern I have is smoothness. Obviously, 45 degree angle changes, even with a completely fluid Z axis, would still look a little jarring in motion. My game runs at a 60 Hz timestep, so my rendering rate would be at least that high. How small a rotation angle would I need to have an appealing turnaround at that rate? Or, perhaps better, is there some clever math or perspective trick I can do to fake it? I render with orthographic projection, but maybe I can pull a clever math trick?

The reason I'm doing this at all is because I was hoping to combine this with skeletal animation. Typical 2D skeletal animations look sort of like paper dolls, mostly because the bones can only turn on a single axis. I was thinking I could leverage the bone animation in something like Blender and use those rotations with this sort of sprite high resolution character sprites that animate fairly smoothly and look good from literally any angle.

But my fundamental question, at the end of the day, is this: is this actually worth my time to pursue further, given how much of a headache it has already been? 

I mean, I still think its a neat idea, but I might just be better off modelling everything in Blender in the first place. Even if I were to reduce the number of orientations to the bare minimum, removing symmetrical cases and orientations in which a sprite would never be seen, that would still be a lot of sprites for a single character. My time might be better used elsewhere.

I've been thinking about these issues in a vacuum, so I was hoping to get input from other people before I drive myself to the brink of insanity trying to do something that may not be as clever as I thought.

Hopefully I explained everything satisfactorily.

Thanks for your help.

Advertisement
4 hours ago, DrDeath3191 said:

is this actually worth my time to pursue further, given how much of a headache it has already been?

Probably not, but it is usually quite fun investigating. What you might find (other than the complexity of implementing it) is that the sheer number of sprites you need to store in different orientations is prohibitive in terms of memory use etc. And alpha blending several bone sprites on top of each other (if this is what you are intending) is not free in terms of performance, it could be very bad on mobile for instance, and you might find it is much quicker to just draw the 3d geometry.

If you want to look at literature on this sort of thing, imposters is a good search term (it is slightly different but highly related).

Another point is that quaternions may not be the best way of storing the orientation for lookup. Depending on your constraints (say you have humanoid characters always standing upright) you might be able to store orientation as e.g. a unit x, y, z direction. Or maybe euler angles or axis angle. These might be easier to do numerical comparisons and allow lookup tables etc.

I wasn't too concerned about the alpha blending. I'm not developing for phones, and most desktop GPUs can handle a large number of sprites with minimal issue. As for lookup, the vector rotation method works, I just thought I could do it smarter with quaternion comparison instead.

But the sheer amount of texture work required is the major issue. With 45 degree increments in both axes, after removing redundant sprites, my test sprite has 26 sprites. If I wanted to move to 22.5 degree increments for smoother motion, I would need to almost quadruple that. And that would be for a single body part! Granted, my current test is not symmetrical on either axis for exactly the purpose of testing that. I could also reduce the rotational definition in certain sprites and axes (you won't often see the bottom of a character's foot, after all).

I was hoping to use my 45 degree increments to cheat my way to the answer. I'll look more into imposters, but it seems to me I'll need to abandon this enterprise for now. Sometimes you just need another person to confirm. Thanks!

At some point, and I think it's a point you are likely to have already reached, authoring many 2D sprites with skeletal animations can become more expensive than authoring one 3D model with skeletal animation.

Assuming that, unlike 25 years ago, 2D billboard have no performance advantage (they might even have performance disadvantages, due to complex logic and large texture sizes), do they look somehow better than 3D models? Is this effort justified?

A good reference: Starcraft has proper sprites with a very limited number of pose angles.

  • It looks good because of the superiority of well-made pixel art over fuzzy realtime rendering.
  • Due to the combination of a fixed strictly orthographic camera and a strictly 2D environment, there's no need for general 3D rotations.
  • Coarse quantization of unit facing is entirely intentional and tactically very important. With more poses, it would be a worse game and it wouldn't look any better.

Omae Wa Mou Shindeiru

It wasn't so much about it looking better so much as it was looking different: I like the appeal of 2D, and thought this would be a novel way to approach it, and I could get a painterly character that appears 3D. Perhaps the reason it's so novel is because it isn't a particularly good idea.

As for the performance side of things that would depend on the complexity of the model and rigging, but I think you may be right on general principle. Certainly the texture size would be a concern if I go for the painterly look.

Yeah, hearing from 2 different voices has convinced me to shelve the idea for the moment. Maybe I'll play around with idea more later, but I think looking into painterly NPR is going to be my best bet.

This topic is closed to new replies.

Advertisement