#Averaging combined tilemaplayer texture

1 messages · Page 1 of 1 (latest)

thick narwhal
#

Hey! I am trying to create a shader that takes a combined texture from multiple tilemaplayers and averages each 16x16 tile in that resulting image to one solid color. Is there such a shader already out there, maybe? I appreciate any pointers.

#

For example, the first few tiles at the top left from this image...turning into something like this:

sullen owl
#

I think you'd have an easier time reading the image in code and creating a new texture out of the average of the colors. All Texture2D resources have the get_image() function for this purpose.

That way you save up on GPU time AND don't have to rely on shaders (which are pretty limited)

Since shaders act on a pixel-per-pixel basis and the values are discarded every frame, i don't think you can read the rest of the pixel's values in a cheap manner. Altho if the Shader has a uniform with the texture to display, it can use the texture() function to check the color the image at various UV coordinates.
But again, it would be a lot of work for worse results.

proven shuttle
#

Yeah unfortunately godot's shader pipeline's a bit limited. You could in theory use WorldEnviorment's Compositor for this, but last I checked documentation's pretty bad, and it's a hassle to use. Is the map constantly updating/minimap need to be updated every frame? If not it's probably best to do as Nancok said and do it on the cpu side, and only update every so often/update sections at a time.

You might be able to make this process faster by pre-computing the average of each tile alone including alpha, then average those values at runtime. Wouldn't be prefect in every case and I'm mot sure on the best method. Like in the simple case of trees on top of land, you'd subtract the tree's alpha from the land's alpha and use the alpha's as weights in your average. so if the tree covered 70% of the tile the land would be at a 30% weight. But it seems tricky to get a good approximation for many tiles, and probably not worth the effort.

thick narwhal
#

Thanks, both of you! That has gotten me much further already, very quickly. I'm sure there is a lot I can optimise, but it is getting to where I want it to be. Thank you :)

Currently I am just pixel the first colour from the original image and filling an entire 16x16 tile with it, but I'll change that and find maybe the middle pixel or something like that. Yaay

sullen owl
#

You can get the average by summing all the values of the pixels and then dividing by the amount of pixels.

#

There may even be a function for that, not sure.