Stochastic Texture Sampling

For people working on the C++ code.
Post Reply
User avatar
Hybrid Dog
Member
Posts: 2856
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Stochastic Texture Sampling

by Hybrid Dog » Post

Currently textures in Minetest are repeating, for example here all cobblestone nodes are visually made up of the same small stones positioned in the same way everywhere:
stochastic_texture_sampling_off.jpg
stochastic_texture_sampling_off.jpg (114.41 KiB) Viewed 5713 times
With stochastic texture sampling, it is possible to re-use only high frequency details of textures, which makes nodes look more natural, adds visual variety, and prevents artifacts which are visible when a wall of the same node is watched from far away.
Here is the same image with stochastic texture sampling used for all nodes:
stochastic_texture_sampling_on.jpg
stochastic_texture_sampling_on.jpg (117.86 KiB) Viewed 5713 times
Whether stochastic texture sampling looks good depends on the texture, some parameters and opinion. In this case, it looks bad for the mese lamp (in my opinion) because the mese lamp texture should repeat.

I partly implemented stochastic texture sampling in Minetest some time ago and didn't continue because I don't know if it's worth the code complexity.

More screenshots: https://forum.minetest.net/viewtopic.ph ... 24#p423224

The code can be found on this branch in my Minetest fork: https://github.com/HybridDog/minetest/t ... e_sampling

In addition to stochastic texture sampling in Minetest, I have implemented a demonstration program in a single HTML page: https://hybriddog.github.io/stochastic_ ... ling_demo/
(source: https://github.com/HybridDog/stochastic ... ling_demo/)
It allows testing the algorithm with any SDR texture, for example default_stone.png:
stonet.png
stonet.png (63.04 KiB) Viewed 5713 times
It is also possible to implement the algorithm with SVG filters, which I have tried at https://codeberg.org/HybridDog/sts-svg
Last edited by Hybrid Dog on Sun Apr 13, 2025 10:34, edited 2 times in total.

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

Kazooo
Member
Posts: 34
Joined: Sat Apr 13, 2024 23:06
GitHub: Kazooo100
In-game: Kazooo

Re: Stochastic Texture Sampling

by Kazooo » Post

Looks cool! I know there is also seed related textures, called global textures, but MTG doesn't use them.

User avatar
Hybrid Dog
Member
Posts: 2856
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Stochastic Texture Sampling implemented with SVG filters

by Hybrid Dog » Post

Here is an example SVG image which makes the browser apply the algorithm:
Image
It works with Firefox but may show vertical line artifacts with Chromium and I haven't tested it with other browsers. The whole SVG is tileable.
The stochastic texture sampled image is default_stone.png from drummyfish's Hand Painted Pack texture pack, licensed under CC0-1.0.

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

User avatar
Blockhead
Moderator
Posts: 2502
Joined: Wed Jul 17, 2019 10:14
GitHub: Montandalar
IRC: Blockhead256
In-game: Blockhead Blockhead256
Location: Land Down Under
Contact:

Re: Stochastic Texture Sampling implemented with SVG filters

by Blockhead » Post

Hybrid Dog wrote:
Sat Apr 26, 2025 17:06
Here is an example SVG image which makes the browser apply the algorithm:
Image
It works with Firefox but may show vertical line artifacts with Chromium and I haven't tested it with other browsers. The whole SVG is tileable.
The stochastic texture sampled image is default_stone.png from drummyfish's Hand Painted Pack texture pack, licensed under CC0-1.0.
Wow, that's an interesting use of SVG. Not to place multiple instances of a vector graphic, but rearrange parts of a raster image.
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

User avatar
Linuxdirk
Member
Posts: 3285
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: Stochastic Texture Sampling

by Linuxdirk » Post

Just imagine, how good a grass texture would look like using this technique. Grass plains would actually look like grass plains and not like bathroom floors.

This should definitely make it into the engine!

User avatar
TumeniNodes
Member
Posts: 2983
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes
IRC: tumeninodes
In-game: TumeniNodes
Location: in the dark recesses of the mind
Contact:

Re: Stochastic Texture Sampling

by TumeniNodes » Post

Linuxdirk wrote:
Sun Apr 27, 2025 14:03
Just imagine, how good a grass texture would look like using this technique. Grass plains would actually look like grass plains and not like bathroom floors.

This should definitely make it into the engine!
Just adding 3 additional texture variants for grass, dirt, stone, etc. and adding the code as for "default:grass_1" so they distribute nicely during map generation would be a great visual improvement ..
each of these 1 thru 4 was done by simply rotating the texture 90 degrees for each variant, which is easy to due using the rotation modifier in the code (but I find it easier to just rotate in Gimp or something)
of course for textures like brick/block etc, requires an individual texture made for each due to the highlighting and shading for the brick/block itself, meaning using a base texture to rotate each time, and then adding the overlay, then flattening the image before exporting..
This isn't to take away from Hybrid Dog's work/experimenting here
Attachments
06.png
06.png (327.41 KiB) Viewed 1365 times
05.png
05.png (372.65 KiB) Viewed 1365 times
03.png
03.png (473.29 KiB) Viewed 1365 times
A Wonderful World

User avatar
TumeniNodes
Member
Posts: 2983
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes
IRC: tumeninodes
In-game: TumeniNodes
Location: in the dark recesses of the mind
Contact:

Re: Stochastic Texture Sampling

by TumeniNodes » Post

also taking my granite texture above and coloring it for grass,
Attachments
07.png
07.png (269.97 KiB) Viewed 1359 times
A Wonderful World

User avatar
Linuxdirk
Member
Posts: 3285
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: Stochastic Texture Sampling

by Linuxdirk » Post

TumeniNodes wrote:
Sun Apr 27, 2025 18:24
Just adding 3 additional texture variants for grass, dirt, stone, etc. and adding the code as for "default:grass_1" so they distribute nicely during map generation would be a great visual improvement ..
You mean, like for sounds? That would actually quite awesome and pretty much enough for a lot of use cases.

I once played with rotating nodes randomly on world generation. That was horribly laggy, slowed world generation down, and polluted the whole world with tons of metadata. Nowadays I’d likely use param2 rotations, which would be as slow, but at least it wouldn’t spam meta data all over the place :)
TumeniNodes wrote:
Sun Apr 27, 2025 18:24
This isn't to take away from Hybrid Dog's work/experimenting here
Absolutely. This is would be the most awesome visual improvement since the introduction of volumetric light.

User avatar
Wuzzy
Member
Posts: 4951
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

Re: Stochastic Texture Sampling

by Wuzzy » Post

I like this a lot.

I think a poor man's version of Stochastic Texture Sampling could be to just pick a portion of the output with the size equal to a multiple M of the original texture size and use that as a texture for a world-aligned texture with scale=M.

In other words, create a large texture out of the original, then make it span over multiple nodes. So it technically still repeats but it is much less noticable. It is very simple and doesn't need special code, just the node defintion and a texture you basically "extended" once using that algorithm.

I think a scale of 4 (for example: original texture is 16×16, so you make 64×64 out of it and make it span over 4 nodes) already gives so much variety that the repetition is much less obvious.

User avatar
TumeniNodes
Member
Posts: 2983
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes
IRC: tumeninodes
In-game: TumeniNodes
Location: in the dark recesses of the mind
Contact:

Re: Stochastic Texture Sampling

by TumeniNodes » Post

Wuzzy wrote:
Fri May 02, 2025 21:34
I like this a lot.

I think a poor man's version of Stochastic Texture Sampling could be to just pick a portion of the output with the size equal to a multiple M of the original texture size and use that as a texture for a world-aligned texture with scale=M.

In other words, create a large texture out of the original, then make it span over multiple nodes. So it technically still repeats but it is much less noticable. It is very simple and doesn't need special code, just the node defintion and a texture you basically "extended" once using that algorithm.

I think a scale of 4 (for example: original texture is 16×16, so you make 64×64 out of it and make it span over 4 nodes) already gives so much variety that the repetition is much less obvious.
I've tried that method in the past (krock had actually made me aware of the method), it's "ok" I guess but it creates large noticeable patches in open areas.
I still think work should be done on allowing nodes to call from multiple texture variants on a random basis, but without creating an entirely new, separate node for each texture
A Wonderful World

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest