Cheap caustics

Fake unshade caustics deform giving the appearance that they follow the ground.

Shader code
shader_type spatial;
render_mode specular_schlick_ggx, cull_back, unshaded, async_visible;

uniform sampler2D ground_rgb : hint_albedo;
uniform sampler2D caustics_bw: hint_white;
uniform float slowdown : hint_range( 0.1, 10.0, 0.1 ) = 5.0;
uniform float time_caust : hint_range( 0.01, 1.0, 0.01 ) = 0.13;
uniform float tile_caust: hint_range( 0.1, 16.0, 0.1 ) = 4.0;
uniform float tile_ground: hint_range( 0.1, 16.0, 0.1 ) = 8.0;

void fragment() {

// caustics_bw
    vec2 caustics_bw_uv1 = UV * (tile_caust + sin(TIME / slowdown) * time_caust);
	vec2 caustics_bw_uv2 = UV * (tile_caust + cos(TIME / slowdown) * time_caust);
	float caustics_bw1_read = texture(caustics_bw, caustics_bw_uv1.xy).r;
	float caustics_bw2_read = texture(caustics_bw, caustics_bw_uv2.yx).r;
	// ground_rgb
	vec3 ground_rgb_read = texture(ground_rgb, UV * (tile_ground)).rgb;

	ALBEDO = ground_rgb_read.rgb * caustics_bw1_read * caustics_bw2_read;

caustics, river, sea, 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 WaltGD

Cheap terrain with fake normal map or POM

Cheap water shader

Related shaders

Cheap water shader

Cheap terrain with fake normal map or POM

Simple, cheap stylized tree shader

Notify of

1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
26 days ago

I want to use this as an overlay shader, how can I get the current underlying color instead of providing a texture?