-
Notifications
You must be signed in to change notification settings - Fork 0
/
World.tscn
296 lines (239 loc) · 11.2 KB
/
World.tscn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
[gd_scene load_steps=26 format=2]
[ext_resource path="res://terrain_textures/slot0_normal_roughness.packed_tex" type="Texture" id=1]
[ext_resource path="res://terrain_textures/slot3_albedo_bump.packed_tex" type="Texture" id=2]
[ext_resource path="res://terrain_textures/slot2_normal_roughness.packed_tex" type="Texture" id=3]
[ext_resource path="res://terrain_textures/slot3_normal_roughness.packed_tex" type="Texture" id=4]
[ext_resource path="res://terrain_textures/slot1_albedo_bump.packed_tex" type="Texture" id=5]
[ext_resource path="res://terrain_textures/slot2_albedo_bump.packed_tex" type="Texture" id=6]
[ext_resource path="res://terrain_textures/slot1_normal_roughness.packed_tex" type="Texture" id=7]
[ext_resource path="res://terrain_textures/slot0_albedo_bump.packed_tex" type="Texture" id=8]
[ext_resource path="res://addons/zylann.hterrain/hterrain.gd" type="Script" id=9]
[ext_resource path="res://addons/zylann.hterrain/hterrain_texture_set.gd" type="Script" id=10]
[ext_resource path="res://t_data/data.hterrain" type="Resource" id=11]
[ext_resource path="res://addons/zylann.hterrain/tools/icons/icon_detail_layer_node.svg" type="Texture" id=12]
[ext_resource path="res://grass.png" type="Texture" id=13]
[ext_resource path="res://addons/zylann.hterrain/hterrain_detail_layer.gd" type="Script" id=14]
[ext_resource path="res://Player/Player.tscn" type="PackedScene" id=15]
[ext_resource path="res://Coin/Coin.tscn" type="PackedScene" id=16]
[ext_resource path="res://Fonts/Godot-Fontpack-d244bf6170b399a6d4d26a0d906058ddf2dafdf1/fonts/cmu-typewriter/Typewriter/cmuntx.ttf" type="DynamicFontData" id=17]
[ext_resource path="res://Counter.gd" type="Script" id=18]
[ext_resource path="res://NPC/NPC.tscn" type="PackedScene" id=19]
[ext_resource path="res://Enemy/Enemy.tscn" type="PackedScene" id=20]
[sub_resource type="Resource" id=3]
script = ExtResource( 10 )
mode = 0
textures = [ [ ExtResource( 8 ), ExtResource( 5 ), ExtResource( 6 ), ExtResource( 2 ) ], [ ExtResource( 1 ), ExtResource( 7 ), ExtResource( 3 ), ExtResource( 4 ) ] ]
[sub_resource type="Shader" id=4]
code = "shader_type spatial;
render_mode cull_disabled;
uniform sampler2D u_terrain_heightmap;
uniform sampler2D u_terrain_detailmap;
uniform sampler2D u_terrain_normalmap;
uniform sampler2D u_terrain_globalmap : hint_albedo;
uniform mat4 u_terrain_inverse_transform;
uniform mat3 u_terrain_normal_basis;
uniform sampler2D u_albedo_alpha : hint_albedo;
uniform float u_view_distance = 100.0;
uniform float u_globalmap_tint_bottom : hint_range(0.0, 1.0);
uniform float u_globalmap_tint_top : hint_range(0.0, 1.0);
uniform float u_bottom_ao : hint_range(0.0, 1.0);
uniform vec2 u_ambient_wind; // x: amplitude, y: time
uniform vec3 u_instance_scale = vec3(1.0, 1.0, 1.0);
varying vec3 v_normal;
varying vec2 v_map_uv;
float get_hash(vec2 c) {
return fract(sin(dot(c.xy, vec2(12.9898,78.233))) * 43758.5453);
}
vec3 unpack_normal(vec4 rgba) {
vec3 n = rgba.xzy * 2.0 - vec3(1.0);
n.z *= -1.0;
return n;
}
vec3 get_ambient_wind_displacement(vec2 uv, float hash) {
// TODO This is an initial basic implementation. It may be improved in the future, especially for strong wind.
float t = u_ambient_wind.y;
float amp = u_ambient_wind.x * (1.0 - uv.y);
// Main displacement
vec3 disp = amp * vec3(cos(t), 0, sin(t * 1.2));
// Fine displacement
float fine_disp_frequency = 2.0;
disp += 0.2 * amp * vec3(cos(t * (fine_disp_frequency + hash)), 0, sin(t * (fine_disp_frequency + hash) * 1.2));
return disp;
}
void vertex() {
vec4 obj_pos = WORLD_MATRIX * vec4(0, 1, 0, 1);
vec3 cell_coords = (u_terrain_inverse_transform * obj_pos).xyz;
// Must add a half-offset so that we sample the center of pixels,
// otherwise bilinear filtering of the textures will give us mixed results (#183)
cell_coords.xz += vec2(0.5);
vec2 map_uv = cell_coords.xz / vec2(textureSize(u_terrain_heightmap, 0));
v_map_uv = map_uv;
//float density = 0.5 + 0.5 * sin(4.0*TIME); // test
float density = texture(u_terrain_detailmap, map_uv).r;
float hash = get_hash(obj_pos.xz);
float hash2 = get_hash(obj_pos.zx);
if (density > hash) {
// Snap model to the terrain
float height = texture(u_terrain_heightmap, map_uv).r / cell_coords.y;
VERTEX *= u_instance_scale + u_instance_scale * hash2;
VERTEX.y += height;
VERTEX += get_ambient_wind_displacement(UV, hash);
// Fade alpha with distance
vec3 wpos = (WORLD_MATRIX * vec4(VERTEX, 1)).xyz;
float dr = distance(wpos, CAMERA_MATRIX[3].xyz) / u_view_distance;
COLOR.a = clamp(1.0 - dr * dr * dr, 0.0, 1.0);
// When using billboards, the normal is the same as the terrain regardless of face orientation
v_normal = normalize(u_terrain_normal_basis * unpack_normal(texture(u_terrain_normalmap, map_uv)));
} else {
// Discard, output degenerate triangles
VERTEX = vec3(0, 0, 0);
}
}
void fragment() {
NORMAL = (INV_CAMERA_MATRIX * (WORLD_MATRIX * vec4(v_normal, 0.0))).xyz;
ALPHA_SCISSOR = 0.5;
ROUGHNESS = 1.0;
vec4 col = texture(u_albedo_alpha, UV);
ALPHA = col.a * COLOR.a;// - clamp(1.4 - UV.y, 0.0, 1.0);//* 0.5 + 0.5*cos(2.0*TIME);
ALBEDO = COLOR.rgb * col.rgb;
// Blend with ground color
float nh = sqrt(1.0 - UV.y);
ALBEDO = mix(ALBEDO, texture(u_terrain_globalmap, v_map_uv).rgb, mix(u_globalmap_tint_bottom, u_globalmap_tint_top, nh));
// Fake bottom AO
ALBEDO = ALBEDO * mix(1.0, 1.0 - u_bottom_ao, UV.y * UV.y);
}
"
[sub_resource type="ProceduralSky" id=1]
[sub_resource type="Environment" id=2]
background_mode = 2
background_sky = SubResource( 1 )
fog_enabled = true
fog_depth_end = 648.0
fog_height_enabled = true
fog_height_min = 40.0
fog_height_max = -20.0
tonemap_mode = 3
ssao_enabled = true
[sub_resource type="DynamicFont" id=5]
size = 35
outline_color = Color( 0, 0, 0, 1 )
font_data = ExtResource( 17 )
[node name="World" type="Spatial"]
[node name="HTerrain" type="Spatial" parent="."]
script = ExtResource( 9 )
ambient_wind = 0.134
_terrain_data = ExtResource( 11 )
chunk_size = 32
collision_enabled = true
collision_layer = 1
collision_mask = 1
shader_type = "Classic4"
custom_shader = null
custom_globalmap_shader = null
texture_set = SubResource( 3 )
shader_params/u_ground_uv_scale_per_texture = Plane( 20, 20, 20, 20 )
shader_params/u_depth_blending = true
shader_params/u_triplanar = false
shader_params/u_tile_reduction = Plane( 1, 1, 1, 1 )
shader_params/u_globalmap_blend_start = null
shader_params/u_globalmap_blend_distance = null
shader_params/u_colormap_opacity_per_texture = Plane( 1, 1, 1, 1 )
[node name="HTerrainDetailLayer" type="Spatial" parent="HTerrain"]
script = ExtResource( 14 )
__meta__ = {
"_editor_icon": ExtResource( 12 )
}
layer_index = 0
texture = ExtResource( 13 )
view_distance = 500.0
custom_shader = SubResource( 4 )
density = 4.0
instance_mesh = null
shader_params/u_globalmap_tint_bottom = 0.0
shader_params/u_globalmap_tint_top = 0.0
shader_params/u_bottom_ao = 0.0
shader_params/u_instance_scale = Vector3( 2, 2, 2 )
[node name="DirectionalLight" type="DirectionalLight" parent="."]
transform = Transform( 1, 0, 0, 0, -0.759657, 0.650324, 0, -0.650324, -0.759657, 0, 0, 0 )
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource( 2 )
[node name="Player" parent="." instance=ExtResource( 15 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 72.458, 15.7011, 44.7894 )
min_pitch = -50.0
max_pitch = 50.0
[node name="Coins" type="Spatial" parent="."]
[node name="CoinHolder1" type="Spatial" parent="Coins"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 66.9191, 15.5349, 39.041 )
[node name="coin" parent="Coins/CoinHolder1" instance=ExtResource( 16 )]
collision_layer = 3
[node name="CoinHolder2" type="Spatial" parent="Coins"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 86.7158, 14.0812, 39.041 )
[node name="coin" parent="Coins/CoinHolder2" instance=ExtResource( 16 )]
collision_layer = 3
[node name="CoinHolder3" type="Spatial" parent="Coins"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 128.997, 39.1399, 125.106 )
[node name="coin" parent="Coins/CoinHolder3" instance=ExtResource( 16 )]
collision_layer = 3
[node name="CoinHolder4" type="Spatial" parent="Coins"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 139.712, 25.6083, 216.794 )
[node name="coin" parent="Coins/CoinHolder4" instance=ExtResource( 16 )]
collision_layer = 3
[node name="Control" type="Control" parent="."]
margin_right = 1280.0
margin_bottom = 720.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="Control"]
modulate = Color( 0.0470588, 0.0470588, 0.0470588, 1 )
margin_left = 20.0
margin_top = 19.0
margin_right = 167.0
margin_bottom = 71.0
rect_scale = Vector2( 1.18844, 1.1856 )
custom_fonts/font = SubResource( 5 )
text = "Coins:"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Counter" type="Label" parent="Control"]
modulate = Color( 0.0470588, 0.0470588, 0.0470588, 1 )
margin_left = 150.0
margin_top = 19.0
margin_right = 250.0
margin_bottom = 71.0
rect_scale = Vector2( 1.18844, 1.1856 )
custom_fonts/font = SubResource( 5 )
text = "Q"
script = ExtResource( 18 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="NPCs" type="Spatial" parent="."]
[node name="NPCHolder" type="Spatial" parent="NPCs"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 61.913, 16.668, 44.639 )
[node name="NPC" parent="NPCs/NPCHolder" instance=ExtResource( 19 )]
[node name="NPCHolder2" type="Spatial" parent="NPCs"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 182.095, 26.7453, 95.9305 )
[node name="NPC" parent="NPCs/NPCHolder2" instance=ExtResource( 19 )]
[node name="NPCHolder3" type="Spatial" parent="NPCs"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 180.15, 30.0251, 220.618 )
[node name="NPC" parent="NPCs/NPCHolder3" instance=ExtResource( 19 )]
[node name="Enemys" type="Spatial" parent="."]
[node name="EnemyHolder" type="Spatial" parent="Enemys"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 97.1212, 28.4405, 118.741 )
[node name="Enemy" parent="Enemys/EnemyHolder" instance=ExtResource( 20 )]
[node name="EnemyHolder2" type="Spatial" parent="Enemys"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 129.597, 36.7824, 148.384 )
[node name="Enemy" parent="Enemys/EnemyHolder2" instance=ExtResource( 20 )]
[node name="EnemyHolder3" type="Spatial" parent="Enemys"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 229.248, 30.3979, 200.386 )
[node name="Enemy" parent="Enemys/EnemyHolder3" instance=ExtResource( 20 )]
[connection signal="body_entered" from="Coins/CoinHolder1/coin" to="Coins/CoinHolder1/coin" method="_on_coin_body_entered"]
[connection signal="coinCollected" from="Coins/CoinHolder1/coin" to="Control/Counter" method="_on_coin_coinCollected"]
[connection signal="body_entered" from="Coins/CoinHolder2/coin" to="Coins/CoinHolder2/coin" method="_on_coin_body_entered"]
[connection signal="coinCollected" from="Coins/CoinHolder2/coin" to="Control/Counter" method="_on_coin_coinCollected"]
[connection signal="body_entered" from="Coins/CoinHolder3/coin" to="Coins/CoinHolder3/coin" method="_on_coin_body_entered"]
[connection signal="coinCollected" from="Coins/CoinHolder3/coin" to="Control/Counter" method="_on_coin_coinCollected"]
[connection signal="body_entered" from="Coins/CoinHolder4/coin" to="Coins/CoinHolder4/coin" method="_on_coin_body_entered"]
[connection signal="coinCollected" from="Coins/CoinHolder4/coin" to="Control/Counter" method="_on_coin_coinCollected"]