-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworld.tscn
More file actions
285 lines (238 loc) · 11.6 KB
/
Copy pathworld.tscn
File metadata and controls
285 lines (238 loc) · 11.6 KB
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
[gd_scene load_steps=17 format=4 uid="uid://bagibq6uter7j"]
[ext_resource type="PackedScene" uid="uid://dgpjxoygnvyy4" path="res://assets/simple_fpsplayer/Player.tscn" id="1_f3sb7"]
[ext_resource type="Script" uid="uid://cc6q1eio36k0o" path="res://voxel_lod_terrain.gd" id="1_fj7yv"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_fj7yv"]
sky_horizon_color = Color(0.66224277, 0.6717428, 0.6867428, 1)
ground_horizon_color = Color(0.66224277, 0.6717428, 0.6867428, 1)
[sub_resource type="Sky" id="Sky_tlwt5"]
sky_material = SubResource("ProceduralSkyMaterial_fj7yv")
[sub_resource type="Environment" id="Environment_aqk2v"]
background_mode = 2
sky = SubResource("Sky_tlwt5")
tonemap_mode = 2
glow_enabled = true
[sub_resource type="VoxelStreamMemory" id="VoxelStreamMemory_f3sb7"]
[sub_resource type="FastNoiseLite" id="FastNoiseLite_fj7yv"]
[sub_resource type="FastNoiseLite" id="FastNoiseLite_tlwt5"]
fractal_type = 0
[sub_resource type="VoxelGeneratorGraph" id="VoxelGeneratorGraph_tlwt5"]
graph_data = {
"connections": [[5, 0, 8, 0], [6, 0, 7, 0], [7, 0, 5, 1], [8, 0, 4, 0], [10, 0, 11, 2], [11, 0, 9, 0]],
"nodes": {
"10": {
"auto_connect": true,
"gui_position": Vector2(340, 360),
"noise": SubResource("FastNoiseLite_tlwt5"),
"type": "Noise3D",
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"11": {
"a": 0.0,
"b": 1.0,
"gui_position": Vector2(640, 380),
"threshold": 0.0,
"type": "Select"
},
"4": {
"auto_connect": true,
"gui_position": Vector2(940, 140),
"type": "OutputSDF"
},
"5": {
"auto_connect": true,
"gui_position": Vector2(520, 140),
"type": "SdfPlane",
"y": 0.0
},
"6": {
"auto_connect": true,
"gui_position": Vector2(120, 160),
"noise": SubResource("FastNoiseLite_fj7yv"),
"type": "Noise2D",
"x": 0.0,
"y": 0.0
},
"7": {
"b": 20.0,
"gui_position": Vector2(340, 160),
"type": "Multiply"
},
"8": {
"gui_position": Vector2(740, 140),
"max": 1.0,
"min": -1.0,
"type": "Clamp"
},
"9": {
"gui_position": Vector2(920, 380),
"type": "OutputSingleTexture"
}
},
"version": 2
}
[sub_resource type="VoxelMesherTransvoxel" id="VoxelMesherTransvoxel_pkg7o"]
texturing_mode = 1
[sub_resource type="Shader" id="Shader_fj7yv"]
code = "shader_type spatial;
// From Voxel Tools API
uniform int u_transition_mask;
// Textures should preferably be in a Texture2DArray, so looking them up is cheap
uniform sampler2DArray u_texture_array : source_color, filter_nearest;
// We'll need to pass data from the vertex shader to the fragment shader
varying vec4 v_indices;
varying vec4 v_weights;
varying vec3 v_normal;
varying vec3 v_pos;
// We'll use a utility function to decode components.
// It returns 4 values in the range [0..255].
vec4 decode_8bit_vec4(float v) {
uint i = floatBitsToUint(v);
return vec4(
float(i & uint(0xff)),
float((i >> uint(8)) & uint(0xff)),
float((i >> uint(16)) & uint(0xff)),
float((i >> uint(24)) & uint(0xff)));
}
// A voxel mesh can have overhangs in any direction,
// so we may have to use triplanar mapping functions.
vec3 get_triplanar_blend(vec3 world_normal) {
vec3 blending = abs(world_normal);
blending = normalize(max(blending, vec3(0.00001))); // Force weights to sum to 1.0
float b = blending.x + blending.y + blending.z;
return blending / vec3(b, b, b);
}
vec4 texture_array_triplanar(sampler2DArray tex, vec3 world_pos, vec3 blend, float i) {
vec4 xaxis = texture(tex, vec3(world_pos.yz, i));
vec4 yaxis = texture(tex, vec3(world_pos.xz, i));
vec4 zaxis = texture(tex, vec3(world_pos.xy, i));
// blend the results of the 3 planar projections.
return xaxis * blend.x + yaxis * blend.y + zaxis * blend.z;
}
float get_transvoxel_secondary_factor(int idata) {
int transition_mask = u_transition_mask & 0xff;
int cell_border_mask = idata & 63; // Which sides the cell is touching
int vertex_border_mask = (idata >> 8) & 63; // Which sides the vertex is touching
// If the vertex is near a side where there is a low-resolution neighbor,
// move it to secondary position
int m = transition_mask & cell_border_mask;
float t = float(m != 0);
// If the vertex lies on one or more sides, and at least one side has no low-resolution neighbor,
// don't move the vertex.
t *= float((vertex_border_mask & ~transition_mask) == 0);
// Debugging
//t *= 0.5 + 0.5 * sin(TIME * 4.0);
//t *= 2.0;
return t;
}
vec3 get_transvoxel_position(vec3 vertex_pos, vec4 fdata) {
int idata = floatBitsToInt(fdata.a);
// Move vertices to smooth transitions
float secondary_factor = get_transvoxel_secondary_factor(idata);
vec3 secondary_position = fdata.xyz;
vec3 pos = mix(vertex_pos, secondary_position, secondary_factor);
// If the mesh combines transitions and the vertex belongs to a transition,
// when that transition isn't active we change the position of the vertices so
// all triangles will be degenerate and won't be visible.
// This is an alternative to rendering them separately,
// which has less draw calls and less mesh resources to create in Godot.
// Ideally I would tweak the index buffer like LOD does but Godot does not
// expose anything to use it that way.
int itransition = (idata >> 16) & 0xff; // Is the vertex on a transition mesh?
float transition_cull = float(itransition == 0 || (itransition & u_transition_mask) != 0);
pos *= transition_cull;
return pos;
}
void vertex() {
VERTEX = get_transvoxel_position(VERTEX, CUSTOM0);
// Indices are integer values so we can decode them as-is
v_indices = decode_8bit_vec4(CUSTOM1.x);
// Weights must be in [0..1] so we divide them
v_weights = decode_8bit_vec4(CUSTOM1.y) / 255.0;
v_pos = VERTEX;
v_normal = NORMAL;
//...
}
void fragment() {
// Define a texture scale for convenience.
// We can use an array instead if different scales per index is needed.
float uv_scale = 0.5;
// Sample the 4 blending textures, all with triplanar mapping.
// We can re-use the same triplanar blending factors for all of them so separating that part
// of the function improves performance a little.
vec3 blending = get_triplanar_blend(v_normal);
vec3 col0 = texture_array_triplanar(u_texture_array, v_pos * uv_scale, blending, v_indices.x).rgb;
vec3 col1 = texture_array_triplanar(u_texture_array, v_pos * uv_scale, blending, v_indices.y).rgb;
vec3 col2 = texture_array_triplanar(u_texture_array, v_pos * uv_scale, blending, v_indices.z).rgb;
vec3 col3 = texture_array_triplanar(u_texture_array, v_pos * uv_scale, blending, v_indices.w).rgb;
// Get weights and make sure they are normalized.
// We may add a tiny safety margin so we can afford some degree of error.
vec4 weights = v_weights;
weights /= (weights.x + weights.y + weights.z + weights.w + 0.00001);
// Calculate albedo
vec3 col =
col0 * weights.r +
col1 * weights.g +
col2 * weights.b +
col3 * weights.a;
ALBEDO = col;
//...
}"
[sub_resource type="Image" id="Image_fj7yv"]
data = {
"data": PackedByteArray("fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8cnJycnJycnJyfHx8cnJycnJyfHx8fHx8fHx8fHx8fHx8cnJycnJycnJycnJyfHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8goKCgoKCfHx8fHx8fHx8fHx8fHx8goKCgoKCgoKCgoKCfHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8cnJycnJyfHx8fHx8cnJycnJycnJycnJycnJycnJyfHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8goKCgoKCfHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8cnJycnJycnJycnJycnJycnJycnJyfHx8fHx8fHx8cnJyfHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8goKCgoKCgoKCfHx8fHx8fHx8fHx8fHx8fHx8goKCgoKCcnJycnJyfHx8fHx8fHx8fHx8cnJycnJycnJycnJyfHx8fHx8cnJycnJycnJycnJyfHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8goKCgoKCgoKCgoKCfHx8fHx8fHx8fHx8fHx8goKCgoKCgoKCgoKCfHx8cnJycnJyfHx8cnJycnJycnJycnJycnJyfHx8fHx8cnJycnJycnJycnJycnJycnJyfHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8cnJycnJycnJycnJycnJyfHx8fHx8fHx8fHx8fHx8fHx8fHx8goKCgoKC"),
"format": "RGB8",
"height": 16,
"mipmaps": false,
"width": 16
}
[sub_resource type="Image" id="Image_tlwt5"]
data = {
"data": PackedByteArray("I4c9I4c9I4c9I4c9JpNDI4c9I4c9JpNDH3c2I4c9I4c9I4c9I4c9I4c9I4c9I4c9I4c9I4c9H3c2I4c9I4c9I4c9I4c9I4c9I4c9I4c9I4c9I4c9H3c2I4c9I4c9I4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biL5biLxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxx5biL5biL5biL5biL5biL5biL5biL5biL5biL8sOT8sOT8sOT8sOT8sOT8sOT8sOT26x95biL26x926x95biL5biL26x926x926x926x95biL5biL5biL5biL26x926x95biL5biL8sOT8sOT8sOT8sOT5biL5biL5biL5biL5biL5biL5biL5biL5biL5biLxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxx5biL5biL5biL5biL5biL5biL5biL8sOT8sOT8sOT8sOT8sOT8sOT8sOT8sOT5biL5biL26x926x95biL26x926x926x926x95biL5biL5biL26x926x926x926x95biL8sOT8sOT8sOT8sOT8sOT8sOT8sOT8sOT8sOT5biL5biL5biL5biL5biL5biL5biLxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxx5biL5biL5biL5biL5biL5biL5biL5biL5biL5biL8sOT8sOT8sOT8sOT8sOT8sOT26x926x926x926x926x926x95biL5biL5biL26x926x95biL26x926x926x95biL5biL8sOT8sOT8sOT8sOT8sOT8sOT8sOT8sOT8sOT5biL5biL5biL5biL5biL5biLxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxxxpxx8sOT8sOT8sOT8sOT8sOT8sOT5biL5biL5biL5biL5biL5biL5biL5biL5biL5biL5biL26x926x95biL5biL26x926x926x95biL5biL26x926x95biL26x926x95biL"),
"format": "RGB8",
"height": 16,
"mipmaps": false,
"width": 16
}
[sub_resource type="Texture2DArray" id="Texture2DArray_pkg7o"]
_images = Array[Image]([SubResource("Image_fj7yv"), SubResource("Image_tlwt5"), SubResource("Image_aqk2v")])
[sub_resource type="ShaderMaterial" id="ShaderMaterial_tlwt5"]
render_priority = 0
shader = SubResource("Shader_fj7yv")
shader_parameter/u_transition_mask = 0
shader_parameter/u_texture_array = SubResource("Texture2DArray_pkg7o")
[node name="World" type="Node3D"]
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_aqk2v")
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(-0.8660254, -0.43301278, 0.25, 0, 0.49999997, 0.86602545, -0.50000006, 0.75, -0.43301266, 0, 0, 0)
shadow_enabled = true
[node name="VoxelLodTerrain" type="VoxelLodTerrain" parent="."]
stream = SubResource("VoxelStreamMemory_f3sb7")
generator = SubResource("VoxelGeneratorGraph_tlwt5")
mesher = SubResource("VoxelMesherTransvoxel_pkg7o")
material = SubResource("ShaderMaterial_tlwt5")
script = ExtResource("1_fj7yv")
[node name="Player" parent="." instance=ExtResource("1_f3sb7")]
[node name="Label" type="Label" parent="."]
offset_right = 40.0
offset_bottom = 23.0
text = "Godot Voxel Tool by Zylann.
Demo by PiCode.
SimpleFirstPerson (controller) by aarroz.
Control:
Move - WASD & Space
Sprint - Shift
Place - Left mouse
Break - Right mouse
Switch material - E
"