Compiler2 min read

Noise Module

Hash, value, gradient, Worley, cellular, and fractal noise helpers.

Reading Time
2 min
Word Count
227
Sections
9
Try It Live

Turn the guide into code

Take the key idea from this page into the playground and validate it in a real shader instead of leaving it as theory.

Open Playground

Hash, value, gradient, Worley, cellular, and fractal noise helpers.

Import

bwsl
import Noise

This module has no module imports.

Usage Examples

Organic Surface Variation

Use Noise when UVs or world positions need coherent variation: dirt masks, water ripples, animated dissolve edges, terrain bands, or procedural albedo.

bwsl
import Noise
float2 p = input.uv * 6.0;
float base = Noise::fbm_2d(p, 5, 2.0, 0.5);
float detail = Noise::turbulence_2d(p * 3.0 + resources.time * 0.08, 4);
float mask = saturate(base * 0.8 + detail * 0.25);
float3 clean = resources.baseColor;
float3 worn = resources.edgeWearColor;
output.color = float4(lerp(clean, worn, mask), 1.0);

Domain-Warped Effects

Use domain warp helpers when ordinary noise looks too grid-aligned or repetitive. Warped coordinates are useful for clouds, magic, fire, liquid, and force fields.

bwsl
import Noise
float2 flowUv = input.uv * resources.flowScale;
float2 warped = Noise::domain_warp_2d(flowUv + resources.time * 0.05, 0.6);
float veins = Noise::ridged_fbm_2d(warped * 3.0, 5, 2.1, 0.48);
float glow = smoothstep(0.55, 0.95, veins);
float3 color = lerp(resources.backgroundColor, resources.energyColor, glow);
output.color = float4(color * (0.6 + glow * 1.8), 1.0);

Constants

const float3 HASH_SCALE3 = float3(0.1031, 0.1030, 0.0973)const float4 HASH_SCALE4 = float4(0.1031, 0.1030, 0.0973, 0.1099)

Structs

No structs found.

Enums

No enums found.

Functions

hash11

float -> float

bwsl
hash11 :: (float p) -> float

hash21

float2 -> float

bwsl
hash21 :: (float2 p) -> float

hash31

float3 -> float

bwsl
hash31 :: (float3 p) -> float

hash22

float2 -> float2

bwsl
hash22 :: (float2 p) -> float2

hash33

float3 -> float3

bwsl
hash33 :: (float3 p) -> float3

hash23

float2 -> float3 (useful for colored noise)

bwsl
hash23 :: (float2 p) -> float3

value_noise_2d

bwsl
value_noise_2d :: (float2 p) -> float

value_noise_3d

bwsl
value_noise_3d :: (float3 p) -> float

gradient_noise_2d

bwsl
gradient_noise_2d :: (float2 p) -> float

gradient_noise_3d

bwsl
gradient_noise_3d :: (float3 p) -> float

worley_2d

Returns (F1, F2) - distance to closest and second closest points

bwsl
worley_2d :: (float2 p) -> float2

worley_2d_f1

Simple F1 only version (faster)

bwsl
worley_2d_f1 :: (float2 p) -> float

worley_3d

bwsl
worley_3d :: (float3 p) -> float2

fbm_2d

bwsl
fbm_2d :: (float2 p, int octaves, float lacunarity = 2.0, float gain = 0.5) -> float

fbm_3d

bwsl
fbm_3d :: (float3 p, int octaves, float lacunarity = 2.0, float gain = 0.5) -> float

ridged_fbm_2d

Ridged multifractal - great for mountains, lightning

bwsl
ridged_fbm_2d :: (float2 p, int octaves, float lacunarity = 2.0, float gain = 0.5) -> float

ridged_fbm_3d

bwsl
ridged_fbm_3d :: (float3 p, int octaves, float lacunarity = 2.0, float gain = 0.5) -> float

domain_warp_2d

Warp coordinates using noise (creates organic distortions)

bwsl
domain_warp_2d :: (float2 p, float strength = 1.0) -> float2

domain_warp_3d

bwsl
domain_warp_3d :: (float3 p, float strength = 1.0) -> float3

domain_warp_fbm_2d

Double domain warp for more complex patterns

bwsl
domain_warp_fbm_2d :: (float2 p, int octaves = 4, float warp_strength = 0.5) -> float

turbulence_2d

Turbulence (absolute value of FBM layers)

bwsl
turbulence_2d :: (float2 p, int octaves) -> float

billowy_2d

Billowy noise (for clouds)

bwsl
billowy_2d :: (float2 p, int octaves) -> float

voronoi_edge_2d

Swiss cheese / voronoi edge noise

bwsl
voronoi_edge_2d :: (float2 p) -> float

Source

Generated from compiler-reference/modules/noise.bwsl.