Discrete Ocean

Discretized color gradient built of waves flowing through the screen with a slight parallax effect. Customizable in color and wave properties

Shader code
shader_type canvas_item;

uniform vec4 bottom_color: source_color;
uniform vec4 top_color: source_color;

uniform float wave_amp: hint_range(0.0, 0.5);
uniform float wave_size: hint_range(1.0, 10.0);
uniform float wave_time_mul: hint_range(0.1, 2.0);

uniform int total_phases: hint_range(2, 600, 1);


float rand(float n){return fract(sin(n) * 43758.5453123);}


float noise(float p){
	float fl = floor(p);
  float fc = fract(p);
	return mix(rand(fl), rand(fl + 1.0), fc);
}


float fmod(float x, float y) {
	return x - floor(x / y) * y;
}


vec4 lerp(vec4 a, vec4 b, float w) {
	return a + w * (b - a);
}


void fragment() {
	float t = float(total_phases);
	float effective_wave_amp = min(wave_amp, 0.5 / t);
	float d = fmod(UV.y, 1.0 / t);
	float i = floor(UV.y * t);
	float vi = floor(UV.y * t + t * effective_wave_amp);
	float s = effective_wave_amp * sin((UV.x + TIME * max(1.0 / t, noise(vi)) * wave_time_mul * vi / t) * 2.0 * PI * wave_size);
	
	if (d < s) i--;
	if (d > s + 1.0 / t) i++;
	i = clamp(i, 0.0, t - 1.0);
	
	COLOR = lerp(top_color, bottom_color, i / (t - 1.0));
}
Tags
Abstract, background, canvas, wave
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from Moraguma

Discrete Sunset

Discrete Clouds

Related shaders

Discrete Sunset

Discrete Clouds

Gerstner Wave Ocean Shader

Subscribe
Notify of
guest

6 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
joshyboy
joshyboy
1 month ago

how do you get it to work

forgottenworkshop
forgottenworkshop
25 days ago

May want to let people know that they can mess with the layer count to get this shader to visually work in the editor. Without changing layer count, the shader does not render at first.

luke
luke
17 days ago

how do u that plz?

forgottenworkshop
forgottenworkshop
14 days ago
Reply to  luke

Hit the rocker buttons (the small up and down arrows) next to the shader parameter ‘layer count’ (or similarly named; in this case I think it’s “total phases” but all the ‘Discrete’ shaders have this issue it seems).

luke
luke
15 days ago

I really love the look of it, but i just cant get it to work. I put it on a color rect, then a canvas layer and edited it, but literaly nothing happens. Can someone plz help ?