[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]

## Making a Tilemap Shader Started by Caleb P Sep 15 2015 11:15 AM

29 replies to this topic
shader tiles
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#26

### thomas6

[GLOBAL: userInfoPane.html]
thomas6
• Contributor

• 824 posts
• Corona SDK

Ah yes... Okay, I see. Thanks for the superclear update!

[TOPIC: post.html]
#27

### StarCrunch

[GLOBAL: userInfoPane.html]
StarCrunch
• Contributor

• 758 posts
• Corona SDK

To add to Caleb's excellent summary, the difference in my technique for packing two values is that it encodes an integer[1] using exactly representable floating point values (refer to some of those links I mention above), then decodes them on the shader side accordingly.

Unfortunately, I'm stuck with what GLES 2.0 gives me, so I'm still unsure whether I have an exact decoding or just a good approximation;  thus the mention of a test. I'm at least heartened that it no longer wildly freaks out on some values.    (To give an analogy, think about trying different identities for, say, 1 - cos(x). Mathematically they're all equal, but in real-world computing, some might give more accurate / stable results than others. In this case I'm aiming for an equation that is 100% exact.)

[1] - Up to 20 bits, so  for example two integers from 0 to 1023, but able to just sneak in 1024 as well on a lowest-common-denominator device. Often these will only temporarily be integers, e.g. having undergone a math.floor(x * 1024) transformation, which will be undone once in the shader.

[TOPIC: post.html]
#28

### Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
• Corona Geek

• 1,424 posts
• Corona SDK

Wow, it's been a while. I've decided that, if uniform userdata is coming fairly soon, I'll just wait and go with that for clarity and "normal Corona-ness." I posted a topic about it here: https://forums.coronalabs.com/topic/59706-uniform-userdata/

- Caleb

[TOPIC: post.html]
#29

### davebollinger

[GLOBAL: userInfoPane.html]
davebollinger
• Corona Geek

• 1,239 posts
• Enterprise

Width of the layer in pixels, height of the layer in pixels (because GLSL sends coordinates in the range of [0,1]), tileset width in tiles, tileset height in tiles, width of each tile in pixels, height of each tile in pixels, and, preferably, margin and spacing of the tileset. That makes at least 6 inputs required, and ideally 8.

If you were willing to trade-off flexibility, might you require that the tileset scheme be one of a few supported configurations, then just pass a single number to describe it?  (getting a 4-for-1 deal, otherwise you'd fall back to conventional tile rendering for "atypical" tileset schemes)

for example,

tileset scheme "1" might decode to:  256x256 sheet, 16x16 tiles

tileset scheme "2" might decode to:  512x512 sheet, 32x32 tiles

tileset scheme "3" might decode to:  512x512 sheet, 30x30 tiles, border 1 for aa edge extrude

etc

[TOPIC: post.html]
#30

### Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
• Corona Geek

• 1,424 posts
• Corona SDK

Hm. Interesting idea. I'll think through it. Maybe a better way would be to encode only certain values as presets. That is, the layer width and height could be normal numbers, but the tile size could be presets, 'cause they're usually 16x16/32x32/64x64. Or, alternatively, I could assume people use square tiles and store tile size in one variable. Good stuff to think about; thanks for bringing this approach up.

- Caleb

[topic_controls]

[/topic_controls]