4
\$\begingroup\$

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?

\$\endgroup\$
6
  • \$\begingroup\$ Depends on what you mean with projection - perspective or ortho? \$\endgroup\$
    – wondra
    Sep 13, 2014 at 23:42
  • \$\begingroup\$ Perspective projection. \$\endgroup\$
    – zduny
    Sep 13, 2014 at 23:43
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Ascendion
    Sep 14, 2014 at 2:20
  • \$\begingroup\$ 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. \$\endgroup\$ Sep 14, 2014 at 10:11
  • \$\begingroup\$ If anyone can think of a shorter title that describes the question well, I'd appreciate it. :) \$\endgroup\$
    – Anko
    Jan 3, 2015 at 22:18

1 Answer 1

1
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .