Home

Awesome

Stride Generate Simple Mesh and Marching Cube From Compute Shader - intro

Introduction

This project aims to provide a practical implementation of generating simple 3D meshes and applying the Marching Cubes algorithm using a Compute Shader in Stride (formerly known as Xenko). It offers a foundation for creating complex voxel-based terrain, medical imaging, or other applications where surface reconstruction from volumetric data is required.

GeneateMesh : image

GenerateMarchingCube image image

Context of Use

The project finds relevance in various contexts, including but not limited to:

Informations - Compute shader & Mesh Generation

GenerateMesh.sdsl

Overview

The GenerateMesh compute shader is designed to create a simple triangle mesh using the Stride (formerly known as Xenko) game engine's compute shader capabilities. This document provides detailed information about the constants, structures, buffers, and methods used in this shader.

Constants

Structures

VoxelPoint

VertexOutput

Buffers

Methods

void Compute()

Usage

You can customize the mesh generation logic within the Compute() method to suit your specific needs. The provided code generates a simple triangle for each voxel point, but you can modify it to create more complex mesh structures.

This compute shader can be integrated into various applications, such as 3D visualization, game development, scientific simulations, and computer graphics, to efficiently generate 3D meshes from voxel data.

GenerateMeshFromPointsComponent.cs

Overview

The GenerateMeshFromPointsComponent is a C# script designed to work with the Stride game engine. It provides functionality for generating a 3D mesh from voxel points using a compute shader. This script includes data structures, buffers, and methods to facilitate the mesh generation process.

Structures

VoxelPoint

Fields

Buffers

Methods

public override void Start()

public override void Update()

Private Method - UnsetUAV()

Usage

  1. Attach this script to a GameObject in your Stride project.
  2. Customize the VoxelPoints array to define the initial positions of voxel points.
  3. Use keyboard input (NumPad keys) to interactively modify voxel point positions during runtime.
  4. The mesh generation process occurs in the compute shader.
  5. The generated mesh is associated with an entity and rendered in the scene.

Informations - Marching cube

GenerateMarchingCube.sdsl

Overview

The GenerateMarchingCube compute shader is designed to create a triangle mesh using the Marching Cubes algorithm within the Stride (formerly known as Xenko) game engine. This shader converts voxel data into a detailed and visually appealing 3D surface representation. This document provides detailed information about the constants, structures, buffers, and methods used in this shader.

Constants

Structures

VoxelData

VertexOutput

Static Arrays

Buffers

Methods

void Compute()

bool Same(float3 a, float3 b)

float3 interpolateVerts(float4 v1, float4 v2)

uint indexFromCoord(uint3 p)

Usage

GenerateMeshMarchingCubeComponent.cs

Overview

The GenerateMeshMarchingCubeComponent class is designed to facilitate the generation of a triangle mesh using the Marching Cubes algorithm within the Stride game engine. This component provides functionality for converting voxel data into a detailed 3D surface representation. This document provides a comprehensive overview of the class and its usage.

Fields

public Vector3 ChunkSize

public float IsoLevel

public int MaxVectrices

Structs

public struct VoxelData

Fields and Buffers

Methods

private void SetUpRender()

private void SetUpVoxelPoints()

private void SetUpBuffers()

private void SetUpParameters()

private void DefineStaticsValues()

private void DefineDynamicsValues()

private void SetUpMeshAndEntity()

public override void Start()

public override void Update()

Private Helper Methods

Usage

TriangleTable.cs

Overview

The TriangleTable class is a utility class that provides static tables used in the Marching Cubes algorithm for generating triangle meshes from voxel data. These tables are essential for determining the configuration of vertices and triangles during the mesh generation process. This document provides an overview of the class and its purpose.

Fields

public static int[] edgeTable

public static int[] triTable

Usage

The TriangleTable class provides precomputed tables that are crucial for the Marching Cubes algorithm's functionality. You can get tables by calling them as they are static.

ChunkContainer.cs

Overview

The ChunkContainer class is responsible for creating and managing a grid of chunks within a 3D world. Each chunk represents a portion of the world and can contain voxel data. This document provides an overview of the class and its purpose.

Fields

public Vector3 WorldSize

public Vector3 ChunkSize

Methods

public override void Start()

Usage

The ChunkContainer class allows you to create and manage a grid of chunks within your 3D world. Use as a component to an Entity in stride.

Credits

Special thanks to Tebjan for valuable contributions to render programming, and to Sebastian Lague for insights and resources related to the Marching Cubes algorithm. Sebastian Lague's GitHub repository here and his informative YouTube tutorial here have been instrumental in this project's development.

Notes

This README was written with the assistance of ChatGPT, a language model developed by OpenAI. ( well, i guess it's fair to let the chatbot make it's ad (: ) If you encounter any errors, have suggestions for improvements, please don't hesitate to create an issue. Your feedback and contributions are highly appreciated, and they help improve the quality of this project.