114 lines
2.8 KiB
Plaintext
114 lines
2.8 KiB
Plaintext
|
[gd_scene load_steps=5 format=2]
|
||
|
|
||
|
[ext_resource path="res://assets/water.png" type="Texture" id=1]
|
||
|
[ext_resource path="res://scenes/water.gd" type="Script" id=2]
|
||
|
|
||
|
[sub_resource type="Shader" id=1]
|
||
|
code = "shader_type canvas_item;
|
||
|
|
||
|
uniform vec2 tiled_factor = vec2(5.0, 5.0);
|
||
|
uniform float aspect_ratio = 0.5;
|
||
|
uniform float wave_speed = 0.4;
|
||
|
|
||
|
vec4 fragment_tiled_voronoi(vec2 uv) {
|
||
|
vec2 tiled_uvs = uv * tiled_factor;
|
||
|
tiled_uvs.y *= aspect_ratio;
|
||
|
|
||
|
vec2 i_st = floor(tiled_uvs);
|
||
|
vec2 f_st = fract(tiled_uvs);
|
||
|
|
||
|
vec2 point = vec2 (0.2, 0.2);
|
||
|
|
||
|
|
||
|
vec2 diff = point - f_st;
|
||
|
float dist = length(diff);
|
||
|
|
||
|
return vec4(1.0, 0., 0., 1.0);
|
||
|
}
|
||
|
/*
|
||
|
void fragment_old() {
|
||
|
vec2 tiled_uvs = UV * tiled_factor;
|
||
|
tiled_uvs.y *= aspect_ratio;
|
||
|
|
||
|
vec2 uv_offset = vec2(0., 0.);
|
||
|
// uv_offset.x = sin(TIME * wave_speed);
|
||
|
// uv_offset.y = cos(TIME * wave_speed);
|
||
|
|
||
|
tiled_uvs = tiled_uvs;
|
||
|
|
||
|
vec2 uv_repeat = tiled_uvs;
|
||
|
uv_repeat.x = uv_repeat.x - round(uv_repeat.x) + 0.5;
|
||
|
uv_repeat.y = uv_repeat.y - round(uv_repeat.y) + 0.5;
|
||
|
|
||
|
vec2 points[5];
|
||
|
points[0] = vec2(0.83,0.75);
|
||
|
points[1] = vec2(0.60,0.07);
|
||
|
points[2] = vec2(0.28,0.64);
|
||
|
points[3] = vec2(0.31,0.26);
|
||
|
|
||
|
float m_dist = 1.;
|
||
|
for (int i = 0; i < 5; i++) {
|
||
|
float dist = distance (uv_repeat, points[i]);
|
||
|
m_dist = min(m_dist, dist);
|
||
|
}
|
||
|
|
||
|
COLOR = vec4(uv_repeat, 0., 1.);
|
||
|
COLOR = vec4(m_dist, m_dist, m_dist, 1.0);
|
||
|
// COLOR = texture(TEXTURE, uv_repeat);
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
vec2 rand(vec2 co){
|
||
|
return vec2(
|
||
|
fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453),
|
||
|
fract(sin(dot(co.yx ,vec2(12.9898,78.233))) * 43758.5453));
|
||
|
}
|
||
|
|
||
|
void fragment() {
|
||
|
vec2 tiled_uvs = UV * tiled_factor;
|
||
|
tiled_uvs.y *= aspect_ratio;
|
||
|
|
||
|
vec2 i_st = floor(tiled_uvs);
|
||
|
vec2 f_st = fract(tiled_uvs);
|
||
|
|
||
|
float m_dist = 1.;
|
||
|
for (int y = -1; y <= 1; y++) {
|
||
|
for (int x = -1; x <= 1; x++) {
|
||
|
vec2 neighbour = vec2(float(x), float(y));
|
||
|
|
||
|
vec2 point = rand (i_st + neighbour);
|
||
|
point = 0.5 + 0.5 * sin(TIME * 1. + 6.2831 * point);
|
||
|
|
||
|
vec2 diff = neighbour + point - f_st;
|
||
|
float dist = length(diff);
|
||
|
m_dist = min(m_dist, dist);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
vec4 blue_color = vec4(0.04, 0.33, 1.0, 1.);
|
||
|
vec4 m_dist_color = vec4(m_dist, m_dist, m_dist, 1.);
|
||
|
float exponent = 4.;
|
||
|
vec4 color = blue_color + 0.5 * pow(m_dist_color, vec4(exponent, exponent, exponent, 1.));
|
||
|
// vec4 color =
|
||
|
// color += 1.0 - m_dist;
|
||
|
|
||
|
COLOR = vec4(color);
|
||
|
}"
|
||
|
|
||
|
[sub_resource type="ShaderMaterial" id=2]
|
||
|
shader = SubResource( 1 )
|
||
|
shader_param/tiled_factor = Vector2( 300, 300 )
|
||
|
shader_param/aspect_ratio = 0.647
|
||
|
shader_param/wave_speed = 0.4
|
||
|
|
||
|
[node name="Water" type="Node2D"]
|
||
|
|
||
|
[node name="water" type="Sprite" parent="."]
|
||
|
material = SubResource( 2 )
|
||
|
position = Vector2( -0.00827694, 0 )
|
||
|
scale = Vector2( 0.444957, 0.287887 )
|
||
|
texture = ExtResource( 1 )
|
||
|
script = ExtResource( 2 )
|
||
|
|
||
|
[connection signal="item_rect_changed" from="water" to="water" method="calculate_aspect_ratio"]
|