- Home /
Calculating Texel ratio
How would I go about calculating the texel ratio of a texture? As an example let's say I decide to have a texture of 512x512px that should fill a 1x1 metre space in Unity3D. How do I figure out how many texels are projected in that 1 metre?
Answer by cjdev · Aug 22, 2015 at 09:32 PM
From what little I understand on the topic (and it is very little) the number of texels is determined by the distance of the texture from the camera and the kind of interpolation used in rendering. Assuming bilinear interpolation, OpenGL will use at most 4 texels to render a pixel during magnification all the way down to a single texel during minification (when the texture is a single pixel). With these numbers I think you could calculate the number of texels by first getting the distance from the camera where the 512px texture on that 1x1m surface in world space fills 512x512px in screen space and then where in world space it is 1024x1024px in screen space. You could then extrapolate for any distance value between or below to find the number of texels since you know the point for the maximum number of texels (1024) and another point in the line (512). For anything closer than the case of 1024px you can just use it as a constant to divide for the new density.
I'm not quite sure I've got all that right but hopefully it's something that can point you in the right direction.
Thanks for the explanation cjdev! So I understand that texel size is actually dynamic depending on how close the camera is. That explains why there isn't much matter on the net trying to explain how to calculate the ratio.
$$anonymous$$aybe it's not important at all to know the ratio. I'm creating a modular set of 3D models and textures and thought it would be useful to know the texel ratio.
For the most part I think the ratio isn't too important, your concern is likely going to be with how big to make the textures and still have it look good. People just let OpenGL handle the specifics under the hood as deciding on a texture resolution is more of an art than a science with all the varying distances and interpolations involved. If I were you I'd create the first model with a high res texture and check it out in Unity at the distance and size you intend for it to be displayed then scale down your texture accordingly.
Answer by FortisVenaliter · Aug 21, 2015 at 04:15 PM
Well, if you know those values, then it would be 512/1m or 512 pixels per meter. Maybe I'm not understanding the question?
That would be pixels per metre but I meant to calculate texels. And they aren't the same, right? Calculating the texel ratio (or density) seems to be something of an elusive topic because I can't find anything particular on it.
What I mean is: If I use a 512px texture for a 1m space in Unity the texture resolution is quite acceptable but if you get close then you can see blurry spots. That's what the texel density is about. What interests me is how many texels are projected across that 1m distance.
@avalonsutra:
Well, a TexEl and a pixel mean technically the same thing. It just depends on the usage. Since textures in 3d aren't just displayed like a raster graphic we don't call them pixels but simply "texture element" (tex - el).
Units like "meter" actually don't belong to a virtual world. It is just common to assume 1 world unit is 1 meter. And of course if you map a 512x512 texture onto a 1x1 unit quad in world space than you have 512 texels in one world unit.
That mapping has nothing to do with the actual rendering and rasterizing on the screen which is something completely different and depends on the camera projection abd finally on the texture filtering method used (like @cjdev explained quite well).
In your comment you said "I thought it would be useful to know the texel ratio", but useful for what? If you are a 3d artist you should try to have a similar density on your mesh, but in some cases it might even make sense to have certain parts of a model with a higher density. This is sometimes done for human characters where the face texture has a greater resolution than the rest but usually not by much otherwise the cut might get visible.
Note: in your example you said you map the entire texture to a 1x1 square. However it's also possible to only map a part of the texture to a triangle / quad / part of the mesh. The ratio is simply the ratio between "a" and "b" where a is the distance between two vertices of your mesh and b is the distance between those two vertices in texture space (uv-space). Since texture space is in the range of 0 - 1 you have to multiply by your texture resolution to get how many texels there are per world unit
Example:
a quad with the 4 corners: (-1,-1,0), (1,-1,0) , (1,1,0), (-1,1,0) and those 4 uv coords: (0.2, 0.2), (0.5, 0.2), (0.5,0.5,), (0.2, 0.5)
If you just use the first two vertices: a = (-1,-1,0) - (1,-1,0) == (-2, 0, 0) == length "2" so 2 world units b = (0.2, 0.2) - (0.5, 0.2) == (-0.3, 0) == length "0.3" in texture space
textureUnitsPerWorldUnit = b / a texelsPerWorldUnit = (b / a) * textureResolution
So for a 512x512 pixel / texel texture you get about 76.8 texels per world unit. $$anonymous$$eep in $$anonymous$$d that in my example i only mapped a tiny part of the texture to the quad (only 30% of it's width).
As already said if you map the entire texture to exactly 1 world unit the worldunit - texel ratio is just your texture resolution.
Answer by soleron · Apr 07, 2018 at 03:55 PM
This is a very confusing subject. Many people misunderstand the concept and believe that using a 4K or 8K texture means they have used a very high resolution texture, which is not necessarily the case.
Simply put, the concept of Texels is similar to the DPI/PPI (dots per inch/pixels per inch) in printing. And it is usually referring to the Texel Ratio.
It's based on the relations of many things, screen resolution, complexity of a model, size on screen, surface coverage of the texture on the object, etc. etc. i.e. on a device with 640x480 display resolution a 2K texture on a plane is an overkill, but a 2K texture atlas for an entire building is not.
There is no fixed rule really, simply because there are no standards on the way people model anything or in some cases, even on the final resolution. So, in order to calculate this we usually experiment on several categories of assets using the intended platform devices during preproduction, and provide with the best average per asset and device type. (Which makes it somehow easier on consoles than mobile devices, although thankfully most respectable game engines take care of that automatically.)
After testing we can say that for characters the texel ratio is that much, or for buildings is that much, etc. etc. the final value comes to pixels per cm/inch or meters/feet based on the size of our object. i.e. a small door knob, may actually have a higher texel ratio than your entire door if your UV layout is imbalanced. (i.e. in the UV page, you dedicated more texture area coverage per cm on your door knob than the entire door on the UV space.) If you pack too many items in a single UV page, which is the case with detail atlases, lightmaps, etc. you should be careful not to overdo it else you are dispersing your texel ratio and eventually, even in an 8K texture your texture resolution per object could be too low. (Which is often the case with lightmaps and detail maps.)
Your answer
Follow this Question
Related Questions
Get texture pixels under a plane 1 Answer
get pixel from a texture 1 Answer
Perfect 2d image 1 Answer
How can i avoid mouse clicking on alpha areas in my GUITexture? 1 Answer