# Making a texture 'point' at something?

This topic is 1720 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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).

##### Share on other sites

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.

Edited by Dawoodoz

##### Share on other sites
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.

##### Share on other sites

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:

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

Edited by Kryzon

##### Share on other sites

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:

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.