GodotComponentTest/scenes/HexGrid3DTest.tscn

156 lines
4.5 KiB
Plaintext

[gd_scene load_steps=9 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]
[sub_resource type="PlaneMesh" id=1]
size = Vector2( 50, 50 )
[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;
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() {
// 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 = vec3(0.0, 0.0, 0.05);
ALBEDO *= ALPHA;
//ALPHA = 1.0;
}"
[sub_resource type="ShaderMaterial" id=3]
shader = SubResource( 2 )
shader_param/amplitude = Vector2( 0.01, 0.05 )
shader_param/frequency = Vector2( 3, 2.5 )
shader_param/time_factor = Vector2( 2, 3 )
shader_param/beer_factor = 5.0
shader_param/refraction = 0.05
[sub_resource type="CapsuleMesh" id=4]
radius = 0.2
mid_height = 0.5
radial_segments = 16
[sub_resource type="NoiseTexture" id=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="Water" type="MeshInstance" parent="."]
transform = Transform( 10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0.568377, 0.0356998 )
mesh = SubResource( 1 )
material/0 = SubResource( 3 )
[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="Tiles" type="Spatial" parent="."]
[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
}