diff --git a/project/character_controller.gd b/project/character_controller.gd index 72dc2a3..34fc5a8 100644 --- a/project/character_controller.gd +++ b/project/character_controller.gd @@ -23,6 +23,18 @@ func _ready(): #set_shape_transform(0, Transform().rotated(Vector3(1,0,0), PI/2.0)) +func _input(event): + if event is InputEventKey: + if event.pressed: + if event.scancode == KEY_1: + var light = get_node("../DirectionalLight") + light.shadow_enabled = not light.shadow_enabled + + elif event.scancode == KEY_2: + OS.set_use_vsync(not OS.is_vsync_enabled()) + print("Vsync: ", OS.is_vsync_enabled()) + + func _fixed_process(delta): var forward = _head.get_transform().basis.z.normalized() @@ -76,13 +88,13 @@ func _fixed_process(delta): # TODO There is room for optimization, but I'll leave it like this for now, it doesn't cause any lag func move_with_box_physics(motion): - var debug3d = get_node("../Debug3D") + #var debug3d = get_node("../Debug3D") var pos = get_translation() var box = BoxPhysics.box_from_center_extents(pos, Vector3(0.4, 0.9, 0.4)) var expanded_box = BoxPhysics.expand_with_vector(box, motion) - debug3d.draw_wire_box(expanded_box, Color(0,1,0,1)) + #debug3d.draw_wire_box(expanded_box, Color(0,1,0,1)) var potential_boxes = [] @@ -111,7 +123,7 @@ func move_with_box_physics(motion): if voxel_type != 0: var voxel_box = Rect3(Vector3(x,y,z), Vector3(1,1,1)) potential_boxes.append(voxel_box) - debug3d.draw_wire_box(voxel_box) + #debug3d.draw_wire_box(voxel_box) x += 1 x = min_x diff --git a/project/generator.gd b/project/generator.gd deleted file mode 100644 index 3ff64a3..0000000 --- a/project/generator.gd +++ /dev/null @@ -1,205 +0,0 @@ - -class _Base: - var _noise = OsnNoise.new() - func _init(): - _noise.set_seed(131183) - - -class Flat extends _Base: - func generate(voxels, offset): - if offset.y <= 0: - voxels.fill(1) - -class Grid extends _Base: - var step = 4 - - func generate(voxels, offset): - - for z in range(0, voxels.get_size_z()): - for x in range(0, voxels.get_size_x()): - for y in range(0, voxels.get_size_y()): - - var v = 0 - - if (y/step)%2 == 0: - if (x/step)%2 == 0: - if (z/step)%2 == 0: - v = 1 - else: - if (z/step)%2 != 0: - v = 1 - else: - if (x/step)%2 == 0: - if (z/step)%2 != 0: - v = 1 - else: - if (z/step)%2 == 0: - v = 1 - - voxels.set_voxel(v, x,y,z) - - -class Heightmap extends _Base: - var _noise2 = OsnNoise.new() - var channel = Voxel.CHANNEL_TYPE - - func _init(): - _noise2.set_seed(_noise.get_seed() + 1) - - func generate(voxels, offset): - offset *= 16 - var ox = offset.x - var oy = offset.y - var oz = offset.z - var ns1 = 0.01 - var ns2 = 0.05 - - var dirt = 1 - if oy < 0: - dirt = 2 - - var air = 0 - if oy < 0: - air = 4 - - var bs = voxels.get_size_x() - - var noise1 = OsnFractalNoise.new() - noise1.set_source_noise(_noise) - noise1.set_period(150) - noise1.set_octaves(5) - - var noise2 = OsnFractalNoise.new() - noise2.set_source_noise(_noise2) - noise2.set_period(256) - noise2.set_octaves(5) - - for z in range(0, bs): - for x in range(0, bs): - - #var n2 = noise2.get_noise_2d(ox+x, oz+z) -# n2 = (n2+0.5)*8 - 1 -# if n2 > 0.0: -# n2 = 0.0 - - var n1 = noise1.get_noise_2d(ox+x, oz+z) - - var h = floor(64.0 * n1 - oy) - - if h >= 0: - if h < bs: - voxels.fill_area(dirt, Vector3(x,0,z), Vector3(x+1,h,z+1), channel) - voxels.fill_area(air, Vector3(x,h,z), Vector3(x+1,bs,z+1), channel) - else: - voxels.fill_area(dirt, Vector3(x,0,z), Vector3(x+1,bs,z+1), channel) - else: - voxels.fill_area(air, Vector3(x,0,z), Vector3(x+1,bs,z+1), channel) - - -class Volume extends _Base: - var channel = Voxel.CHANNEL_TYPE - - func generate(voxels, offset): - offset *= 16 - var ox = offset.x - var oy = offset.y - var oz = offset.z - var empty = true - var bs = voxels.get_size_x() - - var noise1 = OsnFractalNoise.new() - noise1.set_source_noise(_noise) - noise1.set_period(100) - noise1.set_octaves(4) - - var dirt = 1 - if oy < 0: - dirt = 2 - - for z in range(0, bs): - for x in range(0, bs): - for y in range(0, bs): - var gy = y+oy - var h = noise1.get_noise_3d(x+ox+2, gy, z+oz) - if h < 1-gy*0.005 - 1: - voxels.set_voxel(dirt, x, y, z, channel) - empty = false - else: - if gy < 0: - voxels.set_voxel(4, x, y, z, channel) - else: - voxels.set_voxel(0, x, y, z, channel) - empty = false - - return empty - - -class Test extends _Base: - func generate(voxels, offset): - voxels.set_voxel(1, 1,1,1) - - voxels.set_voxel(1, 3,1,1) - voxels.set_voxel(1, 3,1,2) - - voxels.set_voxel(1, 5,1,1) - voxels.set_voxel(1, 5,1,2) - voxels.set_voxel(1, 5,2,1) - - voxels.set_voxel(1, 8,1,1) - voxels.set_voxel(1, 8,2,1) - voxels.set_voxel(1, 7,1,1) - - voxels.set_voxel(1, 11,1,1) - voxels.set_voxel(1, 11,2,1) - voxels.set_voxel(1, 10,1,1) - voxels.set_voxel(1, 10,1,2) - - for x in range(4,7): - for z in range(4,7): - voxels.set_voxel(1, x, 2, z) - voxels.set_voxel(1, x+5, 2, z) - voxels.set_voxel(1, 5,3,5) - voxels.set_voxel(1, 5,1,5) - - return false - - -class Mixed extends _Base: - var heightmap_generator = null - - func _init(): - heightmap_generator = Heightmap.new() - heightmap_generator.channel = Voxel.CHANNEL_TYPE - - func generate(voxels, offset): - heightmap_generator.generate(voxels, offset) - - var noise1 = OsnFractalNoise.new() - noise1.set_source_noise(_noise) - noise1.set_period(100) - noise1.set_octaves(4) - - offset *= 16 - var ox = offset.x - var oy = offset.y - var oz = offset.z - var empty = true - var bs = voxels.get_size_x() - var channel = Voxel.CHANNEL_ISOLEVEL - - #voxels.fill(255, Voxel.CHANNEL_ISOLEVEL) - - for z in range(0, bs): - for x in range(0, bs): - for y in range(0, bs): - var gy = y+oy - var h = noise1.get_noise_3d(x+ox+2, gy, z+oz) - if h < -0.2: - voxels.set_voxel(255, x,y,z, channel) - empty = false - - return empty - - - - diff --git a/project/main.tscn b/project/main.tscn index 57539b0..eec5eab 100644 --- a/project/main.tscn +++ b/project/main.tscn @@ -1,13 +1,14 @@ [gd_scene load_steps=18 format=2] -[ext_resource path="res://terrain_material.tres" type="Material" id=1] -[ext_resource path="res://terrain_marerial_transparent.tres" type="Material" id=2] -[ext_resource path="res://voxel_map.gd" type="Script" id=3] -[ext_resource path="res://grid.gd" type="Script" id=4] -[ext_resource path="res://character_avatar.tscn" type="PackedScene" id=5] -[ext_resource path="res://axes.tscn" type="PackedScene" id=6] -[ext_resource path="res://profiling_gui.gd" type="Script" id=7] -[ext_resource path="res://debug3d.gd" type="Script" id=8] +[ext_resource path="res://provider_heightmap.tres" type="VoxelProvider" id=1] +[ext_resource path="res://terrain_material.tres" type="Material" id=2] +[ext_resource path="res://terrain_marerial_transparent.tres" type="Material" id=3] +[ext_resource path="res://voxel_map.gd" type="Script" id=4] +[ext_resource path="res://grid.gd" type="Script" id=5] +[ext_resource path="res://character_avatar.tscn" type="PackedScene" id=6] +[ext_resource path="res://axes.tscn" type="PackedScene" id=7] +[ext_resource path="res://profiling_gui.gd" type="Script" id=8] +[ext_resource path="res://debug3d.gd" type="Script" id=9] [sub_resource type="ProceduralSky" id=1] @@ -40,7 +41,7 @@ background_energy = 1.0 background_canvas_max_layer = 0 ambient_light_color = Color( 0.0546875, 0.0546875, 0.0546875, 1 ) ambient_light_energy = 1.0 -ambient_light_sky_contribution = 1.0 +ambient_light_sky_contribution = 0.7 fog_enabled = true fog_color = Color( 0.552734, 0.818359, 0.908691, 1 ) fog_sun_color = Color( 1, 0.9, 0.7, 1 ) @@ -99,23 +100,16 @@ glow_intensity = 0.8 glow_strength = 1.0 glow_bloom = 0.0 glow_blend_mode = 2 -glow_hdr_threshold = 1.0 +glow_hdr_threshold = 0.5 glow_hdr_scale = 2.0 glow_bicubic_upscale = false adjustment_enabled = false adjustment_brightness = 1.0 adjustment_contrast = 1.0 adjustment_saturation = 1.0 -_sections_unfolded = [ "Ambient Light", "Background", "Fog" ] +_sections_unfolded = [ "Ambient Light", "Background", "Fog", "Glow" ] -[sub_resource type="VoxelProviderTest" id=3] - -mode = 1 -voxel_type = 1 -pattern_size = Vector3( 10, 10, 10 ) -pattern_offset = Vector3( 0, 0, 0 ) - -[sub_resource type="Voxel" id=4] +[sub_resource type="Voxel" id=3] voxel_name = "" color = Color( 1, 1, 1, 1 ) @@ -123,7 +117,7 @@ transparent = true material_id = 0 geometry_type = 0 -[sub_resource type="Voxel" id=5] +[sub_resource type="Voxel" id=4] voxel_name = "" color = Color( 1, 1, 1, 1 ) @@ -138,13 +132,13 @@ cube_tiles/top = null cube_tiles/back = null cube_tiles/front = null -[sub_resource type="VoxelLibrary" id=6] +[sub_resource type="VoxelLibrary" id=5] atlas_size = 4 -voxels/0 = SubResource( 4 ) -voxels/1 = SubResource( 5 ) +voxels/0 = SubResource( 3 ) +voxels/1 = SubResource( 4 ) -[sub_resource type="SpatialMaterial" id=7] +[sub_resource type="SpatialMaterial" id=6] flags_transparent = false flags_unshaded = false @@ -189,14 +183,7 @@ uv2_offset = Vector3( 0, 0, 0 ) uv2_triplanar = false uv2_triplanar_sharpness = 1.0 -[sub_resource type="CubeMesh" id=8] - -size = Vector3( 2, 2, 2 ) -subdivide_width = 0 -subdivide_height = 0 -subdivide_depth = 0 - -[sub_resource type="SpatialMaterial" id=9] +[sub_resource type="SpatialMaterial" id=7] flags_transparent = false flags_unshaded = true @@ -242,6 +229,9 @@ uv2_triplanar = false uv2_triplanar_sharpness = 1.0 _sections_unfolded = [ "Emission", "Flags", "Vertex Color" ] +[sub_resource type="QuadMesh" id=8] + + [node name="Node" type="Node"] [node name="WorldEnvironment" type="WorldEnvironment" parent="."] @@ -250,27 +240,26 @@ environment = SubResource( 2 ) [node name="VoxelTerrain" type="VoxelTerrain" parent="."] -provider = SubResource( 3 ) -voxel_library = SubResource( 6 ) -view_distance = 32 -viewer_path = NodePath("") +provider = ExtResource( 1 ) +voxel_library = SubResource( 5 ) +view_distance = 256 +viewer_path = NodePath("../CharacterAvatar") generate_collisions = true -material/0 = ExtResource( 1 ) -material/1 = ExtResource( 2 ) +material/0 = ExtResource( 2 ) +material/1 = ExtResource( 3 ) material/2 = null material/3 = null material/4 = null material/5 = null material/6 = null material/7 = null -script = ExtResource( 3 ) -_sections_unfolded = [ "material" ] +script = ExtResource( 4 ) [node name="Grid" type="MeshInstance" parent="."] visible = false layers = 1 -material_override = SubResource( 7 ) +material_override = SubResource( 6 ) cast_shadow = 1 extra_cull_margin = 0.0 use_in_baked_light = false @@ -280,13 +269,13 @@ lod_max_distance = 0.0 lod_max_hysteresis = 0.0 mesh = null skeleton = NodePath("..") -script = ExtResource( 4 ) +script = ExtResource( 5 ) size = 4 step = 16 [node name="DirectionalLight" type="DirectionalLight" parent="."] -transform = Transform( 0.875835, -0.352595, 0.329529, 0, 0.682806, 0.7306, -0.48261, -0.639885, 0.598026, 0, 0, 0 ) +transform = Transform( -0.985468, 0.124099, -0.11598, 0.0154004, 0.745271, 0.666584, 0.169159, 0.655111, -0.736353, 1.51966, 19.7004, 14.0879 ) layers = 1 light_color = Color( 1, 1, 1, 1 ) light_energy = 1.0 @@ -308,12 +297,14 @@ directional_shadow_blend_splits = false directional_shadow_normal_bias = 0.1 _sections_unfolded = [ "Directional Shadow", "Light", "Shadow" ] -[node name="CharacterAvatar" parent="." instance=ExtResource( 5 )] +[node name="CharacterAvatar" parent="." instance=ExtResource( 6 )] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 25, 17 ) terrain = NodePath("../VoxelTerrain") -[node name="axes" parent="." instance=ExtResource( 6 )] +[node name="axes" parent="." instance=ExtResource( 7 )] + +visible = false [node name="ProfilingInfo" type="Label" parent="."] @@ -332,11 +323,27 @@ size_flags_vertical = 0 percent_visible = 1.0 lines_skipped = 0 max_lines_visible = -1 -script = ExtResource( 7 ) +script = ExtResource( 8 ) -[node name="MeshInstance" type="MeshInstance" parent="."] +[node name="Debug3D" type="MeshInstance" parent="."] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -5.47068, 0, 0 ) +layers = 1 +material_override = SubResource( 7 ) +cast_shadow = 1 +extra_cull_margin = 0.0 +use_in_baked_light = false +lod_min_distance = 0.0 +lod_min_hysteresis = 0.0 +lod_max_distance = 0.0 +lod_max_hysteresis = 0.0 +mesh = null +skeleton = NodePath("..") +script = ExtResource( 9 ) +_sections_unfolded = [ "Geometry" ] + +[node name="MeshInstance2" type="MeshInstance" parent="."] + +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 3.24619, 16.9203, 17.301 ) layers = 1 material_override = null cast_shadow = 1 @@ -348,23 +355,6 @@ lod_max_distance = 0.0 lod_max_hysteresis = 0.0 mesh = SubResource( 8 ) skeleton = NodePath("..") -material/0 = ExtResource( 1 ) -_sections_unfolded = [ "material" ] - -[node name="Debug3D" type="MeshInstance" parent="."] - -layers = 1 -material_override = SubResource( 9 ) -cast_shadow = 1 -extra_cull_margin = 0.0 -use_in_baked_light = false -lod_min_distance = 0.0 -lod_min_hysteresis = 0.0 -lod_max_distance = 0.0 -lod_max_hysteresis = 0.0 -mesh = null -skeleton = NodePath("..") -script = ExtResource( 8 ) -_sections_unfolded = [ "Geometry" ] +material/0 = null diff --git a/project/noise_distorted.png b/project/noise_distorted.png new file mode 100644 index 0000000..ef7206b Binary files /dev/null and b/project/noise_distorted.png differ diff --git a/project/noise_distorted.png.import b/project/noise_distorted.png.import new file mode 100644 index 0000000..1b32d3e --- /dev/null +++ b/project/noise_distorted.png.import @@ -0,0 +1,24 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/noise_distorted.png-a3823ac1452b83d7bf69c4608544df15.stex" + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +stream=false +size_limit=0 +detect_3d=true +scale=1.0 diff --git a/project/provider.gd b/project/provider.gd deleted file mode 100644 index 577e687..0000000 --- a/project/provider.gd +++ /dev/null @@ -1,17 +0,0 @@ -extends VoxelProvider - -const Generators = preload("generator.gd") - -var _generator = null - - -func _init(): - _generator = Generators.Mixed.new() - - -func emerge_block(out_buffer, block_pos): - _generator.generate(out_buffer, block_pos) - - -#func immerge_block(buffer, bock_pos): -# pass diff --git a/project/provider_heightmap.gd b/project/provider_heightmap.gd new file mode 100644 index 0000000..af21f01 --- /dev/null +++ b/project/provider_heightmap.gd @@ -0,0 +1,108 @@ +extends VoxelProvider + + +class OsnNoise: + var iamaproxy = null +class OsnFractalNoise: + var iamaproxy = null + + +var _noise = OsnNoise.new() +var _noise2 = OsnNoise.new() +var channel = Voxel.CHANNEL_TYPE +var _image = preload("res://noise_distorted.png") + + +func _init(): +# _noise.set_seed(131183) +# _noise2.set_seed(_noise.get_seed() + 1) + _image = _image.get_data() + + +func emerge_block(out_buffer, origin_in_voxels): + emerge_block_im(out_buffer, origin_in_voxels) + + +func emerge_block_im(out_buffer, origin_in_voxels): + var ox = int(floor(origin_in_voxels.x)) + var oy = int(floor(origin_in_voxels.y)) + var oz = int(floor(origin_in_voxels.z)) + + _image.lock() + var im_w = _image.get_width() + var im_h = _image.get_height() + var im_wm = im_w - 1 + var im_hm = im_h - 1 + + var x = 0 + var z = 0 + + var bs = out_buffer.get_size_x() + + var dirt = 1 + + while z < bs: + while x < bs: + + var c = _image.get_pixel((ox+x) & im_wm, (oz+z) & im_hm) + var h = int(c.r * 200.0) - 50 + h -= oy + if h > 0: + if h > bs: + h = bs + out_buffer.fill_area(dirt, Vector3(x,0,z), Vector3(x+1,h,z+1), channel) + + x += 1 + z += 1 + x = 0 + + _image.unlock() + + +#func emerge_block_noise(out_buffer, origin_in_voxels): +# var ox = origin_in_voxels.x +# var oy = origin_in_voxels.y +# var oz = origin_in_voxels.z +# var ns1 = 0.01 +# var ns2 = 0.05 +# +# var dirt = 1 +# #if oy < 0: +# # dirt = 2 +# +# var air = 0 +# #if oy < 0: +# # air = 4 +# +# var bs = voxels.get_size_x() +# +# var noise1 = OsnFractalNoise.new() +# noise1.set_source_noise(_noise) +# noise1.set_period(150) +# noise1.set_octaves(5) +# +# var noise2 = OsnFractalNoise.new() +# noise2.set_source_noise(_noise2) +# noise2.set_period(256) +# noise2.set_octaves(5) +# +# for z in range(0, bs): +# for x in range(0, bs): +# +# #var n2 = noise2.get_noise_2d(ox+x, oz+z) +# # n2 = (n2+0.5)*8 - 1 +# # if n2 > 0.0: +# # n2 = 0.0 +# +# var n1 = noise1.get_noise_2d(ox+x, oz+z) +# +# var h = floor(64.0 * n1 - oy) +# +# if h >= 0: +# if h < bs: +# voxels.fill_area(dirt, Vector3(x,0,z), Vector3(x+1,h,z+1), channel) +# voxels.fill_area(air, Vector3(x,h,z), Vector3(x+1,bs,z+1), channel) +# else: +# voxels.fill_area(dirt, Vector3(x,0,z), Vector3(x+1,bs,z+1), channel) +# else: +# voxels.fill_area(air, Vector3(x,0,z), Vector3(x+1,bs,z+1), channel) diff --git a/project/provider_heightmap.tres b/project/provider_heightmap.tres new file mode 100644 index 0000000..32c071d --- /dev/null +++ b/project/provider_heightmap.tres @@ -0,0 +1,8 @@ +[gd_resource type="VoxelProvider" load_steps=2 format=2] + +[ext_resource path="res://provider_heightmap.gd" type="Script" id=1] + +[resource] + +script = ExtResource( 1 ) +