Not logged inOpenClonk Forum
Up Topic Development / Developer's Corner / Background materials
- - By Maikel Date 2015-08-08 15:16
A nice new feature has been completed by ck, which introduces background materials. This can be used to prevent flowing liquids to overwrite the tunnel texture, but also to have infinite reappearing of liquids.

There has not been a discussion on this and I have a few questions/comments:

* What will happen internally when I put background material to water at some point in the landscape and rock in front and then blast the rock? It seems that once the normal material is blasted the water at those points in the landscape move to the foreground to create a flood. Some detailed explanation would be nice to have.

* Since we now have 255 indexes free for materials, should we reorder them more sensibly in the TexMap? Also the comment "# Index +128 for underground materials" is obsolete.

* In the editor, the sky texture is greyed out but not set to none, to be consistent it should be set to none. Also, when I select sky as foreground the background is greyed out and equals sky, is there a reason for that? Tunnel can have background materials, which is a bit inconsistent somehow.

* The bucket of paint tool I can't select when drawing a landscape.

I guess that is it after a first round of testing, great feature though! I will definitely use it in some of the existing maps.
Parent - - By Clonk-Karl [us] Date 2015-08-08 16:33 Edited 2015-08-08 16:37
There has been a brief discussion in the bugtracker. I just thought I push it early because otherwise I don't get people to use/test it anyway. The primary motivation for me is that loam bridges and moving liquids preserve the background material and texture, which comes for free without having to modify any existing maps.

> This can be used to prevent flowing liquids to overwrite the tunnel texture, but also to have infinite reappearing of liquids.


Or also infinite gold mines :), or indestructible granite.

> What will happen internally when I put background material to water at some point in the landscape and rock in front and then blast the rock? It seems that once the normal material is blasted the water at those points in the landscape move to the foreground to create a flood. Some detailed explanation would be nice to have.


What happens is that simply when a pixel is cleared, e.g. by digging or blasting, instead of either creating tunnel or sky where the pixel was, the pixel is changed to the background material. Afterwards, both the foreground and background materials are the same. When building loam bridges, or when the MassMover moves liquid around, it only changes the foreground material and leaves the background material as it is.

> Since we now have 255 indexes free for materials, should we reorder them more sensibly in the TexMap? Also the comment "# Index +128 for underground materials" is obsolete.


The index 255 is reserved for internal use, so in fact there are "only" 254 indices available (and 0 is always sky). In order to preserve backwards compatibility, the "index + 128 for underground" is still true for Map.bmp maps. If you want to make use of the full set of 254 indices, use a file MapFg.bmp instead (MapBg.bmp can then be used to specify the background materials). For other map types such as Map.c there is no such restriction (see the documentation for how to draw background materials with Map.c scripts).

> In the editor, the sky texture is greyed out but not set to none, to be consistent it should be set to none. Also, when I select sky as foreground the background is greyed out and equals sky, is there a reason for that? Tunnel can have background materials, which is a bit inconsistent somehow.


Sky has always been somewhat special, e.g. it does not have a texture compared to all other materials. But the major reason I think is just that it doesn't seem to make sense that there could be something "behind" sky. I'm not even sure what would happen at the moment if you have sky with say tunnel as background material and start to dig around in the sky region... but I don't have a very strong opinion on it, and it can be easily changed.

> The bucket of paint tool I can't select when drawing a landscape.


If I remember correctly that tool only works in exact landscape mode, but it has always been like that. Did you try that? Otherwise sounds like a bug...
Reply
Parent - - By Sven2 [us] Date 2015-08-08 16:42

> Or also infinite gold mines :), or indestructible granite.


That's good! It could be used in Krakatoa so we can remove the wall0kit hack there.

(Although of course preferable would be to have another brick texture instead).

Btw infinite gold mines won't work because the gold will spawn locked into the material, right?
Parent - - By Maikel Date 2015-08-08 17:25
I think gold with background gold is infinite.

I am on vacation tomorrow and then travelling for work afterwards, but I will fix Krakatoa using the new system afterwards. I think even more worlds can profit from this. like Flooded Veins to ensure water on insane difficulty.
Parent - By Sven2 [us] Date 2015-08-09 01:38
Krakatoa could do brick behind granite. Then people would see at least after blasting that it's hopeless to go through there.

Also, it could make the side wall destructible on easy difficulty.
Parent - - By Clonk-Karl [us] Date 2015-08-08 23:11

> Btw infinite gold mines won't work because the gold will spawn locked into the material, right?


No, it actually works. The gold spawns at the same location at which the flint exploded, which is still outside the material.
Reply
Parent - By Sven2 [us] Date 2015-08-09 01:38
Oh, you're right. Now that's kinda cool :)
Parent - - By Newton [de] Date 2015-08-08 18:14
Does this mean that if you blast through rock, you see rock in the background and not "tunnel" (earth)?
Parent - - By Sven2 [us] Date 2015-08-08 18:30
No. It means that if you blast rock, rock is created. I.e. rock is indestructible in that place. We can now set which material appears when the previous material is removed (e.g.: Have a lake and if the water is removed, solid gold appears behind. Of course you couldn't blast that gold though ;) ).
Parent - - By Caesar [jp] Date 2015-08-09 00:18
But we could make background materials (blasted stone vein → stone background), right? It would probably be confusing, though…
Parent - By Matthias [de] Date 2015-08-09 05:38
The textures have to be very clear, but I think it is possible. it would only need to be a different texture, not a whole material!
Reply
Parent - By Newton [de] Date 2015-08-09 09:15
Yes that would be cool.
Parent - - By Pyrit Date 2015-08-09 12:46
It would be a pain in the butt to always see that non-minable ore in the background.
Parent - By Matthias [de] Date 2015-08-09 20:54
Nah
Reply
Parent - - By Sven2 [us] Date 2015-08-18 02:41
By the way, one unfortunate "feature" is that when zooming map to landscape, background materials are always drawn with the same shape as the foreground material.

This means that, if I alternate brick and tunnel backgrounds behind a lava lake, the background bricks will always be square (which is OK for the current brick texture, but might look weird if it is changed).
Parent - - By Clonk-Karl [us] Date 2015-08-21 01:16

>  By the way, one unfortunate "feature" is that when zooming map to landscape, background materials are always drawn with the same shape as the foreground material.


The motivation behind this was basically that for example a goldmine could have tunnel with a different texture as a backgroud, and then after blasting it away one could still see where the goldmine once was.

Do you have ideas how to do it differently, or maybe different options we could provide?
Reply
Parent - By Sven2 [us] Date 2015-08-21 01:53
It's pretty difficult actually. We would want to draw in the shape of the background material instead of foreground material, but with the caveats:
* The background shape must not cover a smaller area than the foreground shape. Otherwise, borders of the outer foreground shape would not be covered with the proper background
* If the background shape is larger than the foreground shape, we do not want to expand it over different materials. Otherwise, e.g. a tunnel background on the top of a flat lake would stick out of the top and become visible under weird conditions, like when someone builds + digs away a loam bridge

One way to achieve this would be the following:
1. Draw background in foreground shape as it is done right now.
2. Afterwards, do a second ChunkOZoom pass over each MatTex entry for the background, where the background is drawn in background shape with an AND operation to the condition that the foreground material is the same as the one of the corresponding chunk.

I don't know if that small feature is worth doing a second ChunkOZoom-pass. It could be accelerated greatly by doing some sanity checks, such as drawing chunks only if one of the borders has a different background mat and if the background shape is larger than the foreground shape, but it's still a bit of coding effort for little gain.
Parent - By Sven2 [us] Date 2015-08-21 01:56
Also, it would have to run with exactly the same seed because otherwise background changes within the same material would cause the shape to become larger.
- - By Maikel Date 2015-08-17 09:03
How do SetPixel, GetPixel and CreateMatTexMask work in map scripts with the new materials?

I'd like to use this to loop over some part of the map and use those functions to set the background material of that part of the map.
Parent - - By Clonk-Karl Date 2015-08-18 02:21 Edited 2015-08-18 02:25

>  How do SetPixel, GetPixel and CreateMatTexMask work in map scripts with the new materials?


Whoops, looks like I forgot something here. There are still some todos in the code that I seem to have missed:

// TODO: Add function to get background pixel

My plan was to add a function GetBackPixel() to query the background pixel value, and add another parameter to SetPixel() to set the background material (can be nil for "keep current"). For CreateMatTexMask I'd either return a 512-bool array, or add a CreateBackMatTexMask.

Actually, for SetPixel something like SetPixel(x, y, "Brick:Tunnel-BrickBack"); should work already, but it's not yet possible to set the background material by index.
Reply
Parent - - By Sven2 [us] Date 2015-08-18 02:33
I think we should have a script function GetMaterialTextureIndex, which resolves the MatTex name to an index.

The current workaround in map scripts is to do e.g. this in the beginning:

SetPixel(0,0,"Granite");
var granite_index = GetPixel(0,0);
Parent - - By Maikel Date 2015-08-18 07:05
Yes, I was missing that function. SetPixel(x, y, fg, bkg) could then work with integers.

I never understood what CreateMatTexMask is useful for though.
Parent - - By Clonk-Karl Date 2015-08-19 00:23
I've made the following changes for now:

* Added int GetMaterialTextureIndex(string mattex);
* Added int GetBackPixel(int x, int y)
* Added int GetDefaultBackgroundIndex(string | int);
* Changed SetPixel to SetPixel(x, y, fg, bg); fg and bg can be a string or an integer or nil. If nil, the value is unchanged.
Reply
Parent - By Maikel Date 2015-08-19 06:33
Very good, that last function makes my life a lot easier.
- - By Maikel Date 2015-08-19 18:53
Interestingly, although somewhat expected the game crashes (or hangs) when triggering an explosion of Firestone:Firestone material.
Parent - By Caesar [de] Date 2015-08-30 06:10
My guess: The explosion creates new firestone material and flings firestones iside that material, which immediately collide and trigger another explosion to repeat the process.
I don't think we should do anything about this…
Up Topic Development / Developer's Corner / Background materials

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill