godot-demo-projects/misc/compute_shader_heightmap
Hugo Locurcio 31d1c0c112
Remove old and unused project settings, update various demos for 4.2 (#1024)
- Move all demo projects that don't require Forward+/Mobile-only features
  to the Compatibility rendering method. This improves performance significantly
  on low-end devices and ensures visuals are identical to a web export
  of the demo.
- Set deadzone on all inputs to 0.2 for better gamepad usability.
- Remove reliance on `default_env.tres` to use built-in Environment
  resources in the main scene instead (which follows the preview environment
  workflow).
- Remove notices pointing to GDNative or VisualScript, since both were
  removed in 4.0.
- Various bug fixes and usability tweaks to 10+ demos.
2024-03-26 18:01:58 +01:00
..
screenshots
README.md Remove old and unused project settings, update various demos for 4.2 (#1024) 2024-03-26 18:01:58 +01:00
compute_shader.glsl
compute_shader.glsl.import
icon.webp
icon.webp.import
main.gd Remove old and unused project settings, update various demos for 4.2 (#1024) 2024-03-26 18:01:58 +01:00
main.tscn
project.godot Update demo files for Godot 4.2.1 (#1013) 2024-02-01 17:30:08 +01:00

README.md

Compute Shader Heightmap

This demo project gives an example of how to use compute shaders in Godot. A compute shader is a piece of code that runs on the GPU and is written in GLSL (as opposed to the Godot shader language).

A compute shader can be used to take advantage of the GPU's ability to perform massively parallel operations faster than a CPU. This demo can generate the heightmap of an island from a noise texture, both on the CPU and the GPU. You can try both options to compare the time it takes to generate the heightmap on the CPU and GPU respectively.

For smaller noise textures, the CPU will often be faster, but the larger the gains are by using the GPU. On a PC with a NVIDIA GeForce RTX 3060 and 11th-generation Intel Core i7 processor, the compute shader was tested to be faster for textures 1024×1024 and larger.

The dimensions of the image can be set on the exported Dimensions property on the main scene. By default, it's set to 2048, which creates a 2048×2048 heightmap.

Note

The shader code has been structured to be followed step-by-step by the user, and may not necessarily represent best practices. The CPU code is also less optimized than it could be. This is to reflect the GPU code as much as possible. Besides the use of the GPU, no multithreading is used.

Languages: GDScript, GLSL

Renderer: Mobile

Compute Shader Heightmap