Or, what constitutes resolution...
You may have seen a lot of routes and have likely noticed that some have very detailed textures, and some others don't. Some even have textures that are so large that you can approach the objects very closely without losing detail, but would not be able to notice the detail from the cab.
This topic is for informational purposes. As a route or train developer, you may have asked the question: How large should I make my textures? Of course, everything starts with the source material. If you have very small photographs, then you can do very little about it but to use what you have. And if you have very large ones, would it be worth including them, or would it be better to make them smaller?
In this topic, I want to present a means to judge the quality of textures, and to give a rule-of-thumb to answer the questions.
Background
First of all, what even is high-res and low-res? Well, the naive approach would be to look at the size of your textures. If you have a 32x32 texture, that's low-res, and if you have a 512x512 texture, that's high-res. But actually, you can't look at your textures like this.
The first thing to take into account is the size of the object against you project your texture. If you map a 512x512 texture against a building of 50m height, then you have 512px / 50m = 10.24 px/m of vertical density. On the other hand, if you map a 32x32 texture against a clock of 0.8m height, then you have 32px / 0.8m = 40 px/m of vertical density. So actually, the clock would have four times the vertical resolution than the building, even though it uses a much smaller texture.
Working with pixel density is therefore a good start, but it's not enough. You still have to take into account that objects are at different distance from the cab than others. If, for example, the clock is at 3m distance from the camera, but the building at 50m, we will later see that the building actually has four times the resolution of the clock, and not vice versa.
The last thing to take into account is the monitor resolution. If you position yourself so that the object fits perfectly the vertical resolution of your monitor, then obviously, if the texture is larger than your monitor, every further detail will be for nothing and just wastes hard disk space, and more importantly, video RAM.
A mathematical approach
If you are not interested in the mathematical derivation of my judgement formula, just skip to the next section.
Given:
- The vertical viewing angle a in radians,
- the vertical display resolution r in pixels,
- the height of the object h in meters,
- the height of the texture t in pixels,
- and the smallest occuring distance to the cab d in meters,
Given the vertical viewing angle a and the distance d to the object, the height y which fills the screen exactly is:
y = 2 d tan(a/2)
Assuming that the actual height h of the object is exactly the ideal height y, our final resolution coefficient c could be expressed using the vertical screen resolution r as simple as:
c = t / r
We can create a final formula by correcting by the ratio between the ideal height y and the actual height of the object h as follows:
c = t y / (h r)
We can expand this to:
c = 2 d t tan(a/2) / (h r)
Or, given that we assumed that a is fixed at 45° and r at 1050 pixels, this is our rule-of-thumb judgement for resolution:
c = 0.00078897821404399 d t / h
Interpreting the coefficient
In words for those who skipped the previous section, if we have the DistanceToTheCab our object is placed at, the HeightOfTheTexture the object uses, and the HeightOfTheObject itself, we can calculate a coefficient to judge how high-res our texture on that object at that distance really is:
Coefficient = 0.00078897821404399 * DistanceToTheCab * HeightOfTheTexture / HeightOfTheObject
Assuming that we face our object from the distance we assumed, then a coefficient of 1 means that for every screen pixel, we would have exactly one pixel in the texture corresponding to it. That is for all practical purposes often too good of a quality already. But, everything larger than 1 means that unless we approach the object more closely, we won't see any further detail, because our monitor wouldn't be able to display it.
Let's take the initial examples of a clock and building again. If we have a clock at 3m distance, of 0.8m height and using a 32x32 texture, then our coefficient would be about 0.0946. A building at 50m distance, of 50m height and using a 512x512 texture, however, would have a coefficient of 0.4039. That's actually quite high-res, because it means that for about every 2 vertical pixels on our screen, we have 1 vertical pixel in the texture.
As said earlier on, a coefficient of 1 is actually too good. If you are impressed by HDTV or BluRays, then take into account that while they may have 1920x1080 of screen size, a still image is usually far from pixel-perfect, but rather blurry and smudgy. If we drive in our cab, we also have some sort of motion, and a pixel-perfect scenario is not usually noticable in motion. Also, take into account that most of the faces aren't actually faced directly, but at an oblique angle. In this case, the texture is effectively squeezed into something much smaller on screen, one more time illustrating that a cofficient of 1 is actually more than enough.
So what is low-res and high-res, and how large to make my textures?
Actually, we can't quite yet answer the first question, because we would need to have reference values for the coefficient. Assuming we had some reference values, the answer to the second question is easy:
HeightOfTheTexture = 1267.46212024588 * Coefficent * HeightOfTheObject / DistanceToTheCab
Reference values
I have inspected some objects in some routes to create some reference values. If you know the routes and the particular objects, and have a feeling on how good the textures look like, then compare against the following values.
Cars in openBVE's DemoRoute1 (URL)
Distance: 17m
Height: 2m
Texture: 128px
Coefficient: 0.86
Subjective judgement: The texture is too large. Some detail is hard or impossible to notice, especially when farther away.
Trees in Birmingham Cross City South v1.3 (URL)
Distance: 7m
Height: 8.3m
Texture: 128px
Coefficient: 0.09
Subjective judgement: The textures are way too small, even if farther away.
Shop on Narita Line (URL)
Distance: 20m
Height: 7.6m
Texture: 64px
Coefficient: 0.13
Subjective judgement: The textures could be more detailed, but are generally acceptable.
Stairs on Ginza Line (URL)
Distance: 10m
Height: 4.4m
Texture: 64px
Coefficient: 0.11
Subjective judgement: The textures could be more detailed, but are generally acceptable.
Depot on Blueridge Line (URL)
Distance: 13m
Height: 7.0m
Texture: 128px
Coefficient: 0.19
Subjective judgement: The textures are detailed enough, but improvements would still be noticable.
Judging from this small chart, it would seem at a coefficient of about 0.20 onwards could be considered good resolution, while anything about 0.80 onward is just too large and wastes space. Please also take into account that I took into consideration a screen resolution of 1680x1050. If your screen is smaller in the vertical, then the situation improves radically, and given that some of the depicted routes are quite old and were meant for much smaller screens, their textures are actually relatively good.
If we agreed on a coefficient of about 0.3, then our rule-of-thumb formula simplifies to about:
HeightOfTheTexture = 380 * HeightOfTheObject / DistanceToTheCab
So if you ask yourself how large to make a texture to look good on a particular object, this would be very rough rule-of-thumb formula. Mind to round the value to the nearest power-of-two, though.
Bottom line
Of course, it should be noted that the size of the texture alone isn't the whole matter. The difference between a pixel-perfect texture and a smudgy and blurry texture is often what matters most. Think of it this way: If you reduce your texture in half and then scale it back up to normal again, and can't make a substantial perceptual difference, then your texture is just not worth its own resolution and should be reduced in size. Only then, a comparison is any meaningful, if at all. Other factors such as the surrounding textures and lighting conditions also play an important role in whether a texture is perceived as detailed or not. In a dark scene, you can generally cut your textures in size without noticing, for example.
So what's the end result... I don't know, I just wanted to find an objective way to judge the quality of a texture under given circumstances. Maybe it helps you finding an appropriate texture size of an object you are building, maybe it doesn't.
