Skip to content
Matúš Chovan edited this page Feb 7, 2019 · 6 revisions

Welcome to the godot-fftwater wiki!

Pipeline

  1. (CPU) C++ Generates displacement map
  2. (CPU) GDScript updates displacement map (every _process()) and sends it to shader
  3. (GPU) Shader displaces vertices and does shading

Download

To use water, download latest package from Releases

Files

The Release package contains:

  • bin/
    • x11/ / win64/ / osx/ (depends on platform) <- contains compiled c++ libraries
    • gdwaterfft.gdnlib <- Godot native library binding file, which tells Godot where to look for compiled libraries
    • tessendorf.gdns <- FFT Water Godot native script
  • Water.gd <- example usage
  • Water.shader <- example shader

Usage

Node setup

  1. Create MeshInstance and set PlaneMesh as mesh property
    • adjust size and subdivide as you want (default: 100x100 size, 512x512 subdivide)
  2. Create ShaderMaterial in material property and attach Water.shader to it
  3. Attach Water.gd
  4. Run

FFT Water usage (GDScript) - explained Water.gd

To create object

onready var tessendorf = load("res://bin/tessendorf.gdns").new()

To create FFT, we need to set the resolution (needs to be a power of 2)

tessendorf.create(128)

Tessendorf contains adjustable variables

# General wave height
tessendorf.amplitude = 15.0
# Controlls weather (higher number, the more stormy the water will look)
tessendorf.wind_speed = 31.0
# Size of water plane (on plane 100x100 length=500)
tessendorf.length = 500.0
# How sharp the waves should be (needs to be negative)
tessendorf.lambda = -0.9
# Ignoring waves
tessendorf.smoothing = 1.0
# Waves direction...
tessendorf.wind_direction = Vector2(1.0, 0.0)

After setting all the variables, we need to precalculate

tessendorf.calculate()

To update water to current time

In Water.gd is an example of how to calculate passed time

tessendorf.update(time_that_passed)

Sending calculated displacement map

tessendorf.send_displacement(shader_material, "name_of_shader_variable")

shader_material is obtained using mesh.surface_get_material(0)

"name_of_shader_variable" is the name of shader uniform, that is used for displacement