• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

GMS 2 Customizing Mip Maps?

IGameArt

Member
So i'm hoping this is possible, but I'm not seeing any information about it in the manual. Is it possible to manually create mip maps for textures in your game by, say, packing each level to a texture page and telling the system what part of the page each mip level should use?

I'm not trying to change how mips work in my scene, but rather what each mip looks like.
 

Bart

WiseBart
I guess you've already had a look at the built-in functions to work with mipmapping.
But if I understand your question correctly you're trying to put all mip levels of a texture on a single texture page without using those built-in functions.

One way to do this is to add a sprite for each mip level and let GM's texture packer work out the positions on the page:



Seems like you can right-click on a sprite or a group of sprites to easily Assign Texture Page.

You can verify how the resulting texture page looks by using the Preview option under Options > Windows > Graphics:


To get the actual sprites you can use texturegroup_get_sprites with the name of the texture group.
For each of the sprites returned, you can then get the corresponding uvs using sprite_get_uvs.
With a couple of array_copys these values can be put in a single array that you send to the shader through a uniform.

In the vertex shader you then have to figure out a way to index them and retrieve the correct uvs, depending on the mip level you want to use for the current vertex.

The important thing is to keep the array indices the same between updates of the texture page and I'm not entirely sure if GM's texture packer guarantees that behind the scenes, e.g. suppose the texture page gets updated then you'll want mip level 0, 1, 2, etc. to stay at the same uv coordinates each time.
Although that's something you could get rid of entirely if you decide to not let GM do the texture packing and import your own texture page and uv layout from somewhere else (make sure to tick 'Separate Texture Page' on that sprite in that case).

Here's a quick example to show the basics of how this can be done:
(the sprites aren't exactly correct, they're simply scaled down versions of the 512x512 sprite)

Texture Groups and Coords Example
 
Last edited:
Top