GodotComponentTest/scenes/HexGrid3DTest.tscn

200 lines
6.2 KiB
Plaintext

[gd_scene load_steps=11 format=2]
[ext_resource path="res://scenes/HexTile3D.tscn" type="PackedScene" id=1]
[ext_resource path="res://scenes/HexGrid3DTest.gd" type="Script" id=2]
[ext_resource path="res://scenes/DebugCamera.gd" type="Script" id=3]
[ext_resource path="res://scenes/Island.tscn" type="PackedScene" id=4]
[ext_resource path="res://assets/water_diffuse.png" type="Texture" id=5]
[sub_resource type="CapsuleMesh" id=4]
radius = 0.2
mid_height = 0.5
radial_segments = 16
[sub_resource type="NoiseTexture" id=5]
[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.01, 0.011 )
shader_param/frequency = Vector2( 50, 48 )
shader_param/time_factor = Vector2( 7, 8 )
shader_param/beer_factor = 0.5
shader_param/refraction = 0.01
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( 5 )
[node name="HexGrid3DTest" type="Spatial"]
script = ExtResource( 2 )
[node name="HexTile3D" parent="." instance=ExtResource( 1 )]
visible = false
[node name="DirectionalLight" type="DirectionalLight" parent="."]
transform = Transform( 0.83729, 0.174005, 0.518332, -0.54676, 0.266466, 0.793757, 0, -0.948008, 0.318248, 0, 8.03448, 0 )
shadow_enabled = true
shadow_contact = 1.565
directional_shadow_mode = 0
directional_shadow_depth_range = 1
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="HBoxContainer" type="HBoxContainer" parent="CanvasLayer"]
margin_right = 40.0
margin_bottom = 40.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="FPSLabel" type="Label" parent="CanvasLayer/HBoxContainer"]
margin_top = 13.0
margin_right = 22.0
margin_bottom = 27.0
text = "FPS"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="PlayerPos" type="Label" parent="CanvasLayer/HBoxContainer"]
margin_left = 26.0
margin_top = 13.0
margin_right = 88.0
margin_bottom = 27.0
text = "PlayerPos"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="TilePos" type="Label" parent="CanvasLayer/HBoxContainer"]
margin_left = 92.0
margin_top = 13.0
margin_right = 138.0
margin_bottom = 27.0
text = "TilePos"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Player" type="Spatial" parent="."]
[node name="Camera" type="Camera" parent="Player"]
transform = Transform( 1, 0, 0, 0, 0.511698, 0.859165, 0, -0.859165, 0.511698, -4.76837e-07, 6.70866, 3.34822 )
current = true
fov = 60.0
script = ExtResource( 3 )
[node name="MeshInstance" type="MeshInstance" parent="Player"]
transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0.5, 0 )
mesh = SubResource( 4 )
material/0 = null
[node name="TextureRect" type="TextureRect" parent="."]
margin_right = 40.0
margin_bottom = 40.0
texture = SubResource( 5 )
expand = true
__meta__ = {
"_edit_use_anchors_": false
}
[node name="World" type="Spatial" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )
[node name="Island" parent="World" instance=ExtResource( 4 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )
[node name="Water" type="Spatial" parent="."]
[node name="Water" type="MeshInstance" parent="Water"]
transform = Transform( 10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0 )
mesh = SubResource( 1 )
skeleton = NodePath("../..")
material/0 = SubResource( 3 )
[node name="Water2" type="MeshInstance" parent="Water"]
transform = Transform( -10, 0, 0, 0, 10, 0, 0, 0, 10, -20, 0, -0.01 )
mesh = SubResource( 1 )
skeleton = NodePath("../..")
material/0 = SubResource( 3 )