• Create Account

## Making a texture 'point' at something?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1Kryzon  Prime Members

4436
Like
2Likes
Like

Posted 08 May 2013 - 01:31 AM

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

### #2Dawoodoz  Members

463
Like
1Likes
Like

Posted 08 May 2013 - 01:58 AM

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, 08 May 2013 - 01:59 AM.

"App". is an acronym and must always be followed by a dot.

### #3Hodgman  Moderators

49410
Like
2Likes
Like

Posted 08 May 2013 - 08:31 AM

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.

### #4Kryzon  Prime Members

4436
Like
0Likes
Like

Posted 08 May 2013 - 12:25 PM

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, 08 May 2013 - 12:57 PM.

### #5Dawoodoz  Members

463
Like
1Likes
Like

Posted 09 May 2013 - 03:30 AM

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.

"App". is an acronym and must always be followed by a dot.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.