3D 3D Shader Help

I was wondering if it is possible to modify Gamemaker's general shader to use a z variable in addition to the already-present x and y variables. If so, how would this be done? Through the pixel or vertex shader? What shader code would have to be written? Would it automatically use the z var, or would that have to be done in another shader? What would that other shader or script look like? Could I also have the shader automatically render shadows? I use Gamemaker Studio 1.4, or whatever version the original is at.


I do not know the answer, but I am curious, why are you using Gamemaker for 3d? I have heard that Unity/Unreal are better suited for 3d projects, while GameMaker is more ideal for 2d.
I also have heard that, but Unity only runs, at maximum, around 9 FPS for the demo projects, so I don't use them. I am also much more, let's say, fluent in GML than any of Unity's languages. I have Unreal, but it is giving me trouble with running, taking around an hour to start.


The forum's immigrant
I dont know what you mean by Game Maker's general shader... I mean if you are trying to pass a z variable into Game Maker, you can do that simply by assign a personal z local variable for every entity in your game. And pass that as uniform into a shader. Shaders should already handle z depth as well using the position attribute.

Could you explain more on what you really need?
The default shader already uses x,y,z. If you turn on perspective you would see that even sprites that are drawn at different depths will have different z values.
I am meaning a z which can be used in collisions, and one which would work as naturally in gamemaker's functions, or which can be made to, as the x and y variables. I also want it to be able to be used for gravity automatically, if possible, and in gamemaker's physics engine.


I'm not sure if you correctly know how shaders work.

Shaders have their own programming languages, that isn't intertwined with Game Maker Language. You can pass in textures, models and variables to the shader and the shader can return a surface, but that's the only link between the two languages.
OK, then how would I pass in a 3d model from, say blender, into a shader, which would translate it into GML compatible images? How would the most effective and efficient way to do 3d collisions and physics and etc. be? Also, you're correct in assuming I'm new to shaders. I thought this would be the most useful and applicable way to learn them.


To say that you want to pass a 3d model from blender into a shader into a GM image is about as incorrect as it gets =P

You need to learn a bit of what's going on under-the-hood in graphics programming to understand how to do this stuff.

Firstly, you have your hardware. Your CPU and GPU. The CPU controls all of the logic in your game. It can also be used to initially load a file into Memory (RAM). When you want to draw anything (everything), the CPU tells the GPU that it would like to draw something. The GPU waits for the data and then draws it to a buffer. This buffer is then copied to the screen and you can visibly see it.

In the past, there weren't things like shaders, the rendering library did everything for you (DirectX/OpenGL). However, this is no longer the case. What you now have are shader programs. These are bits of code that you write, that are then compiled at run-time and sent off to the GPU. When you draw a bit of geometry (could be 3d or 2d they are both the same), it will run through your shader; Once for all vertices, once for all rasterized pixels.

Then when this stage is done all pixels that are outputted from the fragment shader will appear on the screen buffer (or whichever buffer is currently bound).

When you want to get a 3d model to draw. You need to first use Game Maker to define a 3d model. There are different ways you can do this. In old versions of Game Maker you are limited to using d3d_model_create(), and then populating it with vertices. In newer versions you have the vertex_buffers, which are much more powerful.

After a 3d model is defined, it is sent to the GPU and kept there for the duration of your program. When you draw it, the CPU just tells the GPU that you want to draw that model that is already loaded into the GPU's VRAM.

If you want to load an external model, you need to look into the actual model format. I believe someone wrote a blender-to-gamemaker importer (though I cannot find it). There is also a Blender-to-gamemaker model exporter.
TheSnidr also released a nice model format that works with Game Maker nicely.

Game Maker doesn't do any magic. Its renderer works like a renderer in any other language (except it is much more limited feature-wise).
  • Like
Reactions: Yal


šŸ§ *penguin noises*
GMC Elder
If you don't even know basic terms about 3D, trying to make something 3D might not be the best use of your time.

  • Shaders are only used for drawing. (They can be used to operate on data buffers as well to offload computations to the GPU, but that's not the intended way to use them)
  • Shaders can be used to distort a 3D mesh, and thus animate a 3D model.
  • 3D collisions are usually done with hitboxes that has nothing to do with what's actually drawn, it's faster that way and players generally won't notice the improved precision.
  • To draw a 3D model you need to load it and draw it, generally you'd use a texture for it too. In GM, you can only draw one texture per model but you can use ANY texture, letting you customize stuff by using alternate textures.
  • GM only has 2D collisions, you need to add your own Z variable - as a variable - and use that in ways you need it to.
You might be interested in my 3D platforming engine and my FPS engine.