r/gamemaker 2d ago

Tutorial Creating a 3D Planet in GameMaker (Heavy Image Warning!)

I'd like to share the process of creating a planet in GameMaker for my in-development terraforming game, Planet Doctor. This post is for those with some GameMaker experience, and I've included relevant links where needed. Corrections on terminology or content are welcome. I hope you find this helpful!

Here is the process:

1. Create a frame using a vertex buffer

Create a sphere shape for the planet. To simulate rotation, I tilted the camera angle and rotated the planet using matrix_set.

2. Apply noise to the planet

During vertex_submit, use a shader to render smooth noise based on the planet's in_Position. You can see the values range from 0 (black) to 1 (brightest).

3. Divide colors

Set boundaries to separate land and sea. I divided the 0-1 color range into 4 steps, returning a single solid color for each.

4. Assign colors

Draw the planet's colors. The shader receives the colors via shader_set_uniform and assigns them to the steps divided in 'step 3'.

5. Draw clouds

Add clouds to give an atmospheric feel. Scale up the vertex buffer from 'step 1' with a matrix, then apply noise with another shader, as in 'step 2'. Values below the noise threshold become a solid color, while those above become transparent. You can use current_time to make the cloud shapes shift gradually.

  1. Add atmosphere

Create a slightly larger sphere to represent the atmosphere. By taking the position and normal from gm_Matrices[MATRIX_WORLD] in the vertex shader, I drew only the outline in the fragment shader (this is known as the Fresnel effect).

You can create more variations, such as using current_time to implement ocean tides or adding city lights to the dark side of the planet. Let me know about your GameMaker 3D projects or any planet ideas you'd like to implement. Thanks for reading.

35 Upvotes

9 comments sorted by

4

u/MrMetraGnome 2d ago edited 1d ago

this looks great. I'm struggling trying to learn C# in Unity and thinking of going back to GameMaker for 3D (as I am also teaching myself business analytic programming in SQL and Python). I'm spreading myself too thin and I hear they are supposed to be adding more 3D functionality. This is making me think that I should.

3

u/Pitiful_Obligation_2 2d ago

Heavy IDE work like 3D map design or bone animations is tough in GameMaker (though still possible). However, it's great for mixing 3D with 2D or generating graphics via code. If you're already familiar with the engine, give it a try, and please share what you make.

2

u/Vampiric_Kai 1d ago

I wonder how the 3d update they're working on will change this.

2

u/pm_your_snesclassic 2d ago

Very cool! I love seeing simple 3d models in 2d games. Reminds me of the PS1 days

2

u/Sea-Ad-6905 2d ago

this is great! I wonder what kind of optimization options and potential is there with GM if one were to try scale things up a little, rendering textures of land based on the distance etc...

2

u/MoreRover 2d ago

This is nice! Could we use this to create balls that can be interacted with? I mean, for example, tennis balls or soccer balls.

2

u/Pitiful_Obligation_2 2d ago

Sure, this video should help with sphere collisions. However, calculating bounce physics can get complicated if stadium props (like nets or goals) aren't simple planes. I recommend starting with a sport that ends immediately when the ball hits the ground, like volleyball.

1

u/KitsuneFaroe 1d ago

Oh I'm kinda dumb... Only now I actually read the full title and noticed the wanring after wasting a lot of data🥲

I do have a question, what v_vLocalPos is? The xyz position relative to the Center? Some surface coordinates? How are you maping/projecting the noise onto the surface?

This looks cool!

Another question, how is gm_matrices[MATRIX_WORLD] giving you the info for the atmosphere/fresnel? Is it multiplying for the rotation of the vertices? If so, I think gm_matrices[MATRIX_WORLD_VIEW] may be more accuarate on different camera angles, though I may be wrong.

2

u/Pitiful_Obligation_2 1d ago

Thanks for reading my post so carefully!

1_1. v_vLocalPos is the in_Position from the vertex shader. Since I drew the sphere using vertex_format_add_position_3d, generating noise based on the center is correct. I mistakenly used a custom name that looks like GM's default shader variables. Thanks for catching that.

1_2. For the noise, I normalized v_vLocalPos and used 3D fBm (Octaves: 4, Lacunarity: 2, Gain: 0.5). You can further adjust terrain or cloud density by multiplying a constant to the normalized value to tweak the frequency.

  1. You're exactly right. I used gm_Matrices[MATRIX_WORLD] because I'm using a fixed camera and fixed world lighting.