Giter VIP home page Giter VIP logo

lelserslasers / underwaterworld Goto Github PK

View Code? Open in Web Editor NEW
11.0 1.0 0.0 170.66 MB

Infinite explorable underwater world created using Rust and WGPU using marching cubes and 3D perlin noise populated with 3D boids.

Home Page: https://lelserslasers.itch.io/underwater-world

License: MIT License

Rust 76.33% HTML 0.35% WGSL 1.62% Shell 0.02% JavaScript 21.67%
boids chunks marching-cubes perlin-noise rust shader spatial spatial-partitioning wgpu rust-lang

underwaterworld's Introduction

Underwater World

Infinite explorable underwater world created using Rust and WGPU using marching cubes and 3D perlin noise populated with 3D boids.

showcase1

Controls

  • Change pitch: WASD or arrow keys
  • Roll: Q/E or pgUp/pgDown
  • Speed up: space
  • Slow down: control
  • Reset submarine: R or enter

Features

The main build target was WASM and WebGL, meaning I did not have access to any parallelism/threading or compute shaders. This made performance a key concern, especially with the generation of the world/chunks and the fish.

  • Performance optimizations
    • Chunks/World
      • Each chunk is built one at a time and is split over multiple frames to keep the frame rate high
      • To hide the chunk generation, the chunks to build are sorted:
        1. If they are in the view frustum
        2. If they are in the direction that the sub is facing
        3. Distance to sub but with a little extra prio to chunks with a lower Z value (because they are more likely to be not blank)
      • After collecting the perlin noise values for a chunk, if the chunk will be blank, it skips trying to create the mesh and it will skipped for rendering
      • Built chunk models are stored and sent to the GPU in a more compact way using index buffers
      • Despite the fact that chunks take up 16x16x16 voxels, they are built out of 12x12x12 voxels
      • When trying to render the chunks, it will only sent chunks that in the view frustum to the GPU
      • vertex order is designed for backface culling
    • Boids
      • Index buffer + backface culling for models
      • Spatial partitioning used to find boids that are close to each other instead of iterating through all boids
      • If boids get too far from a point, they are teleported to the opposite side
        • The center point is a space in the direction the sub is facing, as there is no point in having the boids be far away from the sub or behind the sub
  • Other features
    • Marching cubes with linear interpolation based on the isosurface values
    • 3D multi-octave perlin noise to generate infinite terrain
    • Boids
      • Wall avoidance using raycasting
    • Shader effects:
      • Fog: further away objects fade into the sea
      • Darker/deeper: the deeper you go, the darker the fog/water color gets
      • The fish have a swimming animation that moves some of their vertices left and right using a sine wave
      • The sub has a light that illuminates the direction it is facing

showcase2

Assets

Resources

underwaterworld's People

Contributors

lelserslasers avatar lord-lelsers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

underwaterworld's Issues

Question about license.

That's really such an amazing project.
I was wondering about it's license, MIT, Apache 2, etc..
Or is it public domain or unlicense?
Please tell me or add LICENSE file to the repo and thanks again for this amazing project.

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.