PirateTreasureHunt/scenes/Water.tscn

70 lines
1.9 KiB
Plaintext
Raw Normal View History

2021-08-09 00:27:53 +02:00
[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 float region_size = 300.0;
2021-08-09 00:27:53 +02:00
uniform float aspect_ratio = 0.5;
uniform float wave_speed = 0.4;
uniform vec4 blue_color : hint_color = vec4(0.04, 0.33, 1.0, 1.);
uniform float exponent = 4.;
uniform float blue_scale = 0.1;
uniform float wave_step = 1.0;
2021-08-09 00:27:53 +02:00
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));
2021-08-09 00:27:53 +02:00
}
void fragment() {
vec2 tiled_uvs = UV * vec2(region_size, region_size);
2021-08-09 00:27:53 +02:00
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 m_dist_color = vec4(m_dist, m_dist, m_dist, 1.);
vec4 color = blue_color + vec4(blue_scale * pow(m_dist, exponent));
2021-08-09 00:27:53 +02:00
COLOR = vec4(color);
}"
[sub_resource type="ShaderMaterial" id=2]
shader = SubResource( 1 )
shader_param/region_size = 999.0
2021-08-09 00:27:53 +02:00
shader_param/aspect_ratio = 0.647
shader_param/wave_speed = 0.4
shader_param/blue_color = Color( 0, 0.25098, 0.494118, 1 )
shader_param/exponent = 4.0
shader_param/blue_scale = 0.04
shader_param/wave_step = 3.0
2021-08-09 00:27:53 +02:00
[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"]