Mutant Amoeba Development a peek behind the scenes at the MAD lair

20Jul/120

Tiles as offset lookups into an arbitrary texture

 

This one's been on my mind for a while now, but after seeing its effective use in Dynamite Jack and Prison Architect it's a go-ahead.

note the ground tiles and how they're not constrained to wall size. This could be achieved with multiple wall-sized tiles, but why bother?

The gist is that instead of using a specific image for each grid point in a map, you instead do a wrapped lookup into that texture so that it can be larger (or smaller) than the grid size itself.  Fairly basic stuff.  Just imagine a texture repeated across the screen and then masked so it only shows on tiles that match. (that's not how you'd implement it, but seems like a clearer image)

However there's an implementation detail which I find interesting: originally I was just going to allow images whose dimensions were a multiple of the tile size, this is easy to code and makes wrapping trivial when using a sprite sheet.  We can also render the tile map by having a fixed grid of points already attached in the graphics card and then simply going through and dynamically changing the UVs for each point whenever the map moves by a whole tile or more.

Dynamite Jack

Again note the ground tiles aren't constrained to wall size. Also note that I'm quietly ignoring how similar our games look. Maybe I shouldn't add that flashlight after all? :)

An nice alternative which would definitely help "break up the grid" is allowing completely arbitrary texture sizes, which would be just as easy to implement if we used a separate texture for every tile, but texture changes are horrendously (and notoriously) slow so that's not an option.  However, using sprite sheets means we can't rely on the hardware to automatically wrap tile images (as it'd simply show adjacent images from within the sheet rather than wrapping at the tile boundary).

The only solution which leaps out at me is to implement the whole tile rendering side of things in a GLSL shader so that we can manually wrap texture coordinates at the appropriate tile boundaries.

Seems simple enough, and it'll mean I finally need to learn how to send arrays to a shader from Java..  Something about IntBuffer objects which seem simple enough but are a little odd.  Not sure why it can't just be a reference to a flat array like in C..

Ho hum!

Hands On: Prison Architect | Rock, Paper, Shotgun.

Posted by pentaphobe

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

No trackbacks yet.