GithubHelp home page GithubHelp logo

artnas / unityvoxelmeshgpu Goto Github PK

View Code? Open in Web Editor NEW
32.0 2.0 3.0 101 KB

GPU voxel mesh generation and drawing in Unity HDRP

License: Apache License 2.0

C# 33.17% HLSL 66.83%
chunk compute-shader gpu gpu-computing hdrp mesh mesh-generation meshing shader shader-graph

unityvoxelmeshgpu's Introduction

GPU voxel mesh generation and drawing in Unity HDRP

This is an experiment to generate a cubic voxel chunk mesh as efficiently as possible. This is insanely fast, meshing and drawing at around 650 FPS on my RTX 4090. The mesh generation itself is much faster than that, running at more than 1000 FPS with camera disabled.

movie_015.mp4

This example uses a 3D noise library to generate voxel data. You can control frequency, amplitude, offset and speed of the noise via inspector in Unity.

What you can learn from it

  • How to create a mesh on gpu
  • How to use shader graph with a custom function to draw a mesh using Graphics.DrawProceduralIndirect. This was only recently made possible when Unity added VertexId node to shader graph.

How it works

  • generate voxels compute -> voxel data (0/1) is generated using 3d noise
  • feedback compute -> iterates all voxels and calculates the count of vertices and indices which will be required for the mesh
  • voxelizer compute -> iterates all voxels and writes vertex and index data into the buffers
  • the mesh is drawn with Graphics.DrawProceduralIndirect using data from index and vertex buffers

The mesh is generated on the GPU and is never read back to the CPU to create a Mesh object, that would be very slow by comparison (5 FPS).

Credits

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.