Making a texture 'point' at something?

Started by
3 comments, last by Dawoodoz 10 years, 11 months ago

The game "Conker's Bad Fur Day" for the Nintendo 64 boasts several special effects never seen before in that platform at the time, even featuring a rudimentary shadow-mapping effect.

One of the special effects of this game is especially intriguing. It occurs when you're using the "POV" camera mode to look around the level and happen to orbit around the character's face. His eyes follow the camera.

I've looked at the wireframe for the character mesh and noticed the character's eyes are entirely represented by texturing. They aren't "decal" meshes as one would expect. So the effect of movable eyes is somehow achieved by transforming the texture's matrix so as to make it slide.

Here's some footage from the game:

I was wondering what would be the math theory behind this, to compute an UV offset for an "eye" texture based on a point of origin (the position of the eye) and a point of destination in space (the object being looked at).

Advertisement

Apply a UV offset from a constant buffer to move the eyes like that. Then you cover the edges by lerping the eyes to visibility where the skin's alpha is low. You can use a tangent function to compute the offset in the head's space.

If you assume the eyes are a sphere, and you can calculate the UV coordinates of any point on the sphere, then you just need to normalize your direction (to turn it into a point on the sphere), and then transform that point into UV-space. Then subtract the UV coordinates of where the pupils are "at rest", and you've got your UV offset.

You can use a tangent function to compute the offset in the head's space.

Could you elaborate on this?

What would you be comparing to get the tangent?

EDIT: On Hodgman's suggestion, there's code to calculate the UVs of a point on a sphere based on a normalized direction (i.e: a radius connecting the center of the sphere to the point where you want to find the UVs). It's from the wikipedia article on UV Mapping:

761ef477fca2de40aed0cbbae3cbf9ca.png

ad415e568bc911ec29c8233d7c26bef2.png

So I could take the vector from [center of eye] to [object being looked at], normalize it and use that as d.

You can use a tangent function to compute the offset in the head's space.

Could you elaborate on this?

What would you be comparing to get the tangent?

EDIT: On Hodgman's suggestion, there's code to calculate the UVs of a point on a sphere based on a normalized direction (i.e: a radius connecting the center of the sphere to the point where you want to find the UVs). It's from the wikipedia article on UV Mapping:

761ef477fca2de40aed0cbbae3cbf9ca.png

ad415e568bc911ec29c8233d7c26bef2.png

So I could take the vector from [center of eye] to [object being looked at], normalize it and use that as d.

It all depends on how you projected the textures in the first place and flat eyes will always be a rough approximation. if you want real precision, you can rotate 3D spheres instead.

This topic is closed to new replies.

Advertisement