[gd_scene load_steps=9 format=2] [ext_resource path="res://scenes/World.gd" type="Script" id=1] [ext_resource path="res://assets/water_diffuse.png" type="Texture" id=2] [sub_resource type="CylinderMesh" id=7] top_radius = 0.5 bottom_radius = 0.5 height = 0.1 radial_segments = 6 rings = 1 [sub_resource type="SpatialMaterial" id=8] render_priority = 1 flags_transparent = true albedo_color = Color( 1, 1, 1, 0.407843 ) roughness = 0.0 [sub_resource type="PlaneMesh" id=1] subdivide_width = 24 subdivide_depth = 24 [sub_resource type="Shader" id=2] code = "shader_type spatial; uniform vec2 amplitude = vec2(0.01, 0.05); uniform vec2 frequency = vec2(3.0, 2.5); uniform vec2 time_factor = vec2(2.0, 3.0); uniform float beer_factor = 100.01; uniform float refraction = 0.05; uniform sampler2D uv_offset_texture : hint_black; uniform vec2 uv_offset_scale = vec2(0.2, 0.2); uniform float uv_offset_time_scale = 0.01; uniform float uv_offset_amplitude = 0.2; uniform sampler2D texturemap : hint_albedo; uniform vec2 texture_scale = vec2(8.0, 4.0); float height(vec2 pos, float time) { return (amplitude.x * sin(pos.x * frequency.x + time * time_factor.x)) + (amplitude.y * sin(pos.y * frequency.y + time * time_factor.y)); } void vertex() { VERTEX.y += height(VERTEX.xz, TIME); // sample the height at the location of our vertex TANGENT = normalize(vec3(0.0, height(VERTEX.xz + vec2(0.0, 0.2), TIME) - height(VERTEX.xz + vec2(0.0, -0.2), TIME), 0.4)); BINORMAL = normalize(vec3(0.4, height(VERTEX.xz + vec2(0.2, 0.0), TIME) - height(VERTEX.xz + vec2(-0.2, 0.0), TIME ), 0.0)); NORMAL = cross(TANGENT, BINORMAL); } void fragment() { vec2 base_uv_offset = UV * uv_offset_scale; // Determine the UV that we use to look up our DuDv base_uv_offset += TIME * uv_offset_time_scale; vec2 texture_based_offset = texture(uv_offset_texture, base_uv_offset).rg; // Get our offset texture_based_offset = texture_based_offset * 2.0 - 1.0; // Convert from 0.0 <=> 1.0 to -1.0 <=> 1.0 vec2 texture_uv = UV * texture_scale; texture_uv += uv_offset_amplitude * texture_based_offset; ALBEDO = texture(texturemap, texture_uv).rgb * 0.5; METALLIC = 0.0; ROUGHNESS = 0.5; //NORMALMAP = texture(normalmap, base_uv_offset).rgb; //NORMALMAP_DEPTH = 0.2; if (ALBEDO.r > 0.9 && ALBEDO.g > 0.9 && ALBEDO.b > 0.9) { ALPHA = 0.9; } else { // sample our depth buffer float depth = texture(DEPTH_TEXTURE, SCREEN_UV).r; // grab to values //depth = depth * 50.0 - 49.0; // unproject depth depth = depth * 2.0 - 1.0; float z = -PROJECTION_MATRIX[3][2] / (depth + PROJECTION_MATRIX[2][2]); // float x = (SCREEN_UV.x * 2.0 - 1.0) * z / PROJECTION_MATRIX[0][0]; // float y = (SCREEN_UV.y * 2.0 - 1.0) * z / PROJECTION_MATRIX[1][1]; float delta = -(z - VERTEX.z); // z is negative. // delta *= 0.1; // beers law float att = exp(-delta * beer_factor); ALPHA = clamp(1.0 - att, 0.0, 1.0); } vec3 ref_normal = normalize( mix(NORMAL,TANGENT * NORMALMAP.x + BINORMAL * NORMALMAP.y + NORMAL * NORMALMAP.z,NORMALMAP_DEPTH) ); vec2 ref_ofs = SCREEN_UV - ref_normal.xy * refraction; EMISSION += textureLod(SCREEN_TEXTURE,ref_ofs,ROUGHNESS * 2.0).rgb * (1.0 - ALPHA); ALBEDO *= ALPHA; ALPHA = 1.0; }" [sub_resource type="ShaderMaterial" id=3] shader = SubResource( 2 ) shader_param/amplitude = Vector2( 0.005, 0.005 ) shader_param/frequency = Vector2( 50, 48 ) shader_param/time_factor = Vector2( 7, 8 ) shader_param/beer_factor = 2.0 shader_param/refraction = 0.001 shader_param/uv_offset_scale = Vector2( 0.2, 0.2 ) shader_param/uv_offset_time_scale = 0.1 shader_param/uv_offset_amplitude = 1.2 shader_param/texture_scale = Vector2( 8, 8 ) shader_param/texturemap = ExtResource( 2 ) [sub_resource type="HeightMapShape" id=6] [node name="World" type="Spatial"] script = ExtResource( 1 ) generate_flag = true [node name="Scene" type="Spatial" parent="."] [node name="Navigation" type="Spatial" parent="."] [node name="Tiles" type="Spatial" parent="."] [node name="Highlight" type="MeshInstance" parent="."] transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0, 0.2, 0 ) cast_shadow = 0 mesh = SubResource( 7 ) material/0 = SubResource( 8 ) [node name="Water" type="MeshInstance" parent="."] transform = Transform( 10, 0, 0, 0, 10, 0, 0, 0, 10, 0, -0.1, 0 ) cast_shadow = 0 mesh = SubResource( 1 ) skeleton = NodePath("../..") material/0 = SubResource( 3 ) [node name="ClckArea" type="Area" parent="."] [node name="CollisionShape" type="CollisionShape" parent="ClckArea"] transform = Transform( 50, 0, 0, 0, 1, 0, 0, 0, 50, 0, 0, 0 ) shape = SubResource( 6 ) [connection signal="input_event" from="ClckArea" to="." method="_on_ClckArea_input_event"] [connection signal="mouse_entered" from="ClckArea" to="." method="_on_ClckArea_mouse_entered"] [connection signal="mouse_exited" from="ClckArea" to="." method="_on_ClckArea_mouse_exited"]