# How can I find the minimal texture size so the texture requires no pixel interpolation when transformed by a given matrix?

Given a rectangle with width x and height y, and a transformation matrix T: How can I estimate the minimal resolution of the texture (that is, its width and height) such the interpolation of additional pixels won't be needed?

Simple example: If x = 200px, y = 150px and T is a 2× scale matrix, then the required resolution is 400×300.

How can I do this for more complex cases, such as perspective projection?

• Depends on what you mean with projection - perspective or ortho? Sep 13 '14 at 23:42
• Perspective projection. Sep 13 '14 at 23:43
• Once you add in projection, you need to consider the pixel error resolution, which depends on field of view and distance from camera... [This article]( developer.valvesoftware.com/wiki/Field_of_View) covers some of the math involved and is directly related to using mipmaps to apply textures to your models that are appropriate for the viewing distance. Sep 14 '14 at 2:20
• Your computation depends also on a model M and the distance d from model to camera (imagine a textured monster very far/very near from the camera). To avoid headache, you have to decide of some 'average case' i guess. Sep 14 '14 at 10:11
• If anyone can think of a shorter title that describes the question well, I'd appreciate it. :)
– Anko
Jan 3 '15 at 22:18

To calculate perspective projection divide by w.

vec4 result = vec4(x, y, z, 1) * perspective_view_model_matrix;
result /= w;


You are then left with the (x,y) in screen space (-1 to 1).

Multiply this by 1/2 screen width,height and you get pixel coordinates.

You then need to take the corresponding vertex UVs, multiply by the texture size and you get texel coordinates.

What you need to do next is calculate the polygon (triangle) pixel area and the polygon (triangle) texel area, divide one by the other and you get the texel-to-pixel ratio (or the other way around).

This will give you an approximation of how big/small the texture is relative to screen size.

It will work even rotated as long as the polygons are facing the screen and have uniform scaling otherwise you'll get an average as some texels will be more stretched than others.