Started implementing lod for the world. The current idea is for Lod level 1 to not use uv2. For lod level 2+ the meshes will be combined and the texture mapping will be converted to only vertex colors, and these will be simplified. Also update the modules to get all the new features needed.

This commit is contained in:
Relintai 2020-03-29 21:30:40 +02:00
parent 74459bec3f
commit 066c43b48a
7 changed files with 191 additions and 68 deletions

2
HEADS
View File

@ -1 +1 @@
{"engine": {"3.2": "da4eb7101d986af0ba6a15efaaed3dee77370d80", "master": "8c73e813134001e575b6f59e3b0100471c007410"}, "world_generator": {"master": "533c25e96fe0e5c46f68e6a532da6583cf86f4e2"}, "entity_spell_system": {"master": "0bc136962658731bac3e9e1b23bd9677f4dea9de"}, "ui_extensions": {"master": "38acc650db260a831dc26ca96fe9d9a087230bdc"}, "voxelman": {"master": "ddfdb4489fdc7865df93bafa830b4e1757319b9d"}, "texture_packer": {"master": "b17c174906f84de93d84aa60d010ffe603efaa28"}, "fastnoise": {"master": "ea3b34d972fb5f76474daabd7c1e192419811348"}, "mesh_data_resource": {"master": "4bda19b12be2c2a79a6121de6d22e48f3934e726"}, "procedural_animations": {"master": "16d0ff1ed1e986202ed7f743d3c70666e0859b28"}, "ess_data": {"master": "3bd637fdd3304b64a18287a49a6b7387acf2f5de"}, "fast_quadratic_mesh_simplifier": {"master": "36ff1f4444cacd195ad1fcab860db2f3be65bc88"}}
{"engine": {"3.2": "da4eb7101d986af0ba6a15efaaed3dee77370d80", "master": "8c73e813134001e575b6f59e3b0100471c007410"}, "world_generator": {"master": "533c25e96fe0e5c46f68e6a532da6583cf86f4e2"}, "entity_spell_system": {"master": "0bc136962658731bac3e9e1b23bd9677f4dea9de"}, "ui_extensions": {"master": "38acc650db260a831dc26ca96fe9d9a087230bdc"}, "voxelman": {"master": "541abb954dd0cf93163eec014de22e8ea33659b5"}, "texture_packer": {"master": "b17c174906f84de93d84aa60d010ffe603efaa28"}, "fastnoise": {"master": "ea3b34d972fb5f76474daabd7c1e192419811348"}, "mesh_data_resource": {"master": "4bda19b12be2c2a79a6121de6d22e48f3934e726"}, "procedural_animations": {"master": "16d0ff1ed1e986202ed7f743d3c70666e0859b28"}, "ess_data": {"master": "3bd637fdd3304b64a18287a49a6b7387acf2f5de"}, "fast_quadratic_mesh_simplifier": {"master": "a412a04be13b410ffb31a09efd962ff89b315501"}}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

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

@ -1,4 +1,4 @@
[gd_resource type="VoxelmanLibraryMerger" load_steps=8 format=2]
[gd_resource type="VoxelmanLibraryMerger" load_steps=10 format=2]
[ext_resource path="res://data/materials/1_standard_material.tres" type="Material" id=1]
[ext_resource path="res://data/voxel_surfaces/4_dungeon_stone.tres" type="VoxelSurfaceMerger" id=2]
@ -7,9 +7,11 @@
[ext_resource path="res://data/voxel_surfaces/3_test2.tres" type="VoxelSurfaceMerger" id=5]
[ext_resource path="res://data/materials/4_standard_material_prop.tres" type="Material" id=6]
[ext_resource path="res://data/voxel_surfaces/0_air.tres" type="VoxelSurfaceMerger" id=7]
[ext_resource path="res://data/materials/5_standard_material_nouv2.tres" type="Material" id=8]
[ext_resource path="res://data/materials/6_standard_material_prop_nouv2.tres" type="Material" id=9]
[resource]
material = ExtResource( 1 )
prop_material = ExtResource( 6 )
materials = [ ExtResource( 1 ), ExtResource( 8 ) ]
prop_materials = [ ExtResource( 6 ), ExtResource( 9 ) ]
texture_flags = 1
voxel_surfaces = [ ExtResource( 7 ), ExtResource( 4 ), ExtResource( 3 ), ExtResource( 5 ), ExtResource( 2 ) ]

View File

@ -500,6 +500,7 @@ actionbar_1_12={
quality/driver/driver_name="GLES2"
quality/driver/fallback_to_gles2=true
vram_compression/import_etc=true
quality/2d/use_batching=true
quality/directional_shadow/size.mobile=1024
quality/shading/force_vertex_shading=true
quality/shadows/enabled=false

View File

@ -30,6 +30,12 @@ var _textures : Array
var _prop_material : SpatialMaterial
var _entities_spawned : bool
const GENERATE_LOD = false
const LOD_NUM = 4
var current_lod_level : int = 0 setget set_current_lod_level, get_current_lod_level
var _lod_meshes : Array
var _lod_mesh_instances : Array
var lod_data : Array = [
1, #CHUNK_INDEX_UP
1, #CHUNK_INDEX_DOWN
@ -94,7 +100,7 @@ func build_phase_prop_mesh() -> void:
# _prop_material.params_specular_mode = SpatialMaterial.SPECULAR_DISABLED
# _prop_material.metallic = 0
VisualServer.instance_geometry_set_material_override(get_prop_mesh_instance_rid(), library.get_prop_material().get_rid())
VisualServer.instance_geometry_set_material_override(get_prop_mesh_instance_rid(), library.get_prop_material(0).get_rid())
for i in range(get_mesher_count()):
get_mesher(i).material = _prop_material
@ -200,82 +206,109 @@ func get_prop_mesh_transform(base_transform : Transform, snap_to_mesh: bool, sna
return base_transform
func _build_phase(phase):
# print(name + " " + str(phase))
if phase == VoxelChunkDefault.BUILD_PHASE_LIGHTS:
if phase == VoxelChunkDefault.BUILD_PHASE_SETUP:
if GENERATE_LOD and _lod_mesh_instances.size() == 0:
for i in range(LOD_NUM):
var inst : RID = VisualServer.instance_create()
if get_world() != null:
VisualServer.instance_set_scenario(inst, get_world().scenario)
var mesh : RID = VisualServer.mesh_create()
VisualServer.instance_set_base(inst, mesh)
VisualServer.instance_set_transform(inst, Transform(Basis(), Vector3(position_x * size_x * voxel_scale, position_y * size_y * voxel_scale, position_z * size_z * voxel_scale)))
VisualServer.instance_set_visible(inst, false)
_lod_mesh_instances.append(inst)
_lod_meshes.append(mesh)
._build_phase(phase)
elif phase == VoxelChunkDefault.BUILD_PHASE_LIGHTS:
clear_baked_lights()
generate_random_ao()
bake_lights()
#set_physics_process_internal(true)
active_build_phase_type = VoxelChunkDefault.BUILD_PHASE_TYPE_PHYSICS_PROCESS
return
# elif phase == VoxelChunkDefault.BUILD_PHASE_TERRARIN_MESH:
# for i in range(get_mesher_count()):
# var mesher : VoxelMesher = get_mesher(i)
# mesher.bake_colors(self)
#
# for i in range(get_mesher_count()):
# var mesher : VoxelMesher = get_mesher(i)
# mesher.set_library(library)
#
# if get_mesh_rid() == RID():
# allocate_main_mesh()
#
# var mesher : VoxelMesher = null
# for i in range(get_mesher_count()):
# var m : VoxelMesher = get_mesher(i)
#
# if mesher == null:
# mesher = m
# continue
#
# mesher.set_material(library.material)
# mesher.add_mesher(m)
#
# if (get_mesh_rid() != RID()):
# VisualServer.mesh_clear(get_mesh_rid())
#
# if mesher.get_vertex_count() == 0:
# next_phase()
# return true
#
# if (get_mesh_rid() == RID()):
# allocate_main_mesh()
#
# var arr : Array = mesher.build_mesh()
#
elif phase == VoxelChunkDefault.BUILD_PHASE_TERRARIN_MESH:
for i in range(get_mesher_count()):
var mesher : VoxelMesher = get_mesher(i)
mesher.bake_colors(self)
for i in range(get_mesher_count()):
var mesher : VoxelMesher = get_mesher(i)
mesher.set_library(library)
if get_mesh_rid() == RID():
allocate_main_mesh()
var mesher : VoxelMesher = null
for i in range(get_mesher_count()):
var m : VoxelMesher = get_mesher(i)
if mesher == null:
mesher = m
continue
mesher.set_material(library.material)
mesher.add_mesher(m)
if (get_mesh_rid() != RID()):
VisualServer.mesh_clear(get_mesh_rid())
if mesher.get_vertex_count() == 0:
next_phase()
return true
if (get_mesh_rid() == RID()):
allocate_main_mesh()
var arr : Array = mesher.build_mesh()
VisualServer.mesh_add_surface_from_arrays(get_mesh_rid(), VisualServer.PRIMITIVE_TRIANGLES, arr)
if library.get_material(0) != null:
VisualServer.mesh_surface_set_material(get_mesh_rid(), 0, library.get_material(0).get_rid())
if GENERATE_LOD and LOD_NUM > 0:
#for lod 1 just remove uv2
var arr_lod1 : Array
arr_lod1.resize(arr.size())
for i in range(arr.size()):
if i == VisualServer.ARRAY_TEX_UV2:
continue
arr_lod1[i] = arr[i]
VisualServer.mesh_add_surface_from_arrays(_lod_meshes[0], VisualServer.PRIMITIVE_TRIANGLES, arr_lod1)
if library.get_material(1) != null:
VisualServer.mesh_surface_set_material(_lod_meshes[0], 0, library.get_material(1).get_rid())
if LOD_NUM > 1:
pass
# var fqms : FastQuadraticMeshSimplifier = FastQuadraticMeshSimplifier.new()
# fqms.initialize(arr)
# fqms.simplify_mesh(0.5)
# fqms.enable_smart_link = true
# fqms.preserve_border_dges = true
# fqms.preserve_uv_seam_edges = true
# fqms.simplify_mesh(600, 7)
# var arr2 = fqms.get_arrays()
#
## print("-----")
## print(arr[VisualServer.ARRAY_VERTEX].size())
## print(arr2[VisualServer.ARRAY_VERTEX].size())
#
## var imgeom : ImmediateGeometry = get_child(0) as ImmediateGeometry
## imgeom.begin(Mesh.PRIMITIVE_POINTS)
## var vs = arr2[VisualServer.ARRAY_VERTEX]
## for v in vs:
## imgeom.add_vertex(v)
## imgeom.end()
#
#
# VisualServer.mesh_add_surface_from_arrays(get_mesh_rid(), VisualServer.PRIMITIVE_TRIANGLES, arr2)
#
# if library.material != null:
# VisualServer.mesh_surface_set_material(get_mesh_rid(), 0, library.material.get_rid())
#
# next_phase();
#
# return
next_phase();
return
elif phase == VoxelChunkDefault.BUILD_PHASE_PROP_MESH:
# set_physics_process_internal(true)
active_build_phase_type = VoxelChunkDefault.BUILD_PHASE_TYPE_PHYSICS_PROCESS
return
elif phase == BUILD_PHASE_FINALIZE:
update_lod_transforms()
._build_phase(phase)
set_current_lod_level(1)
else:
._build_phase(phase)
@ -326,3 +359,27 @@ func _build_phase_physics_process(phase):
# var pos_z = (light.get_world_position_z() - (size_z * position_z)) ;
## print(Vector3(pos_x, pos_y, pos_z))
# draw_cross_voxels_fill(Vector3(pos_x, pos_y, pos_z), 1)
func update_lod_transforms():
for m in _lod_mesh_instances:
VisualServer.instance_set_transform(m, transform);
func get_current_lod_level():
return current_lod_level
func set_current_lod_level(val):
current_lod_level = val
if not GENERATE_LOD:
return
VisualServer.instance_set_visible(get_mesh_instance_rid(), false)
for m in _lod_mesh_instances:
VisualServer.instance_set_visible(m, false)
if val == 0:
VisualServer.instance_set_visible(get_mesh_instance_rid(), true)
else:
VisualServer.instance_set_visible(_lod_mesh_instances[val - 1], true)