23 lines
775 B
Plaintext
23 lines
775 B
Plaintext
|
|
shader_type canvas_item;
|
||
|
|
|
||
|
|
// Use the captured screen texture from the BackBufferCopy
|
||
|
|
uniform sampler2D screen_texture : hint_screen_texture, filter_linear_mipmap;
|
||
|
|
|
||
|
|
uniform float threshold : hint_range(0.0, 2.0) = 0.5;
|
||
|
|
uniform float smoothness : hint_range(0.0, 1.0) = 0.02;
|
||
|
|
uniform vec4 fluid_color : source_color = vec4(0.2, 0.5, 1.0, 1.0);
|
||
|
|
|
||
|
|
void fragment() {
|
||
|
|
// 1. Grab the pixel from the 'screen' behind this ColorRect
|
||
|
|
vec4 screen_color = texture(screen_texture, SCREEN_UV);
|
||
|
|
|
||
|
|
// 2. Read the brightness (density)
|
||
|
|
float density = screen_color.r;
|
||
|
|
|
||
|
|
// 3. Apply the threshold/cutoff
|
||
|
|
float alpha = smoothstep(threshold, threshold + smoothness, density);
|
||
|
|
|
||
|
|
// 4. Output the fluid
|
||
|
|
COLOR = vec4(fluid_color.rgb, alpha * fluid_color.a);
|
||
|
|
}
|