Texture Atlas for sprites+tilemaps

Home Forums Monkey 2 Development Texture Atlas for sprites+tilemaps

This topic contains 5 replies, has 3 voices, and was last updated by  Hezkore 1 month ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #9888


    I’m currently interested in getting 2D graphics into a 3D environment, and have been working on a class that makes it easy to “slice” an image into an atlas (like a spritesheet , or a tileset).

    Once it’s loaded, you can create a mesh containing a sprite or a tilemap and hook it up to a Mojo3D model. The format I use for sprite padding is the same Aseprite uses, and the tilemap .txt export is from PyxelEdit.

    I want to share it in the Code Library section, but there’s a few things to figure out before I do that, like:

    • How do I change the texture coordinates in an existing mesh, without creating a new replacement mesh?
    • Mesh based sprites don’t look good yet, since there’s no transparency.

    Anyway, I’ve attached it since the Forum won’t let me post code lately.




    Space cats! \o/

    You can get some transparency by using ‘discard’ in your own material shader.
    if( texture2D( m_EmissiveTexture,v_TexCoord0 ).a < 0.5 ) discard;

    Seen here on the vines: http://monkeycoder.co.nz/forums/topic/quake-bsp-loading/page/2/#post-9288



    While I can look at a shader and more or less understand what it does, the way it “connects” to Mojo (how you pass a variable or a texture from within Monkey2 code, for instance) is still very opaque to me… are there are shader tutorials specifically made for Mojo?

    (yes I’m a programming noob)


    Mark Sibly

    I’m a bit unclear on what you’re actually doing here, ie: what are you using 3d for? Maybe just go with a 2d system?  You can always draw 2d stuff to a 3d texture, ala insectoids demo in b3d. If you’re using images, you’re really in the 2d realm anyway I guess.

    There’s still no transparency in 3d yet because I would like to try to make it ‘more correct’ (probably wont be 100% correct however I do it) than I have in the past and aren’t quite sure show yet (!) – but it’s likely to be overkill for your needs here I suspect!



    Hi Mark, it’s just an experiment. But I do want the ability to use “traditional” 2D systems in 3D, so I can mix & match depending on the aesthetics I want ( the game “Don’t Starve” is probably a good example of that). Besides, it’s a lot of fun for me since I can play with generating the meshes from scratch, something I’ve never done before!

    Also, even if the look is completely 2D, doing it in 3D still has a lot of advantages, like proper occlusion behind objects without breaking things into multiple layers, easily adding “line scrolling” (which, in this case, would be real geometry) and 3D elements to the graphics, even adding real lighting and shadows to seemingly 2d graphics.




    Look up ‘modules/mojo3d/graphics/pbrmaterial.monkey2’ (Or hit F2 on PbrMaterial in Ted2Go)
    You’ll get a clearer view of how it’s done.
    You can extend that class, but change ‘Shader.Open’ from ‘material’ to ‘yourShaderWithTransparency’

    I guess you could also do something like this to the normal PbrMaterial
    ‘material.Shader=New Shader( name, LoadString( pathToShader ) )’
    Or maybe just ‘Shader.Open’ there?
    I haven’t tested, but should work.
    But Mark might yell at you for doing something like that…

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.