• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Shaders Using samplerCube in GMS2

F

Freddie The Potato

Guest
Heya

SamplerCubes are a GLSL feature that allows you to group 6 2D textures together to form a cube (1 texture for each face). You can then use GLSL's textureCube function with a directional vector to grab a color from inside the cube.
Usually in order to use the textureCube function, the user first needs to create a samplerCube object and pass it into the shader. However, GMS2 seems to lack this functionality (at least from what I can see.) There are no uniform functions that allow you to create samplerCubes and pass them into the shader.
The only alternative I can think of is packing all 6 face textures into one 2D texture, then somehow converting the components of a 3D directional vector into a 2D texture coordinate in order to grab a color from the correct face.
Is this the only solution? Any tips would be greatly appreciated :)
 

kraifpatrik

(edited)
GameMaker Dev.
Hey there,

as far as I am aware, what you have described is the common way of doing cube mapping in GM. If you are interested, you can find an example implementation in my repo https://github.com/GameMakerDiscord/Xpanda/blob/master/Xshaders/CubeMapping.xsh, or if you would like to implement it yourself, you can find the official description of the ARB_texture_cube_map extension here https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_texture_cube_map.txt. It also contains the formula for converting 3D vector into UV (you will just have to scale them and move them around a bit, since all the sides will be in a single texture).

Good luck with you project!
 
F

Freddie The Potato

Guest
Thanks for the response! These are some really helpful examples :)
 
Top