Check out our latest project ✨ OpenChapter.io: free ebooks the way its meant to be 📖

Marching Cubes

An asset by gdarielsl
The page banner background of a mountain and forest
Marching Cubes hero image

Quick Information

0 ratings
Marching Cubes icon image
gdarielsl
Marching Cubes

# Godot marching cubesThis is a demo of multiplayer marching cubes game in godot.# Features- Procedural world generation with biomes- Blending different materials- Water- Day night cycle- Multiplayer- Voxel placing and removing# Testing- To run the project open it in godot and run it, two windows will open. - In one window you can enter singleplayer, the other is to test multiplayer. - Connect to the singleplayer world using port 5000.# Adding new voxels- Create a new class that extends Voxel under the "voxel" folder- Give it a unique ID and register it in "Main.cs"- If you're using textures add the uniforms in "terrain.gdshader" and assign the textures in node "Mesh" that is inside "chunk.tscn"- Add it into "terrain.gdshader" under `getVoxelColor` like so: ```glsl if (voxelId == {the id}) {hasNormal = true;normalTex = sampleTex({your normal texture}, {your wall normal texture}, {uv scale}, position, normal).xyz;return sampleTex({your texture}, {your wall texture}, {uv scale}, position, normal).xyz;} ```# Adding new biome- Create a new class that extends Biome under the "world_generator/biome" folder- Optional: You can call base({your base height}, {your height variation})- Implement the `GetVoxel` method- Add your biome to `GetBiome` in the "WorldGenerator" class# Adding new surface mesh- Save the geometry as a ".res" file under "voxel/surface_mesh"- Save the texture as ".png" in the same place- In "Main.cs" load your mesh and texture- Instantiate the surface mesh material (res://shaders/surface_mesh.tres) and assign your texture to the parameter "color"```cs// ExampleMesh grass = ResourceLoader.Load<ArrayMesh>("res://voxel/surface_mesh/grass.res");ShaderMaterial grassMat = ResourceLoader.Load<ShaderMaterial>("res://shaders/surface_mesh.tres");grassMat.SetShaderParameter("color", ResourceLoader.Load<Texture2D>("res://voxel/surface_mesh/grass.png"));SurfaceMesh.SurfaceMeshes.Add(GrassVoxel.ID, new SurfaceMesh(grass, grassMat));```# Optimizing performance for older hardwareYou can play with the in-game settings, lower mesh count and render distance.Or:In "world/Chunk.cs" -> `Generate(bool selfOnly)` I smooth the geometry by subdividing, this is optional. Remove these lines:```cs// OptionalGeometrySmoothing.SubdivideGeometry(positions, indices);GeometrySmoothing.SmoothGeometry(positions, indices);GeometrySmoothing.SubdivideGeometry(tranPositions, tranIndices);GeometrySmoothing.SmoothGeometry(tranPositions, tranIndices);```

Supported Engine Version
4.1
Version String
1.2
License Version
MIT
Support Level
community
Modified Date
11 months ago
Git URL
Issue URL

# Godot marching cubes

This is a demo of multiplayer marching cubes game in godot.

# Features

- Procedural world generation with biomes
- Blending different materials
- Water
- Day night cycle
- Multiplayer
- Voxel placing and removing

# Testing

- To run the project open it in godot and run it, two windows will open.
- In one window you can enter singleplayer, the other is to test multiplayer.
- Connect to the singleplayer world using port 5000.

# Adding new voxels

- Create a new class that extends Voxel under the "voxel" folder
- Give it a unique ID and register it in "Main.cs"
- If you're using textures add the uniforms in "terrain.gdshader" and assign the textures in node "Mesh" that is inside "chunk.tscn"
- Add it into "terrain.gdshader" under `getVoxelColor` like so:
```glsl
if (voxelId == {the id}) {
hasNormal = true;
normalTex = sampleTex({your normal texture}, {your wall normal texture}, {uv scale}, position, normal).xyz;
return sampleTex({your texture}, {your wall texture}, {uv scale}, position, normal).xyz;
}
```

# Adding new biome

- Create a new class that extends Biome under the "world_generator/biome" folder
- Optional: You can call base({your base height}, {your height variation})
- Implement the `GetVoxel` method
- Add your biome to `GetBiome` in the "WorldGenerator" class

# Adding new surface mesh

- Save the geometry as a ".res" file under "voxel/surface_mesh"
- Save the texture as ".png" in the same place
- In "Main.cs" load your mesh and texture
- Instantiate the surface mesh material (res://shaders/surface_mesh.tres) and assign your texture to the parameter "color"
```cs
// Example
Mesh grass = ResourceLoader.Load("res://voxel/surface_mesh/grass.res");
ShaderMaterial grassMat = ResourceLoader.Load("res://shaders/surface_mesh.tres");
grassMat.SetShaderParameter("color", ResourceLoader.Load("res://voxel/surface_mesh/grass.png"));
SurfaceMesh.SurfaceMeshes.Add(GrassVoxel.ID, new SurfaceMesh(grass, grassMat));
```

# Optimizing performance for older hardware

You can play with the in-game settings, lower mesh count and render distance.

Or:

In "world/Chunk.cs" -> `Generate(bool selfOnly)` I smooth the geometry by subdividing, this is optional. Remove these lines:
```cs
// Optional
GeometrySmoothing.SubdivideGeometry(positions, indices);
GeometrySmoothing.SmoothGeometry(positions, indices);
GeometrySmoothing.SubdivideGeometry(tranPositions, tranIndices);
GeometrySmoothing.SmoothGeometry(tranPositions, tranIndices);
```

Reviews

0 ratings

Your Rating

Headline must be at least 3 characters but not more than 50
Review must be at least 5 characters but not more than 500
Please sign in to add a review

Quick Information

0 ratings
Marching Cubes icon image
gdarielsl
Marching Cubes

# Godot marching cubesThis is a demo of multiplayer marching cubes game in godot.# Features- Procedural world generation with biomes- Blending different materials- Water- Day night cycle- Multiplayer- Voxel placing and removing# Testing- To run the project open it in godot and run it, two windows will open. - In one window you can enter singleplayer, the other is to test multiplayer. - Connect to the singleplayer world using port 5000.# Adding new voxels- Create a new class that extends Voxel under the "voxel" folder- Give it a unique ID and register it in "Main.cs"- If you're using textures add the uniforms in "terrain.gdshader" and assign the textures in node "Mesh" that is inside "chunk.tscn"- Add it into "terrain.gdshader" under `getVoxelColor` like so: ```glsl if (voxelId == {the id}) {hasNormal = true;normalTex = sampleTex({your normal texture}, {your wall normal texture}, {uv scale}, position, normal).xyz;return sampleTex({your texture}, {your wall texture}, {uv scale}, position, normal).xyz;} ```# Adding new biome- Create a new class that extends Biome under the "world_generator/biome" folder- Optional: You can call base({your base height}, {your height variation})- Implement the `GetVoxel` method- Add your biome to `GetBiome` in the "WorldGenerator" class# Adding new surface mesh- Save the geometry as a ".res" file under "voxel/surface_mesh"- Save the texture as ".png" in the same place- In "Main.cs" load your mesh and texture- Instantiate the surface mesh material (res://shaders/surface_mesh.tres) and assign your texture to the parameter "color"```cs// ExampleMesh grass = ResourceLoader.Load<ArrayMesh>("res://voxel/surface_mesh/grass.res");ShaderMaterial grassMat = ResourceLoader.Load<ShaderMaterial>("res://shaders/surface_mesh.tres");grassMat.SetShaderParameter("color", ResourceLoader.Load<Texture2D>("res://voxel/surface_mesh/grass.png"));SurfaceMesh.SurfaceMeshes.Add(GrassVoxel.ID, new SurfaceMesh(grass, grassMat));```# Optimizing performance for older hardwareYou can play with the in-game settings, lower mesh count and render distance.Or:In "world/Chunk.cs" -> `Generate(bool selfOnly)` I smooth the geometry by subdividing, this is optional. Remove these lines:```cs// OptionalGeometrySmoothing.SubdivideGeometry(positions, indices);GeometrySmoothing.SmoothGeometry(positions, indices);GeometrySmoothing.SubdivideGeometry(tranPositions, tranIndices);GeometrySmoothing.SmoothGeometry(tranPositions, tranIndices);```

Supported Engine Version
4.1
Version String
1.2
License Version
MIT
Support Level
community
Modified Date
11 months ago
Git URL
Issue URL

Open Source

Released under the AGPLv3 license

Plug and Play

Browse assets directly from Godot

Community Driven

Created by developers for developers