/FastNoiseLiteRuntimeShaderPlugin

Plugin with GLSL version of FastNoiseLite library for Godot game engine.

Primary LanguageCOtherNOASSERTION

FastNoiseLite-RuntimeShader-Godot-Plugin

Adds new type of material to Godot game engine: FastNoiseLiteShaderMaterial
(Use the power of GPU)

Plugin is based on FastNoiseLiteLibruary, so please,
pay a visit to official FastNoiseLite repository.

Material allows user to generate any kind of noise provided by FNL library at runtime on GPU.

Godot has built-in FastNoiseLite object that can be used by NoiseTexture2D and NoiseTexture3D. Unfortunately thouse Texture classes have a pack of issues:

  • All Textures are limited by their resolution property, so you will never see all details of generated noise.
  • FastNoiseLite class uses CPU to calculate data, and it's might take time to create big noise texture, especially 3d noise.
  • Textures generated by NoiseTexture3D and NoiseTexture2D need to be stored somewhere to work and usually they are keept in RAM, so: the bigger texture your have - the bigger amount of memory will be used.

There are two main benefits of FastNoiseLiteShaderMaterial against NoiseTexture3D and NoiseTexture2D classes:

  • Bigger resolutions: You can easily create 3D Texture with 4098x4098x4098 resolution at runtime.
  • Extra details: FastNoiseLiteShaderMaterial are not limited by pixels, so noise will have better quality.

Material provides direct access to FastNoiseLite object, skipping intermediate texture classes.

NOTE: It might take a few seconds to compile the Shader because of library size, but after that you will be able
to obtain noise data at runtime with no freezes and delays!

Custom FNL Shaders

This plugin provides custom version of FastNoiseLite.glsl designed for usage in Godot engine. That version can be used to create custom shader that can use two or more noise types, provided by library.

MultyNoiseShader example:

shader_type spatial;

#define FNL_COMPILLER_OPTIMISATIONS_REQUIRED_MULTYNOISE
//Before ussing any of noise/fractal/domain_warp types in MULTYNOISE mode
//Enable them with #define ENABLE_<type_you_want_to_enable>

#define ENABLE_FNL_NOISE_OPENSIMPLEX2S
#define ENABLE_FNL_FRACTAL_FBM
#include "res://addons/FastNoiseLiteRuntimeShader/FastNoiseLiteLib.gdshaderinc"

void fragment() {
	fnl_state noise = fnlCreateState(1337);//seed ID
	noise.noise_type = FNL_NOISE_OPENSIMPLEX2S;
	noise.fractal_type = FNL_FRACTAL_FBM;
	// <put_your_code_here>
}

SingleNoiseShader example:

shader_type spatial;

#define FNL_COMPILLER_OPTIMISATIONS_REQUIRED
#define SELECTED_NOISE_TYPE FNL_NOISE_OPENSIMPLEX2S
#define SELECTED_FRACTAL_TYPE FNL_FRACTAL_FBM
#define SELECTED_DOMAIN_WARP_TYPE FNL_DOMAIN_WARP_BASICGRID
#define SELECTED_DOMAIN_WARP_FRACTAL_TYPE FNL_FRACTAL_DOMAIN_WARP_INDEPENDENT
#include "res://addons/FastNoiseLiteRuntimeShader/FastNoiseLiteLib.gdshaderinc"

void fragment() {
	fnl_state noise = fnlCreateState(1337);//seed ID
	noise.noise_type = FNL_NOISE_OPENSIMPLEX2S;
	noise.fractal_type = FNL_FRACTAL_FBM;
	// <put_your_code_here>
}

WARNING: The more features of FastNoiseLite.glsl library you use, the more time engine will need to compile your shader! During development I bumped into situation when Godot engine took MORE THAN TEN MINUTES to compile custom shader. So be careful and do not overload your code!

NOTE: This problem can be fixed by splitting the one shader into two. Second can be placed into next_pass variable of ShaderMaterial.

Material Features

Copies of functions from NoiseTexture3D and NoiseTexture2D made in GLSL language:

  • Seamless: Property that makes noise texture seamless.
  • As Normal Map: Noise texture to normal map converter.
  • In 3D Space: Access to 3D noise from 2D textures.
  • Color Ramp: Setting custom Gradient to change color of noise texture.

Shader Controls:

  • Shader Type: Full support of two shader modes: Canvas Item and Spatial.
  • Texture Type: Fast swap between 2D and 3D noise textures, without material changing.
  • Texture UVW: Shader uses custom UVW system used to scale texture.
  • Output: Allows to write noise data to selected color chanel (Red,Green,Blue,Alpha).

Unfortunately there is no way to port normalized and generate_mipmaps. At least for now.

Demonstration

Demo scene can be found here.

  • 3D Scene: 3D Scene
  • 2D Scene: 2D Scene