Need some help with my tileengine

Hello guys,

I tried to port my tileengine from a real “tile”-engine to an “shader”-tileengine.
I’ve uploaded the sourcecode here: https://github.com/EnemyArea/TileEngineShaderTest, feel free to use it (non commercial only please)

As you can see on the screenshot, it looks very good. But I have some issues I want to get rid. I pass my tile-informations as a color to the shader. This color needs all four components, which is realy bad if I want some transparency for it.

new Color(worldmapTile.TextureIndexModMulti / 32, worldmapTile.TextureIndexDivMulti / 32, sourceRectAutotileX1, sourceRectAutotileY1);

the first to components are the x and y position in the tileset and then position for the quad-tile-part of the full tile (One tile is made of 4 smaller tiles, to get the autotiling to work). This is exacly my problem. I looking for a good way to just use the rgb-component and keep the a-component free for transparency. In the moment I use a ‘colorkey’ to have a transparent color.

Have you guys some idears to optimize that shader and my code maybe?

Thank you :slight_smile:

PS: you guys must change this here:
/outputDir:…\bin\Windows\x86\Debug\Content
to
/outputDir:bin/$(Platform)
in your Content.mgcb to get the content to work

So for each tile you want to pass 5 values to the shader, but there’s only 4 components, correct? Possible solutions:

  • use a second texture
  • use 1 texture only, but use 2 pixels per tile instead of 1
  • compress 2 values into 1 component. Does TextureIndexModMulti / 32 by any chance mean that there is only 8 possible values? If so you can put two such values into one 0…255 component: col.r = val1 * 8 + val2. And to extract: val1 = floor(col.r / 8); val2 = col.r - val1 * 8;

Hi markus,

thank you for the reply! I want to keep my texture as small as possible. So multiple or larger textures are not an option.
I thought about to skip the 4 tile-pieces scenario to press the information into one color component, but my skills in shader development are still not that good.
With your suggestion I can maybe get back my a-component, thats nice! Hopefully we find an solution for the other thing too :slight_smile:

Greetings
EnemyArea

easy bit shifting operations… u have 32 bits in color values.
high << 16 | lower & 0xFFFF

reverse

lower = value & 0xFFFF
high = value >> 16

or u use all 3 values and only 8 bits per value. to have 24 bits on each value. a litle bit more complexe compression but possible