Latest Posts

Topic: nearest neighbor / point filter

Kusy
Avatar
Topic Opener
Joined: 2023-02-24, 19:21
Posts: 19
Ranking
Pry about Widelands
Posted at: 2024-04-27, 11:09

Sorry I feel like I asked this some time ago but can't find the post for the life of me. Is it possible to make Widelands not filter and blur the textures at all? As in use point filter / nearest neighbour filtering?


Top Quote
kaputtnik
Avatar
Joined: 2013-02-18, 20:48
Posts: 2550
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2024-04-29, 17:13

Are you referring to terrains?

For terrains it is not possible anymore to make two terrains NOT blur. For an explanation see this post of the corresponding PR.

In version 1.1 this was possible by changing the terrains dither_layer value: If two terrains had the same value for dither_layer they had hard edges. See Helpterrains for examples.


Top Quote
Kusy
Avatar
Topic Opener
Joined: 2023-02-24, 19:21
Posts: 19
Ranking
Pry about Widelands
Posted at: 2024-04-29, 18:36

No, I'm talking about texture filtering / resampling in general, not about blending.

I'm not going to pretend I know much about OpenGL, but from what I see Widelands uses bilinear filtering when zooming in to resample textures. Is it possible to switch to use nearest/point filter instead? I did some edits to shader files but it mostly resulted in crashes.

Also, wouldn't clamping to edges resolve the hack with textures being sampled at 0.99 UV size for terrains?

https://www.khronos.org/opengl/wiki/Sampler_Object

I'm asking because having textures blur out when zoomed in makes any attempt at creating pixelart adjacent assets kinda impossible and while I know it's a personal prefference, even when not using pixelart per se, I preffer the crisp look to blur.

Edited: 2024-04-29, 19:02

Top Quote
tothxa
Avatar
Joined: 2021-03-24, 12:44
Posts: 485
OS: antix / Debian
Version: some new PR I'm testing
Ranking
Tribe Member
Posted at: 2024-04-29, 19:05

Kusy wrote:

No, I'm talking about texture filtering / resampling in general, not about blending.

IMO this is only a problem (only actually visible) when upscaling, so the preferred solution is to provide high resolution images for all map objects in the game. I apologise for the slow progress of the blender re-exports...

from what I see Widelands uses bilinear filtering when zooming in to resample textures. Is it possible to switch to use nearest/point filter instead?

I don't think that would give good results, nearest point is usually extremely ugly... Unless you want to use only integer scales (I don't think widelands helps in that, except when going to the max zoom of 4x), where the blocky images may sometimes be preferable to the blurred ones...

Also, wouldn't clamping to edges resolve the hack with textures being sampled at 0.99 UV size for terrains?

Well, looks like you know quite a bit about OpenGL after all (compared to me anyway face-smile.png ) so you may try to do it and open a PR if you can get something nice out of it. Any help is welcome. face-smile.png


Top Quote
Kusy
Avatar
Topic Opener
Joined: 2023-02-24, 19:21
Posts: 19
Ranking
Pry about Widelands
Posted at: 2024-04-29, 19:17

tothxa wrote: IMO this is only a problem (only actually visible) when upscaling, so the preferred solution is to provide high resolution images for all map objects in the game. I apologise for the slow progress of the blender re-exports...

High resolution images are only a solution to the problem if that's the approach you choose to take with art. Sorry, I edited the post in the mean time so to readress that.

While I know this is the current approach to assets, having textures blur when zoomed in makes it impossible to work on assets that have a more retro / pixelart feel to it, if someone wanted to go for that look. Not having the option puts on hard limits on the art direction for addons.

Edited: 2024-04-29, 19:18

Top Quote
Kusy
Avatar
Topic Opener
Joined: 2023-02-24, 19:21
Posts: 19
Ranking
Pry about Widelands
Posted at: 2024-04-29, 19:36

Kusy wrote: Not having the option puts on hard limits on the art direction for addons.

Which by the way I know can be a valid choice if you're aiming for high level of consistency.


Top Quote
tothxa
Avatar
Joined: 2021-03-24, 12:44
Posts: 485
OS: antix / Debian
Version: some new PR I'm testing
Ranking
Tribe Member
Posted at: 2024-04-29, 20:53

If you go for the blocky look in an add-on, you can upscale your graphics without filtering to create the *_2.png and *_4.png images. Actually I'd already thought of doing that for the iconic bunny, so I've just tried it. Here's what it looks like in the editor at some non-integer scale between 3x and 4x:


Attachment:
bunny_and_duck.png

Top Quote
tothxa
Avatar
Joined: 2021-03-24, 12:44
Posts: 485
OS: antix / Debian
Version: some new PR I'm testing
Ranking
Tribe Member
Posted at: 2024-04-29, 20:54

And here are the used files (replace data/world/critters/{bunny,duck} with the contents of the zip)


Attachment:
bunny_and_duck.zip (56.6 KB)

Top Quote
Kusy
Avatar
Topic Opener
Joined: 2023-02-24, 19:21
Posts: 19
Ranking
Pry about Widelands
Posted at: 2024-04-29, 21:37

Alas, the ground's still blured into oblivion face-smile.png

No ammount of dancing around will change how the filtering affects some elements, not to mention doubling half the art assets doesn't exactly seem like a valid fix. I'll dig around with the shaders a bit more, see where it gets me.


Top Quote
Kusy
Avatar
Topic Opener
Joined: 2023-02-24, 19:21
Posts: 19
Ranking
Pry about Widelands
Posted at: 2024-04-30, 09:01

Ok. I'm semi-sure I found a way to change how the textures filter but I can't get around making a build (errors galore), never built an app in my life and this didn't work out to be the first time.

There are two instances of GL_LINEAR in the source. One is in texture.cc (widelands/src/graphic) and one in dither_program.cc (widelands/src/graphic/gl)

Changing parameters GL_LINEAR to GL_NEAREST in the first file or in both of them would likely do the trick.

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, static_cast<GLint>(GL_LINEAR));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, static_cast<GLint>(GL_LINEAR));

I'll try to build this when I have the time to poke around later in the week unless someone who knows how to do it out of the box can confirm it works.

Again, having this as an option in the game (a checkbox for nearest filtering / a droplist with the two or something in that vein) would be invaluable both from the perspective of players who prefer how it looks and anyone who wants to work on addons with a more pixelart feel to them.

Edited: 2024-04-30, 09:03

Top Quote