Simple Water

Kinda has that CS:GO “this looks realistic-ish” water vibe. Takes in a 3D noise texture for waves (cellular with ~2 octaves looks best imho, remember to subdivide your water plane and make the noise seamless). Set the color to a low-saturation blue for most realistic. Transparency falls off the deeper the water is.

Shader code
shader_type spatial;

uniform sampler2D Depth : hint_depth_texture, repeat_disable, filter_nearest;
uniform sampler3D Noise : repeat_enable;
uniform vec3 Color : source_color = vec3(1.0, 0.5, 0.0);

void vertex() {

	vec3 sample_pos = TIME * 0.1 + vec3(VERTEX.x, 0, VERTEX.z) * 0.05;

	float sample = texture(Noise, sample_pos).r;

	VERTEX.y += sample;

	float sample_px = texture(Noise, sample_pos + vec3( 0.05, 0, 0)).r;
	float sample_nx = texture(Noise, sample_pos + vec3(-0.05, 0, 0)).r;
	float sample_pz = texture(Noise, sample_pos + vec3(0, 0,  0.05)).r;
	float sample_nz = texture(Noise, sample_pos + vec3(0, 0, -0.05)).r;

	NORMAL = vec3((sample_nx - sample_px) / 2.0, 1.0, (sample_nz - sample_pz) / 2.0);
}

void fragment() {

	ALBEDO = Color;

	METALLIC = 0.0;
	SPECULAR = 1.0;
	ROUGHNESS = 0.0;

	// use depth texture to make shallow areas more translucent
	float depth = texture(Depth, SCREEN_UV).x;
	//vec3 ndc = vec3(SCREEN_UV, depth) * 2.0 - 1.0;
	vec3 ndc = vec3(SCREEN_UV * 2.0 - 1.0, depth);
	vec4 view = INV_PROJECTION_MATRIX * vec4(ndc, 1.0);
	view.xyz /= view.w;
	float linear_depth = -view.z;

	float object_depth = FRAGCOORD.z;
	//vec3 object_ndc = vec3(SCREEN_UV, object_depth) * 2.0 - 1.0;
	vec3 object_ndc = vec3(SCREEN_UV * 2.0 - 1.0, object_depth);
	vec4 object_view = INV_PROJECTION_MATRIX * vec4(object_ndc, 1.0);
	object_view.xyz /= object_view.w;
	float linear_object_depth = -object_view.z;

	ALPHA = (smoothstep(0.0, 4.0, linear_depth - linear_object_depth) + 1.0) / 2.0;
}
Tags
realistic, water
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 dairycultist

Subpixelizer

Glitch

Toon Water

Related shaders

Simple animated 3d water

Simple 2d Water

Pixel Water

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments