Now the transvoxel mesher bakes alternative uv coordinates into uv2 so it can inetrpolate between different voxel surfaces near seams (based on COLOR.a).

This commit is contained in:
Relintai 2020-02-13 03:31:42 +01:00
parent c34569a658
commit d30e33a122
10 changed files with 180 additions and 84 deletions

2
HEADS
View File

@ -1 +1 @@
{"engine": {"3.2": "8a0f94a688f18a9565a21657bf44791550aec96a", "master": "8c73e813134001e575b6f59e3b0100471c007410"}, "world_generator": {"master": "09372b146936fda509f5c23a522e998d12f38e13"}, "entity_spell_system": {"master": "0bdf71c431b62b24d56c1fc178dbcb792e5dca3d"}, "ui_extensions": {"master": "38acc650db260a831dc26ca96fe9d9a087230bdc"}, "voxelman": {"master": "3a8310c51fe87c4ab046c1f86a92ddb80fb2768a"}, "texture_packer": {"master": "b17c174906f84de93d84aa60d010ffe603efaa28"}, "fastnoise": {"master": "41b7ea05a1f7aa2b8ecddaa1fd739e64d6970f7e"}, "mesh_data_resource": {"master": "4bda19b12be2c2a79a6121de6d22e48f3934e726"}, "procedural_animations": {"master": "00f6c128bd0e9799b7f7f86e118ed68277fbe27d"}, "fast_quadratic_mesh_simplifier": {"master": "d3f3a829eff40a93464f6b321c13ce26d44e11e3"}, "ess_data": {"master": "3bd637fdd3304b64a18287a49a6b7387acf2f5de"}, "prop_tool": {"master": "df438053ebc900966f8f842fc65f0264f1271d49"}}
{"engine": {"3.2": "8a0f94a688f18a9565a21657bf44791550aec96a", "master": "8c73e813134001e575b6f59e3b0100471c007410"}, "world_generator": {"master": "09372b146936fda509f5c23a522e998d12f38e13"}, "entity_spell_system": {"master": "0bdf71c431b62b24d56c1fc178dbcb792e5dca3d"}, "ui_extensions": {"master": "38acc650db260a831dc26ca96fe9d9a087230bdc"}, "voxelman": {"master": "201ea0ce1f7e170affc911be60128ca807b246aa"}, "texture_packer": {"master": "b17c174906f84de93d84aa60d010ffe603efaa28"}, "fastnoise": {"master": "41b7ea05a1f7aa2b8ecddaa1fd739e64d6970f7e"}, "mesh_data_resource": {"master": "4bda19b12be2c2a79a6121de6d22e48f3934e726"}, "procedural_animations": {"master": "00f6c128bd0e9799b7f7f86e118ed68277fbe27d"}, "fast_quadratic_mesh_simplifier": {"master": "d3f3a829eff40a93464f6b321c13ce26d44e11e3"}, "ess_data": {"master": "3bd637fdd3304b64a18287a49a6b7387acf2f5de"}, "prop_tool": {"master": "df438053ebc900966f8f842fc65f0264f1271d49"}}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=37 format=2]
[ext_resource path="res://data/models/armature.dae" type="PackedScene" id=1]
[ext_resource path="res://data/materials/1_standard_material.tres" type="Material" id=2]
[ext_resource path="res://data/materials/3_standard_character_material.tres" type="Material" id=2]
[ext_resource path="res://player/CharacterSkeletonGD.gd" type="Script" id=3]
[ext_resource path="res://player/CharacterSkeletonAttachPoint.gd" type="Script" id=4]
[ext_resource path="res://test_weapons/sword_i.mesh" type="ArrayMesh" id=5]
@ -210,7 +210,7 @@ bones/19/bound_children = [ NodePath("RightHandAttachment") ]
skin = SubResource( 1 )
[node name="LeftHandAttachment" type="BoneAttachment" parent="armature/Armature/Skeleton" index="1"]
transform = Transform( 0.103496, -0.988074, -0.113867, 0.0567376, -0.108407, 0.992451, -0.993007, -0.109178, 0.0448429, 0.269912, 0.765141, -0.009432 )
transform = Transform( 0.103553, -0.988238, -0.11234, 0.0563584, -0.106903, 0.99262, -0.993022, -0.109123, 0.044628, 0.270796, 0.763348, -0.00915292 )
bone_name = "left_hand"
[node name="LeftHandAP" type="Spatial" parent="armature/Armature/Skeleton/LeftHandAttachment"]
@ -218,7 +218,7 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.04, -0.09 )
script = ExtResource( 4 )
[node name="RightHandAttachment" type="BoneAttachment" parent="armature/Armature/Skeleton" index="2"]
transform = Transform( -0.0414053, -0.998491, 0.0355513, -0.126356, 0.0405158, 0.991109, -0.991131, 0.0365534, -0.127846, -0.27264, 0.76424, -0.00749165 )
transform = Transform( -0.0415039, -0.998438, 0.0367427, -0.126411, 0.0417122, 0.991033, -0.991123, 0.0364982, -0.127949, -0.273113, 0.764931, -0.00762625 )
bone_name = "right_hand"
[node name="RightHandAP" type="Spatial" parent="armature/Armature/Skeleton/RightHandAttachment"]
@ -234,7 +234,7 @@ transform = Transform( 1, 0, 0, 0, -1.62921e-07, 1, 0, -1, -1.62921e-07, 0, 0, 0
script = ExtResource( 4 )
[node name="NeckAttachment" type="BoneAttachment" parent="armature/Armature/Skeleton" index="4"]
transform = Transform( 0.999969, -0.000741187, 0.00780003, 0.0078302, 0.0731273, -0.997236, 0.000168743, 0.997322, 0.0731345, 0.00109308, 1.31594, 7.40913e-05 )
transform = Transform( 0.999966, -0.00104017, 0.00817554, 0.00822331, 0.073102, -0.997213, 0.000439647, 0.997323, 0.0731128, 0.00129018, 1.31429, 9.11438e-05 )
bone_name = "neck"
[node name="TorsoAP" type="Spatial" parent="armature/Armature/Skeleton/NeckAttachment"]
@ -242,7 +242,7 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.04, -0.09 )
script = ExtResource( 4 )
[node name="RightHipAttachment" type="BoneAttachment" parent="armature/Armature/Skeleton" index="5"]
transform = Transform( 0.999694, 1.49325e-08, -0.0247482, -0.0247482, 4.7167e-07, -0.999694, -3.25495e-09, 1, 4.71895e-07, 0.0026686, 0.774437, 1.07684e-09 )
transform = Transform( 0.999802, 1.49329e-08, -0.0198917, -0.0198917, 4.71706e-07, -0.999802, -5.54689e-09, 1, 4.7191e-07, 0.00459351, 0.772787, 1.86265e-09 )
bone_name = "pelvis"
[node name="Spatial" type="Spatial" parent="armature/Armature/Skeleton/RightHipAttachment"]
@ -255,7 +255,7 @@ material/0 = null
material/1 = null
[node name="BoneAttachment" type="BoneAttachment" parent="armature/Armature/Skeleton" index="6"]
transform = Transform( 0.999967, -4.25729e-05, 0.00810519, 0.00810198, -0.00106443, -0.999911, 5.11901e-05, 1, -0.00106458, 0.00261359, 1.12836, -0.000125621 )
transform = Transform( 0.999964, -0.000312868, 0.00850185, 0.00849509, -0.00108792, -0.999886, 0.0003221, 0.999999, -0.00108623, 0.00288511, 1.12671, -0.000112632 )
bone_name = "spine_2"
[node name="Spatial" type="Spatial" parent="armature/Armature/Skeleton/BoneAttachment"]

View File

@ -8,7 +8,18 @@ uniform sampler2D texture_albedo : hint_albedo;
void fragment() {
vec2 base_uv = UV;
vec4 albedo_tex = texture(texture_albedo,base_uv);
vec2 base_uv2 = UV2;
vec4 albedo_tex = texture(texture_albedo, base_uv);
vec4 albedo_tex2 = texture(texture_albedo, base_uv2);
float ratio = COLOR.a;
albedo_tex *= ratio;
albedo_tex2 *= 1.0 - ratio;
albedo_tex += albedo_tex2;
albedo_tex *= COLOR;
ALBEDO = albedo.rgb * albedo_tex.rgb;
}

View File

@ -0,0 +1,17 @@
[gd_resource type="Shader" format=2]
[resource]
code = "shader_type spatial;
render_mode blend_mix,depth_draw_opaque,cull_back,specular_disabled,vertex_lighting;
uniform vec4 albedo : hint_color;
uniform sampler2D texture_albedo : hint_albedo;
void fragment() {
vec2 base_uv = UV;
vec4 albedo_tex = texture(texture_albedo, base_uv);
albedo_tex *= COLOR;
ALBEDO = albedo.rgb * albedo_tex.rgb;
}
"

View File

@ -56,7 +56,8 @@ adjustment_enabled = true
[node name="World" type="VoxelWorld" groups=[
"save",
]]
max_concurrent_generations = 4
use_threads = false
max_concurrent_generations = 1
library = ExtResource( 2 )
level_generator = SubResource( 1 )
chunk_spawn_range = 3

View File

@ -207,13 +207,15 @@ func _build_phase(phase):
generate_random_ao()
bake_lights()
set_physics_process_internal(true)
return false
elif phase == VoxelChunk.BUILD_PHASE_PROP_MESH:
set_physics_process_internal(true)
return false
elif phase == VoxelChunk.BUILD_PHASE_FINALIZE:
._build_phase(phase)
notification(NOTIFICATION_TRANSFORM_CHANGED)
return ._build_phase(phase)
else:
._build_phase(phase)
return ._build_phase(phase)
func _prop_added(prop):
pass

View File

@ -53,6 +53,49 @@ var lod_data : Array = [
const TEXTURE_SCALE = 4
func get_voxel_type_array(buffer : VoxelChunk, x : int, y : int, z : int, size : int = 1) -> Array:
var arr : Array = [
buffer.get_voxel(x, y, z, VoxelChunk.DEFAULT_CHANNEL_TYPE),
buffer.get_voxel(x, y + size, z, VoxelChunk.DEFAULT_CHANNEL_TYPE),
buffer.get_voxel(x, y, z + size, VoxelChunk.DEFAULT_CHANNEL_TYPE),
buffer.get_voxel(x, y + size, z + size, VoxelChunk.DEFAULT_CHANNEL_TYPE),
buffer.get_voxel(x + size, y, z, VoxelChunk.DEFAULT_CHANNEL_TYPE),
buffer.get_voxel(x + size, y + size, z, VoxelChunk.DEFAULT_CHANNEL_TYPE),
buffer.get_voxel(x + size, y, z + size, VoxelChunk.DEFAULT_CHANNEL_TYPE),
buffer.get_voxel(x + size, y + size, z + size, VoxelChunk.DEFAULT_CHANNEL_TYPE)
]
return arr
func get_case_code_from_arr(data : Array) -> int:
var case_code : int = 0
if (data[0] != 0):
case_code = case_code | VOXEL_ENTRY_MASK_000
if (data[1] != 0):
case_code = case_code | VOXEL_ENTRY_MASK_010
if (data[2] != 0):
case_code = case_code | VOXEL_ENTRY_MASK_001
if (data[3] != 0):
case_code = case_code | VOXEL_ENTRY_MASK_011
if (data[4] != 0):
case_code = case_code | VOXEL_ENTRY_MASK_100
if (data[5] != 0):
case_code = case_code | VOXEL_ENTRY_MASK_110
if (data[6] != 0):
case_code = case_code | VOXEL_ENTRY_MASK_101
if (data[7] != 0):
case_code = case_code | VOXEL_ENTRY_MASK_111
return case_code
func get_case_code(buffer : VoxelChunk, x : int, y : int, z : int, size : int = 1) -> int:
var case_code : int = 0
@ -148,7 +191,8 @@ func add_buffer_normal(buffer : VoxelChunk) -> void:
for z in range(0, z_size, lod_size):
for x in range(0, x_size, lod_size):
var case_code : int = get_case_code(buffer, x, y, z, lod_size)
var type_arr : Array = get_voxel_type_array(buffer, x, y, z, lod_size)
var case_code : int = get_case_code_from_arr(type_arr)
if case_code == 0 or case_code == 255:
continue
@ -166,9 +210,62 @@ func add_buffer_normal(buffer : VoxelChunk) -> void:
var temp_verts : Array = Array()
var type_id : int = get_voxel_type(buffer, x, y, z, lod_size)
var carr : Dictionary
var surface : VoxelSurface = library.get_voxel_surface(type_id)
for t in type_arr:
if carr.has(t):
carr[t] += 1
else:
carr[t] = 1
var type_id1 : int = -1
var type_id1c : int = -1
var type_id2 : int = -1
var type_id2c : int = -1
for k in carr.keys():
if k == 0:
continue
var c : int = carr[k]
if type_id1c == -1:
type_id1 = k
type_id1c = c
continue
if c > type_id1c:
type_id1 = k
type_id1c = c
for k in carr.keys():
if k == 0:
continue
var c : int = carr[k]
if type_id2c == -1:
type_id2 = k
type_id2c = c
continue
if c > type_id2c and k != type_id1:
type_id2 = k
type_id2c = c
var surface_ratio : float = 1
if type_id1 != type_id2:
surface_ratio = float(type_id1c) / float(type_id2c) / 8.0
var surface1 : VoxelSurface = library.get_voxel_surface(type_id1)
var surface2 : VoxelSurface = library.get_voxel_surface(type_id2)
if type_id1 == 0:
print(type_id1)
if type_id2 == 0:
print("asd" + str(type_id2))
for i in range(vertex_count):
var fv : int = get_regular_vertex_data_first_vertex(case_code, i)
@ -177,15 +274,14 @@ func add_buffer_normal(buffer : VoxelChunk) -> void:
var offs0 : Vector3 = corner_id_to_vertex(fv) * lod_size
var offs1 : Vector3 = corner_id_to_vertex(sv) * lod_size
var type0 : int = buffer.get_voxel(int(x + offs0.x), int(y + offs0.y), int(z + offs0.z), VoxelChunk.DEFAULT_CHANNEL_TYPE)
# var type1 : int = buffer.get_voxel(int(x + offs1.x), int(y + offs1.y), int(z + offs1.z), VoxelChunk.DEFAULT_CHANNEL_TYPE)
var type : int = buffer.get_voxel(int(x + offs0.x), int(y + offs0.y), int(z + offs0.z), VoxelChunk.DEFAULT_CHANNEL_TYPE)
var fill : int = 0
var vert_pos : Vector3
var vert_dir : Vector3
if type0 == 0:
if type == 0:
fill = buffer.get_voxel(int(x + offs1.x), int(y + offs1.y), int(z + offs1.z), VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
vert_pos = get_regular_vertex_second_position(case_code, i)
@ -202,11 +298,6 @@ func add_buffer_normal(buffer : VoxelChunk) -> void:
temp_verts.append(vert_pos)
# if regular_uv_entries.size() > uvs[i]:
# add_uv(Vector2(regular_uv_entries[uvs[i]][0], regular_uv_entries[uvs[i]][1]));
# add_uv(Vector2(0, 0))
var temp_normals : Array = Array()
#warning-ignore:unused_variable
@ -252,10 +343,6 @@ func add_buffer_normal(buffer : VoxelChunk) -> void:
var by : float = abs(normal.y)
var bz : float = abs(normal.z)
# if case_code == 7 and cvi == 0:
# print(str(bx) + " " + str(by) + " " + str(bz))
# add_uv(surface.transform_uv(VoxelSurface.VOXEL_SIDE_SIDE, Vector2(s.z, t.z)))
if (bx + 0.0001 > by and bx + 0.0001 > bz):
var uv : Vector2 = Vector2(s.x, t.x)
var umargin : Rect2 = uv_margin
@ -265,7 +352,8 @@ func add_buffer_normal(buffer : VoxelChunk) -> void:
uv.x += umargin.position.x
uv.y += umargin.position.y
add_uv(surface.transform_uv_scaled(VoxelSurface.VOXEL_SIDE_SIDE, uv, x % TEXTURE_SCALE, z % TEXTURE_SCALE, TEXTURE_SCALE))
add_uv(surface1.transform_uv_scaled(VoxelSurface.VOXEL_SIDE_SIDE, uv, x % TEXTURE_SCALE, z % TEXTURE_SCALE, TEXTURE_SCALE))
add_uv2(surface2.transform_uv_scaled(VoxelSurface.VOXEL_SIDE_SIDE, uv, x % TEXTURE_SCALE, z % TEXTURE_SCALE, TEXTURE_SCALE))
elif (bz + 0.0001 > bx and bz + 0.0001 > by):
var uv : Vector2 = Vector2(s.z, t.z)
var umargin : Rect2 = uv_margin
@ -275,7 +363,8 @@ func add_buffer_normal(buffer : VoxelChunk) -> void:
uv.x += umargin.position.x
uv.y += umargin.position.y
add_uv(surface.transform_uv_scaled(VoxelSurface.VOXEL_SIDE_SIDE, uv, x % TEXTURE_SCALE, z % TEXTURE_SCALE, TEXTURE_SCALE))
add_uv(surface1.transform_uv_scaled(VoxelSurface.VOXEL_SIDE_SIDE, uv, x % TEXTURE_SCALE, z % TEXTURE_SCALE, TEXTURE_SCALE))
add_uv2(surface2.transform_uv_scaled(VoxelSurface.VOXEL_SIDE_SIDE, uv, x % TEXTURE_SCALE, z % TEXTURE_SCALE, TEXTURE_SCALE))
else:
var uv : Vector2 = Vector2(s.y, t.y)
var umargin : Rect2 = uv_margin
@ -285,10 +374,10 @@ func add_buffer_normal(buffer : VoxelChunk) -> void:
uv.x += umargin.position.x
uv.y += umargin.position.y
add_uv(surface.transform_uv_scaled(VoxelSurface.VOXEL_SIDE_TOP, uv, x % TEXTURE_SCALE, z % TEXTURE_SCALE, TEXTURE_SCALE))
add_uv(surface1.transform_uv_scaled(VoxelSurface.VOXEL_SIDE_TOP, uv, x % TEXTURE_SCALE, z % TEXTURE_SCALE, TEXTURE_SCALE))
add_uv2(surface2.transform_uv_scaled(VoxelSurface.VOXEL_SIDE_TOP, uv, x % TEXTURE_SCALE, z % TEXTURE_SCALE, TEXTURE_SCALE))
for i in range(len(temp_verts)):
var vert_pos : Vector3 = temp_verts[i] as Vector3
vert_pos *= float(lod_size)
@ -300,52 +389,12 @@ func add_buffer_normal(buffer : VoxelChunk) -> void:
var vpy : int = int(vert_pos.y)
var vpz : int = int(vert_pos.z)
# var light : Color = Color(buffer.get_voxel(vpx, vpy, vpz, VoxelChunk.DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, buffer.get_voxel(vpx, vpy, vpz, VoxelChunk.DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, buffer.get_voxel(vpx, vpy, vpz, VoxelChunk.DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0)
# var ao : float = (buffer.get_voxel(vpx, vpy, vpz, VoxelChunk.DEFAULT_CHANNEL_AO) / 255.0) * ao_strength
# var rao : float = (buffer.get_voxel(vpx, vpy, vpz, VoxelChunk.DEFAULT_CHANNEL_RANDOM_AO) / 255.0)
# ao += rao
#
# light.r += base_light_value
# light.g += base_light_value
# light.b += base_light_value
#
# light.r -= ao
# light.g -= ao
# light.b -= ao
#
# light.r = clamp(light.r, 0, 1.0)
# light.g = clamp(light.g, 0, 1.0)
# light.b = clamp(light.b, 0, 1.0)
# if regular_cell_class == 11:
# print("asd")
# if case_code == 112 + 2:
## print(regular_cell_class)
## print("asd")
# light.r = 1
# light.g = 1
# light.b = 1
#add_color(light)
add_color(Color(1, 1, 1, surface_ratio))
vert_pos *= float(voxel_scale)
add_normal(normal)
add_vertex(vert_pos)
# if case_code == 7:
#
# #reset
# set_regular_vertex_data(case_code, 2, 0x3304)
#
# set_regular_vertex_data(case_code, 3, 0x2315)
# set_regular_vertex_data(case_code, 4, 0x4113)
# set_regular_vertex_data(case_code, 5, 0x1326)
#
# set_regular_vertex_data(case_code, 6, 0x3304)
# set_regular_vertex_data(case_code, 7, 0x2315)
# set_regular_vertex_data(case_code, 8, 0x2315)
func add_buffer_lod(buffer : VoxelChunk) -> void:
if lod_data[CHUNK_INDEX_UP] < lod_size:
@ -399,15 +448,14 @@ func generate_main_lod_mesh(buffer : VoxelChunk) -> void:
var offs0 : Vector3 = corner_id_to_vertex(fv) * lod_size
var offs1 : Vector3 = corner_id_to_vertex(sv) * lod_size
var type0 : int = buffer.get_voxel(int(x + offs0.x), int(y + offs0.y), int(z + offs0.z), VoxelChunk.DEFAULT_CHANNEL_TYPE)
# var type1 : int = buffer.get_voxel(int(x + offs1.x), int(y + offs1.y), int(z + offs1.z), VoxelChunk.DEFAULT_CHANNEL_TYPE)
var type : int = buffer.get_voxel(int(x + offs0.x), int(y + offs0.y), int(z + offs0.z), VoxelChunk.DEFAULT_CHANNEL_TYPE)
var fill : int = 0
var vert_pos : Vector3
var vert_dir : Vector3
if type0 == 0:
if type == 0:
fill = buffer.get_voxel(int(x + offs1.x), int(y + offs1.y), int(z + offs1.z), VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
vert_pos = get_regular_vertex_second_position(case_code, i)
@ -424,11 +472,6 @@ func generate_main_lod_mesh(buffer : VoxelChunk) -> void:
temp_verts.append(vert_pos)
# if regular_uv_entries.size() > uvs[i]:
# add_uv(Vector2(regular_uv_entries[uvs[i]][0], regular_uv_entries[uvs[i]][1]));
# add_uv(Vector2(0, 0))
var temp_normals : Array = Array()
#warning-ignore:unused_variable

View File

@ -162,7 +162,6 @@ func add_light(x : int, y : int, z : int, size : int, color : Color) -> void:
chunk.add_voxel_light(light)
func setup_client_seed(pseed : int) -> void:
# _player_file_name = ""
# _player = null