Compare commits

...

4 Commits

Author SHA1 Message Date
Segey Lapin
8a3b4987e8 Update (nature, engine changes) 2021-11-22 01:09:02 +03:00
Segey Lapin
8bb1c26ecd Startup fixes 2021-11-13 16:54:25 +03:00
Segey Lapin
a96673ceb6 Spawn operation for buildings at block level 2021-11-13 16:53:14 +03:00
Segey Lapin
4ba2898ec2 Added water shader 2021-11-13 16:51:24 +03:00
106 changed files with 7348 additions and 132 deletions

View File

@@ -16,20 +16,22 @@ onready var male = preload("res://characters/vroid1-man.tscn")
onready var face_ctrl = preload("res://scenes/face/head_comtrol.tscn")
onready var modules = {
# "physics": load("res://scripts/modules/character_physics.gd"),
"cmdq": load("res://scripts/modules/cmdq.gd"),
"marker": load("res://scripts/modules/npc_marker.gd"),
"sacrifice": load("res://scripts/modules/npc_sacrifice.gd"),
"nun": load("res://scripts/modules/npc_nun.gd"),
"player": load("res://scripts/modules/player_controls.gd"),
"player_clothes": load("res://scripts/modules/player_clothes.gd"),
"hurtboxes": load("res://scripts/modules/character_hurtboxes.gd"),
"student": load("res://scripts/modules/npc_student.gd")
"cmdq": preload("res://scripts/modules/cmdq.gd"),
"marker": preload("res://scripts/modules/npc_marker.gd"),
"sacrifice": preload("res://scripts/modules/npc_sacrifice.gd"),
"nun": preload("res://scripts/modules/npc_nun.gd"),
"player": preload("res://scripts/modules/player_controls.gd"),
"player_clothes": preload("res://scripts/modules/player_clothes.gd"),
"hurtboxes": preload("res://scripts/modules/character_hurtboxes.gd"),
"student": preload("res://scripts/modules/npc_student.gd")
}
var face_data_path = "res://scenes/face/"
var hair_data_path = "res://scenes/hair/"
var female_faces = []
var mesh_female_faces = {}
var male_faces = []
var mesh_male_faces = {}
var female_hairs = []
var male_hairs = []
var hair_materials = []
@@ -56,8 +58,11 @@ func _ready():
match g:
"female":
female_faces.push_back(fp)
mesh_female_faces[fp] = load(fp)
"male":
male_faces.push_back(fp)
mesh_male_faces[fp] = load(fp)
for id in range(10000):
var fp_m = face_data_path + "male-face" + str(id) + ".tscn"
var fp_f = face_data_path + "female-face" + str(id) + ".tscn"
@@ -66,8 +71,10 @@ func _ready():
var mat = hair_data_path + "hair" + str(id) + ".tres"
if data_fd.file_exists(fp_m):
male_faces.push_back(fp_m)
mesh_male_faces[fp_m] = load(fp_m)
if data_fd.file_exists(fp_f):
female_faces.push_back(fp_f)
mesh_female_faces[fp_f] = load(fp_f)
if data_fd.file_exists(hp_m):
male_hairs.push_back(hp_m)
if data_fd.file_exists(hp_f):
@@ -153,7 +160,7 @@ func compose_kinematic_character(g, enable_modules = [], face = -1, hair = -1, h
face = rnd.randi() % female_faces.size()
if hair == -1:
hair = rnd.randi() % female_hairs.size()
face_scene = load(female_faces[face])
face_scene = mesh_female_faces[female_faces[face]]
hair_scene = load(female_hairs[hair])
capsule.radius = 0.2
capsule.height = 1.1
@@ -172,7 +179,7 @@ func compose_kinematic_character(g, enable_modules = [], face = -1, hair = -1, h
face = rnd.randi() % male_faces.size()
if hair == -1:
hair = rnd.randi() % male_hairs.size()
face_scene = load(male_faces[face])
face_scene = mesh_male_faces[male_faces[face]]
hair_scene = load(male_hairs[hair])
capsule.radius = 0.3
capsule.height = 1.2

View File

@@ -49,6 +49,16 @@ onready var palace_map_data = {
"tower_roof_tile": tower_roof_tile
}
onready var buildings = {
"trailer_house": preload("res://buildings/trailer-house.gd").new()
}
func spawn_building(bname: String, xform: Transform) -> void:
if !buildings.has(bname):
return
var objects = buildings[bname].build_house(xform)
spawn_house_objects(xform, objects)
var traffic_rnd: RandomNumberGenerator
var traffic_astar: AStar
@@ -70,6 +80,8 @@ func setup_town(site):
center += p
center /= poly.size()
center.y = height
var infl = RoadsData.get_influence_cached(center.x, center.y, 256)
center.y = infl.y
var radial_points = RoadsData.get_site_radial_points(site, 32.0, 64.0)
var max_r = 0.0
for p in range(radial_points.size()):
@@ -79,16 +91,24 @@ func setup_town(site):
max_r = dst
for p in range(radial_points.size()):
var ep = radial_points[p]
var miff = RoadsData.get_influence_cached(ep.x, ep.z, 256.0)
ep.y = center.y
var d = (center - ep).normalized()
assert(d.length_squared() > 0)
var dst = ep.distance_to(center)
print(dst)
if dst < 64.0 + 12 + 8 + 4:
continue
var step = 16.0
var pstart = ep
var step = 32.0
var pstart = ep + d * 32.0
dst -= 32.0
while dst > 0.0:
var ok = true
miff = RoadsData.get_influence_cached(pstart.x, pstart.z, 256.0)
if miff.x > 0.0:
ok = false
if ok:
pstart.y = miff.y
if !Geometry.is_point_in_polygon(Vector2(pstart.x, pstart.z), poly2):
ok = false
if ok:
@@ -97,7 +117,7 @@ func setup_town(site):
ok = false
if ok:
var xform = Transform(Basis(), pstart).looking_at(pstart + d, Vector3.UP)
stream_obj("trailer_house", xform)
spawn_building("trailer_house", xform)
var aabb = AABB(pstart, Vector3())
aabb = aabb.grow(32)
aabbs.push_back(aabb)
@@ -123,7 +143,9 @@ func setup_first_town():
center += p
center /= poly.size()
center.y = height
# grid.build(border2, center)
var infl = RoadsData.get_influence_cached(center.x, center.z, 256)
center.y = infl.y
print("first town center: ", center)
var radial_points = RoadsData.get_site_radial_points(0, 32.0, 64.0)
var max_r = 0.0
for p in range(radial_points.size()):
@@ -151,16 +173,24 @@ func setup_first_town():
for p in range(radial_points.size()):
var ep = radial_points[p]
var miff = RoadsData.get_influence_cached(ep.x, ep.z, 256.0)
ep.y = center.y
var d = (center - ep).normalized()
assert(d.length_squared() > 0)
var dst = ep.distance_to(center)
print(dst)
if dst < 64.0 + 12 + 8 + 4:
continue
var step = 16.0
var pstart = ep
var step = 32.0
var pstart = ep + d * 32.0
dst -= 32.0
while dst > 0.0:
var ok = true
miff = RoadsData.get_influence_cached(pstart.x, pstart.z, 256.0)
if miff.x > 0.0:
ok = false
if ok:
pstart.y = miff.y
if !Geometry.is_point_in_polygon(Vector2(pstart.x, pstart.z), poly2):
ok = false
if ok:
@@ -169,7 +199,8 @@ func setup_first_town():
ok = false
if ok:
var xform = Transform(Basis(), pstart).looking_at(pstart + d, Vector3.UP)
stream_obj("trailer_house", xform)
# stream_obj("trailer_house", xform)
spawn_building("trailer_house", xform)
var aabb = AABB(pstart, Vector3())
aabb = aabb.grow(32)
aabbs.push_back(aabb)
@@ -237,11 +268,15 @@ func _ready():
}
for k in parts.keys():
Spawner.add_scene(k, parts[k])
Traffic.set_min_spawn_distance(50.0)
# Traffic.set_min_spawn_distance(50.0)
# Traffic.set_deny_physics()
Traffic.set_physics_distance(Vector3(30, -10, 40))
# Traffic.set_physics_distance(Vector3(30, -10, 40))
# Traffic.set_debug(true)
Traffic.set_spawn_cooldown(1, 5)
Traffic.set_default_speed(8.5)
Traffic.add_traffic_vehicle(car)
var water_mat = load("res://water/Water.material")
Water.set_material(water_mat)
var delay = 3.0
var state = 0
@@ -252,7 +287,7 @@ func _process(delta):
if delay < 0:
state = 1
1:
Spawner.update_view(self, 200)
# Spawner.update_view(self, 200)
var sc = get_tree().root
var viewport: = get_viewport()
if !viewport:
@@ -262,7 +297,7 @@ func _process(delta):
return
var cam_xform: = cam.global_transform
# building parts
call_deferred("real_spawn_child")
# call_deferred("real_spawn_child")
func stream_obj(obj: String, xform: Transform):
Spawner.place_scene(obj, xform)
@@ -272,53 +307,6 @@ func _physics_process(delta):
return
match state:
1:
# convert to distant traffic here
for n in get_tree().get_nodes_in_group("traffic_vehicle"):
var p1 = cam.global_transform.origin
var p2 = n.global_transform.origin
# p2 has both vertical and lane offset, correct these and write to path_pos
var path_pos = Traffic.get_path_position(n)
var check_coords = cam.global_transform.xform_inv(path_pos)
var steer = 0.0
var orientation = n.global_transform
orientation.origin = Vector3()
var direction = orientation.xform(Vector3(0, 0, -1))
var good_path = false
var engine_force = n.engine_force
if !n.has_meta("curve"):
continue
if n.has_meta("curve"):
# next_target has corrected vertical position (up from path)
steer = Traffic.get_steer(n, true) * 0.6
if !n.has_meta("space"):
var v = n.get_linear_velocity()
var l = v.length()
print("physics: velocity: ", v, " velocity norm: ", v.normalized())
if true:
if abs(steer) > 3.0:
engine_force *= 0.9
engine_force = clamp(engine_force, 2500.0, max(2500, engine_force))
else:
if abs(steer) > 4.0 && l > 5.0:
engine_force = engine_force * 0.9996
if l > 7.0:
engine_force = engine_force * 0.9996
elif l < 1.1:
engine_force = clamp(engine_force * 1.004, 6000, 8000)
elif l < 2.5:
engine_force = clamp(engine_force * 1.002, 5000, 7000)
elif l < 5.0:
engine_force = clamp(engine_force * 1.001, 4000, 6000)
elif l < 6.0:
engine_force = clamp(engine_force * 1.001, 3000, 5000)
engine_force = clamp(engine_force, 0, 3500)
# print("engine_force: ", engine_force)
n.engine_force = engine_force
n.brake = 0
var base_steering = n.steering
var main_steering = base_steering * 0.95 + steer * 0.05
n.steering = clamp(main_steering, -1, 1)
n.set_meta("steering", n.steering)
var space_state = get_viewport().get_world().direct_space_state
# probaly should not be here
for n in get_tree().get_nodes_in_group("spawn"):
@@ -353,17 +341,13 @@ func _physics_process(delta):
# buildings
var spawn = []
#var spawn = []
onready var spawn_lock: Mutex = Mutex.new()
func spawn_child(n: String, xform: Transform) -> void:
var sp = {"node": n, "xform": xform}
spawn.push_back(sp)
func real_spawn_child():
var count = 0
while spawn.size() > 0:
var e = spawn.pop_front()
Spawner.place_scene(e.node, e.xform)
count += 1
spawn_lock.lock()
Spawner.queue_place_scene(n, xform)
spawn_lock.unlock()
func update_node_position(n):
var space_state = get_viewport().get_world().direct_space_state
@@ -377,3 +361,21 @@ func update_node_position(n):
return
else:
n.global_transform.origin = result.position
func spawn_house_objects(place: Transform, objects) -> void:
for obj in objects:
var x = obj.xform
for w in obj.data:
if w.ends_with("_rotated"):
x.basis = x.basis.rotated(Vector3(0, 1, 0), PI)
var n = w.replace("_rotated", "")
spawn_child(n, place * x)
else:
spawn_child(w, place * x)
static func get_place_rnd(xform: Transform):
var rnd = RandomNumberGenerator.new()
var s = int(xform.origin.x + 100 * xform.origin.z * 2) % 0x1ffffff
rnd.seed = s
return rnd

View File

@@ -0,0 +1,54 @@
extends Reference
static func build_house(main_xform: Transform):
var rnd = streaming.get_place_rnd(main_xform)
print(main_xform.origin, " seed = ", rnd.state)
var l = 5 + 2 * (rnd.randi() % 5) - 1
var h = l - 1
var d = 3 + rnd.randi() % (l - 4 + 1)
var range_used = false
var objects = []
for k in range(l + 1):
var pos = Vector3(0, 0, k * 2)
var xform = Transform(Basis(), pos)
if k > 0:
var what
if k != d && rnd.randf() > 0.5 && !range_used:
what = "roof_floor_range"
range_used = true
else:
what = "roof_floor"
objects.push_back({"xform": xform, "data": [what]})
var xt = [Transform(Basis(), pos), Transform(Basis().rotated(Vector3.UP, PI), pos - Vector3(0, 0, 2))]
for x in range(xt.size()):
if x == 0 && k == d:
continue
if rnd.randf() > 0.5:
what = "wall_solid"
elif rnd.randf() > 0.5:
what = "window_narrow"
else:
what = "window_wide"
objects.push_back({"xform": xt[x], "data": [what]})
var obj_data = []
if k > 1 && k < l && rnd.randf() > 0.6:
objects.push_back({"xform": xform, "data": ["wall_internal"]})
match k:
0:
obj_data = ["side_wall", "bottom_side"]
1:
obj_data = ["bottom"]
2:
obj_data = ["bottom_wheels"]
d:
obj_data = ["entry", "bottom"]
h:
obj_data = ["bottom_wheels"]
l:
obj_data = ["side_wall_rotated", "bottom_side_rotated", "bottom"]
_:
obj_data = ["bottom"]
objects.push_back({"xform": xform, "data": obj_data})
return objects

8
bush.tscn Normal file
View File

@@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://terrain-objects/terrain-bushes_p1_l0.mesh" type="ArrayMesh" id=1]
[node name="bush" type="StaticBody"]
[node name="MeshInstance" type="MeshInstance" parent="."]
mesh = ExtResource( 1 )

View File

@@ -74,6 +74,7 @@ func _ready():
car.add_to_group("keep")
car.add_to_group("car")
add_child(car)
car.global_transform.origin = Vector3(-3, 0, -3)
for e in range(5):
var major_f = Spatial.new()
major_f.add_to_group("spawn")

View File

@@ -1,21 +1,8 @@
extends Spatial
onready var rnd = RandomNumberGenerator.new()
var spawn = []
func _ready():
pass
func spawn_child(n: String, xform: Transform) -> void:
var x = xform
if n.ends_with("_rotated"):
x.basis = x.basis.rotated(Vector3(0, 1, 0), PI)
n = n.replace("_rotated", "")
streaming.spawn_child(n, global_transform * x)
static func build_house(main_xform: Transform):
var rnd = RandomNumberGenerator.new()
var s = int(main_xform.origin.x + 100 * main_xform.origin.z * 2) % 0x1ffffff
rnd.seed = s
print(main_xform.origin, " seed = ", s)
var rnd = streaming.get_place_rnd(main_xform)
print(main_xform.origin, " seed = ", rnd.state)
var l = 6 + 2 * rnd.randi() % 7 - 1
var h = l - 1
var d = 3 + rnd.randi() % (l - 5 + 1)
@@ -73,10 +60,7 @@ func _process(delta):
state = 1
1:
var objects = build_house(global_transform)
for obj in objects:
var x = obj.xform
for w in obj.data:
call_deferred("spawn_child", w, x)
streaming.spawn_house_objects(global_transform, objects)
state = 2
2:
set_process(false)

View File

@@ -84,4 +84,9 @@ fps_mode={
quality/driver/fallback_to_gles2=true
quality/spatial_partitioning/render_tree_balance=0.22
batching/options/use_batching=false
[voxel]
threads/count/minimum=2
threads/count/margin_below_max=2
threads/main/time_budget_ms=1.0

View File

@@ -102,7 +102,10 @@ func _physics_process(delta):
vehicle.steering = -xmotion.x * 0.7
else:
vehicle.brake = 0
if vehicle.linear_velocity.length() < 16.6:
vehicle.engine_force = 4000 * xmotion.y
else:
vehicle.engine_force = 500 * xmotion.y
var accel = vehicle.angular_velocity * 350.0 * delta
vehicle.steering = -xmotion.x * 0.7

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,560 @@
{
"asset" : {
"generator" : "Khronos glTF Blender I/O v1.5.17",
"version" : "2.0"
},
"scene" : 0,
"scenes" : [
{
"name" : "Scene",
"nodes" : [
0,
1,
2,
3,
4
]
}
],
"nodes" : [
{
"mesh" : 0,
"name" : "p1_l0",
"translation" : [
-2.9100000858306885,
0,
-3.072000026702881
]
},
{
"mesh" : 1,
"name" : "p2_l0",
"translation" : [
-2,
0,
-3.072000026702881
]
},
{
"mesh" : 2,
"name" : "p3_l0",
"translation" : [
-1.0899999141693115,
0,
-3.072000026702881
]
},
{
"mesh" : 3,
"name" : "p4_l0",
"translation" : [
-2.9100000858306885,
0,
-4.8919997215271
]
},
{
"mesh" : 4,
"name" : "p5_l0",
"translation" : [
-1.0899999141693115,
0,
-4.8919997215271
]
}
],
"materials" : [
{
"doubleSided" : true,
"name" : "Green.004",
"pbrMetallicRoughness" : {
"baseColorFactor" : [
0.06995400041341782,
0.12185700237751007,
0.047887999564409256,
1
],
"metallicFactor" : 0,
"roughnessFactor" : 0.6732679605484009
}
},
{
"doubleSided" : true,
"name" : "Wood",
"pbrMetallicRoughness" : {
"baseColorFactor" : [
0.12234099954366684,
0.05628800019621849,
0.04760900139808655,
1
],
"metallicFactor" : 0,
"roughnessFactor" : 0.6732679605484009
}
},
{
"doubleSided" : true,
"name" : "Leaves",
"pbrMetallicRoughness" : {
"baseColorFactor" : [
0.12185700237751007,
0.09563499689102173,
0.07339099794626236,
1
],
"metallicFactor" : 0,
"roughnessFactor" : 0.6732679605484009
}
},
{
"doubleSided" : true,
"name" : "DarkGreen",
"pbrMetallicRoughness" : {
"baseColorFactor" : [
0.042527999728918076,
0.07266899943351746,
0.02957800030708313,
1
],
"metallicFactor" : 0,
"roughnessFactor" : 0.6732679605484009
}
},
{
"doubleSided" : true,
"name" : "Green.005",
"pbrMetallicRoughness" : {
"baseColorFactor" : [
0.06995400041341782,
0.12185700237751007,
0.047887999564409256,
1
],
"metallicFactor" : 0,
"roughnessFactor" : 0.6732679605484009
}
},
{
"doubleSided" : true,
"name" : "Yellow.001",
"pbrMetallicRoughness" : {
"baseColorFactor" : [
0.358379989862442,
0.2837910056114197,
0.0901150032877922,
1
],
"metallicFactor" : 0,
"roughnessFactor" : 0.6732679605484009
}
},
{
"doubleSided" : true,
"name" : "Pink",
"pbrMetallicRoughness" : {
"baseColorFactor" : [
0.373759001493454,
0.09044600278139114,
0.22160300612449646,
1
],
"metallicFactor" : 0,
"roughnessFactor" : 0.6732679605484009
}
}
],
"meshes" : [
{
"name" : "p1_l0",
"primitives" : [
{
"attributes" : {
"POSITION" : 0,
"NORMAL" : 1
},
"indices" : 2,
"material" : 0
}
]
},
{
"name" : "p2_l0",
"primitives" : [
{
"attributes" : {
"POSITION" : 3,
"NORMAL" : 4
},
"indices" : 5,
"material" : 1
},
{
"attributes" : {
"POSITION" : 6,
"NORMAL" : 7
},
"indices" : 8,
"material" : 2
}
]
},
{
"name" : "p3_l0",
"primitives" : [
{
"attributes" : {
"POSITION" : 9,
"NORMAL" : 10
},
"indices" : 11,
"material" : 3
}
]
},
{
"name" : "p4_l0",
"primitives" : [
{
"attributes" : {
"POSITION" : 12,
"NORMAL" : 13
},
"indices" : 14,
"material" : 4
}
]
},
{
"name" : "p5_l0",
"primitives" : [
{
"attributes" : {
"POSITION" : 15,
"NORMAL" : 16
},
"indices" : 17,
"material" : 5
},
{
"attributes" : {
"POSITION" : 18,
"NORMAL" : 19
},
"indices" : 20,
"material" : 6
}
]
}
],
"accessors" : [
{
"bufferView" : 0,
"componentType" : 5126,
"count" : 624,
"max" : [
0.5527048110961914,
0.4361256957054138,
0.5199175477027893
],
"min" : [
-0.540502667427063,
-0.025527318939566612,
-0.34054291248321533
],
"type" : "VEC3"
},
{
"bufferView" : 1,
"componentType" : 5126,
"count" : 624,
"type" : "VEC3"
},
{
"bufferView" : 2,
"componentType" : 5123,
"count" : 888,
"type" : "SCALAR"
},
{
"bufferView" : 3,
"componentType" : 5126,
"count" : 80,
"max" : [
0.018657727167010307,
1.6145683526992798,
0.04910542815923691
],
"min" : [
-0.03639454022049904,
-0.00018746100249700248,
-0.020252957940101624
],
"type" : "VEC3"
},
{
"bufferView" : 4,
"componentType" : 5126,
"count" : 80,
"type" : "VEC3"
},
{
"bufferView" : 5,
"componentType" : 5123,
"count" : 114,
"type" : "SCALAR"
},
{
"bufferView" : 6,
"componentType" : 5126,
"count" : 420,
"max" : [
0.2818242609500885,
1.4256141185760498,
0.3100934326648712
],
"min" : [
-0.3423629105091095,
0.26863014698028564,
-0.3140755295753479
],
"type" : "VEC3"
},
{
"bufferView" : 7,
"componentType" : 5126,
"count" : 420,
"type" : "VEC3"
},
{
"bufferView" : 8,
"componentType" : 5123,
"count" : 540,
"type" : "SCALAR"
},
{
"bufferView" : 9,
"componentType" : 5126,
"count" : 1134,
"max" : [
0.45378240942955017,
0.8412840366363525,
0.4951355457305908
],
"min" : [
-0.5378227233886719,
-0.017499301582574844,
-0.3897447884082794
],
"type" : "VEC3"
},
{
"bufferView" : 10,
"componentType" : 5126,
"count" : 1134,
"type" : "VEC3"
},
{
"bufferView" : 11,
"componentType" : 5123,
"count" : 1800,
"type" : "SCALAR"
},
{
"bufferView" : 12,
"componentType" : 5126,
"count" : 932,
"max" : [
0.7841669917106628,
0.7323634624481201,
0.8904631733894348
],
"min" : [
-0.9583673477172852,
-0.005544625222682953,
-1.0364927053451538
],
"type" : "VEC3"
},
{
"bufferView" : 13,
"componentType" : 5126,
"count" : 932,
"type" : "VEC3"
},
{
"bufferView" : 14,
"componentType" : 5123,
"count" : 1536,
"type" : "SCALAR"
},
{
"bufferView" : 15,
"componentType" : 5126,
"count" : 1196,
"max" : [
0.7932196855545044,
0.8964381814002991,
0.7817763686180115
],
"min" : [
-0.7932196855545044,
-0.02066883072257042,
-0.7817763686180115
],
"type" : "VEC3"
},
{
"bufferView" : 16,
"componentType" : 5126,
"count" : 1196,
"type" : "VEC3"
},
{
"bufferView" : 17,
"componentType" : 5123,
"count" : 1806,
"type" : "SCALAR"
},
{
"bufferView" : 18,
"componentType" : 5126,
"count" : 36,
"max" : [
0.05127303674817085,
1.2399932146072388,
0.05427424982190132
],
"min" : [
-0.05127303674817085,
0.5572494268417358,
-0.05427418276667595
],
"type" : "VEC3"
},
{
"bufferView" : 19,
"componentType" : 5126,
"count" : 36,
"type" : "VEC3"
},
{
"bufferView" : 20,
"componentType" : 5123,
"count" : 54,
"type" : "SCALAR"
}
],
"bufferViews" : [
{
"buffer" : 0,
"byteLength" : 7488,
"byteOffset" : 0
},
{
"buffer" : 0,
"byteLength" : 7488,
"byteOffset" : 7488
},
{
"buffer" : 0,
"byteLength" : 1776,
"byteOffset" : 14976
},
{
"buffer" : 0,
"byteLength" : 960,
"byteOffset" : 16752
},
{
"buffer" : 0,
"byteLength" : 960,
"byteOffset" : 17712
},
{
"buffer" : 0,
"byteLength" : 228,
"byteOffset" : 18672
},
{
"buffer" : 0,
"byteLength" : 5040,
"byteOffset" : 18900
},
{
"buffer" : 0,
"byteLength" : 5040,
"byteOffset" : 23940
},
{
"buffer" : 0,
"byteLength" : 1080,
"byteOffset" : 28980
},
{
"buffer" : 0,
"byteLength" : 13608,
"byteOffset" : 30060
},
{
"buffer" : 0,
"byteLength" : 13608,
"byteOffset" : 43668
},
{
"buffer" : 0,
"byteLength" : 3600,
"byteOffset" : 57276
},
{
"buffer" : 0,
"byteLength" : 11184,
"byteOffset" : 60876
},
{
"buffer" : 0,
"byteLength" : 11184,
"byteOffset" : 72060
},
{
"buffer" : 0,
"byteLength" : 3072,
"byteOffset" : 83244
},
{
"buffer" : 0,
"byteLength" : 14352,
"byteOffset" : 86316
},
{
"buffer" : 0,
"byteLength" : 14352,
"byteOffset" : 100668
},
{
"buffer" : 0,
"byteLength" : 3612,
"byteOffset" : 115020
},
{
"buffer" : 0,
"byteLength" : 432,
"byteOffset" : 118632
},
{
"buffer" : 0,
"byteLength" : 432,
"byteOffset" : 119064
},
{
"buffer" : 0,
"byteLength" : 108,
"byteOffset" : 119496
}
],
"buffers" : [
{
"byteLength" : 119604,
"uri" : "terrain-bushes.bin"
}
]
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,7 +1,49 @@
shader_type spatial;
uniform sampler2D u_texture_top : hint_albedo;
uniform sampler2D u_texture_sides : hint_albedo;
// Bitmask telling which of the 6 faces of the block are bordered by a block of lower resolution
uniform int u_transition_mask;
// We'll need to pass data from the vertex shader to the fragment shader
varying vec3 v_world_pos;
varying vec3 v_world_normal;
varying vec4 v_weights;
varying vec4 v_indices;
// 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_triplanar(sampler2D tex, vec3 world_pos, vec3 blend) {
vec4 xaxis = texture(tex, world_pos.yz);
vec4 yaxis = texture(tex, world_pos.xz);
vec4 zaxis = texture(tex, world_pos.xy);
// blend the results of the 3 planar projections.
return xaxis * blend.x + yaxis * blend.y + zaxis * blend.z;
}
float get_hash(vec2 c) {
return fract(sin(dot(c.xy, vec2(12.9898,78.233))) * 43758.5453);
}
vec3 get_transvoxel_position(vec3 vertex_pos, vec4 vertex_col) {
int border_mask = int(vertex_col.a);
@@ -23,9 +65,42 @@ vec3 get_transvoxel_position(vec3 vertex_pos, vec4 vertex_col) {
}
void vertex() {
// Indices are integer values so we can decode them as-is
v_indices = decode_8bit_vec4(UV.x);
// Weights must be in [0..1] so we divide them
v_weights = decode_8bit_vec4(UV.y) / 255.0;
//v_normal = NORMAL;
vec3 world_pos = (WORLD_MATRIX * vec4(VERTEX, 1.0)).xyz;
v_world_pos = world_pos;
v_world_normal = NORMAL;
VERTEX = get_transvoxel_position(VERTEX, COLOR);
}
void fragment() {
ALBEDO = vec3(1, 1, 0);
vec3 normal = v_world_normal;//normalize(v_world_normal);
vec3 wpos = v_world_pos * 0.2;
// 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_world_normal);
vec3 top_col = texture_triplanar(u_texture_top, wpos, blending).rgb;
vec3 side_col = texture_triplanar(u_texture_sides, wpos, blending).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;
float r = top_col.r;
ALBEDO = mix(side_col, top_col, clamp(normal.y * 10.0 - 4.0 - 8.0*r, 0.0, 1.0));
}

31
tree.tscn Normal file
View File

@@ -0,0 +1,31 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://terrain-objects/terrain-trees_t1_l0.mesh" type="ArrayMesh" id=1]
[sub_resource type="CylinderShape" id=1]
radius = 0.3
height = 2.25014
[sub_resource type="SphereShape" id=2]
radius = 1.4
[node name="tree" type="StaticBody"]
[node name="MeshInstance" type="MeshInstance" parent="."]
mesh = ExtResource( 1 )
[node name="CollisionShape" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 0, 0, 0.995445, -0.0953419, 0, 0.0953419, 0.995445, 0, 1.0768, 0 )
shape = SubResource( 1 )
[node name="CollisionShape2" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.59792, 1.42922 )
shape = SubResource( 2 )
[node name="CollisionShape3" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.74276, -1.29866 )
shape = SubResource( 2 )
[node name="CollisionShape4" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0707073, 2.96499, 0.0801156 )
shape = SubResource( 2 )

BIN
water/Caustic.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 597 KiB

25
water/Caustic.png.import Normal file
View File

@@ -0,0 +1,25 @@
[remap]
importer="texture_array"
type="TextureArray"
path="res://.import/Caustic.png-83d58ee04a2e46ae9b1eac21320e0bc3.texarr"
metadata={
"vram_texture": false
}
[deps]
source_file="res://water/Caustic.png"
dest_files=[ "res://.import/Caustic.png-83d58ee04a2e46ae9b1eac21320e0bc3.texarr" ]
[params]
compress/mode=0
compress/no_bptc_if_rgb=false
flags/repeat=true
flags/filter=true
flags/mipmaps=true
flags/anisotropic=false
flags/srgb=2
slices/horizontal=8
slices/vertical=8

BIN
water/Foam.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

35
water/Foam.png.import Normal file
View File

@@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Foam.png-7d99bc032ec52df842a38df4c4ac4710.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://water/Foam.png"
dest_files=[ "res://.import/Foam.png-7d99bc032ec52df842a38df4c4ac4710.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=true
flags/filter=true
flags/mipmaps=true
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

BIN
water/Water.material Normal file

Binary file not shown.

190
water/Water.shader Normal file
View File

@@ -0,0 +1,190 @@
/*
Realistic Water Shader for GODOT 3.1.1
Copyright (c) 2019 UnionBytes, Achim Menzel (alias AiYori)
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
-- UnionBytes <https://www.unionbytes.de/>
-- YouTube: <https://www.youtube.com/user/UnionBytes>
*/
// For this shader min. GODOT 3.1.1 is required, because 3.1 has a depth buffer bug!
shader_type spatial;
render_mode cull_back,diffuse_burley,specular_schlick_ggx, blend_mix;
// Wave settings:
uniform float wave_speed = 0.5; // Speed scale for the waves
uniform vec4 wave_a = vec4(1.0, 1.0, 0.35, 3.0); // xy = Direction, z = Steepness, w = Length
uniform vec4 wave_b = vec4(1.0, 0.6, 0.30, 1.55); // xy = Direction, z = Steepness, w = Length
uniform vec4 wave_c = vec4(1.0, 1.3, 0.25, 0.9); // xy = Direction, z = Steepness, w = Length
// Surface settings:
uniform vec2 sampler_scale = vec2(0.25, 0.25); // Scale for the sampler
uniform vec2 sampler_direction= vec2(0.05, 0.04); // Direction and speed for the sampler offset
uniform sampler2D uv_sampler : hint_aniso; // UV motion sampler for shifting the normalmap
uniform vec2 uv_sampler_scale = vec2(0.25, 0.25); // UV sampler scale
uniform float uv_sampler_strength = 0.04; // UV shifting strength
uniform sampler2D normalmap_a_sampler : hint_normal; // Normalmap sampler A
uniform sampler2D normalmap_b_sampler : hint_normal; // Normalmap sampler B
uniform sampler2D foam_sampler : hint_black; // Foam sampler
uniform float foam_level = 0.5; // Foam level -> distance from the object (0.0 - 0.5)
// Volume settings:
uniform float refraction = 0.075; // Refraction of the water
uniform vec4 color_deep : hint_color; // Color for deep places in the water, medium to dark blue
uniform vec4 color_shallow : hint_color; // Color for lower places in the water, bright blue - green
uniform float beers_law = 2.0; // Beers law value, regulates the blending size to the deep water level
uniform float depth_offset = -0.75; // Offset for the blending
// Projector for the water caustics:
uniform mat4 projector; // Projector matrix, mostly the matric of the sun / directlight
uniform sampler2DArray caustic_sampler : hint_black; // Caustic sampler, (Texture array with 16 Textures for the animation)
// Vertex -> Fragment:
varying float vertex_height; // Height of the water surface
varying vec3 vertex_normal; // Vertex normal -> Needed for refraction calculation
varying vec3 vertex_binormal; // Vertex binormal -> Needed for refraction calculation
varying vec3 vertex_tangent; // Vertex tangent -> Needed for refraction calculation
varying mat4 inv_mvp; // Inverse ModelViewProjection matrix -> Needed for caustic projection
varying vec3 vertex_pos;
// Wave function:
vec4 wave(vec4 parameter, vec2 position, float time, inout vec3 tangent, inout vec3 binormal)
{
float wave_steepness = parameter.z;
float wave_length = parameter.w;
float k = 2.0 * 3.14159265359 / wave_length;
float c = sqrt(9.8 / k);
vec2 d = normalize(parameter.xy);
float f = k * (dot(d, position) - c * time);
float a = wave_steepness / k;
tangent += normalize(vec3(1.0-d.x * d.x * (wave_steepness * sin(f)), d.x * (wave_steepness * cos(f)), -d.x * d.y * (wave_steepness * sin(f))));
binormal += normalize(vec3(-d.x * d.y * (wave_steepness * sin(f)), d.y * (wave_steepness * cos(f)), 1.0-d.y * d.y * (wave_steepness * sin(f))));
return vec4(d.x * (a * cos(f)), a * sin(f) * 0.25, d.y * (a * cos(f)), 0.0);
}
// Vertex shader:
void vertex()
{
float time = TIME * wave_speed;
vec4 vertex = vec4(VERTEX, 1.0);
vec3 vertex_position = (WORLD_MATRIX * vertex).xyz;
vertex_tangent = vec3(0.0, 0.0, 0.0);
vertex_binormal = vec3(0.0, 0.0, 0.0);
vec3 tmp_tangent = vertex_tangent;
vec3 tmp_binormal = vertex_binormal;
vertex += wave(wave_a, vertex_position.xz, time, tmp_tangent, tmp_binormal);
vertex += wave(wave_b, vertex_position.xz, time, tmp_tangent, tmp_binormal);
vertex += wave(wave_c, vertex_position.xz, time, tmp_tangent, tmp_binormal);
vertex_tangent = tmp_tangent;
vertex_binormal = tmp_binormal;
vertex_position = vertex.xyz;
vertex_height = (PROJECTION_MATRIX * MODELVIEW_MATRIX * vertex).z;
TANGENT = vertex_tangent;
BINORMAL = vertex_binormal;
vertex_normal = normalize(cross(vertex_binormal, vertex_tangent));
NORMAL = vertex_normal;
UV = vertex.xz * sampler_scale;
VERTEX = vertex.xyz;
inv_mvp = inverse(PROJECTION_MATRIX * MODELVIEW_MATRIX);
vertex_pos = vertex_position;
}
// Fragment shader:
void fragment()
{
// Calculation of the UV with the UV motion sampler
vec2 uv_offset = sampler_direction * TIME;
vec2 uv_sampler_uv = UV * uv_sampler_scale + uv_offset;
vec2 uv_sampler_uv_offset = uv_sampler_strength * texture(uv_sampler, uv_sampler_uv).rg * 2.0 - 1.0;
vec2 uv = UV + uv_sampler_uv_offset;
// Normalmap:
vec3 normalmap = texture(normalmap_a_sampler, uv - uv_offset * 2.0 + vertex_pos.xz).rgb * 0.75; // 75 % sampler A
normalmap += texture(normalmap_b_sampler, uv + uv_offset + vertex_pos.xz).rgb * 0.25; // 25 % sampler B
// vec3 normalmap = texture(normalmap_b_sampler, uv + uv_offset).rgb;
// Refraction UV:
vec3 ref_normalmap = normalmap * 2.0 - 1.0;
ref_normalmap = normalize(vertex_tangent*ref_normalmap.x + vertex_binormal*ref_normalmap.y + vertex_normal*ref_normalmap.z);
vec2 ref_uv = SCREEN_UV + (ref_normalmap.xy * refraction) / vertex_height;
// Ground depth:
float depth_raw = texture(DEPTH_TEXTURE, ref_uv).r * 2.0 - 1.0;
float depth = PROJECTION_MATRIX[3][2] / (depth_raw + PROJECTION_MATRIX[2][2]);
float depth_blend = exp((depth+VERTEX.z + depth_offset) * -beers_law);
depth_blend = clamp(1.0-depth_blend, 0.0, 1.0);
float depth_blend_pow = clamp(pow(depth_blend, 2.5), 0.0, 1.0);
// Ground color:
vec3 screen_color = textureLod(SCREEN_TEXTURE, ref_uv, depth_blend_pow * 2.5).rgb;
vec3 dye_color = mix(color_shallow.rgb, color_deep.rgb, depth_blend_pow);
vec3 color = mix(screen_color*dye_color, dye_color*0.25, depth_blend_pow*0.5);
// Caustic screen projection
vec4 caustic_screenPos = vec4(ref_uv*2.0-1.0, depth_raw, 1.0);
vec4 caustic_localPos = inv_mvp * caustic_screenPos;
caustic_localPos = vec4(caustic_localPos.xyz/caustic_localPos.w, caustic_localPos.w);
vec2 caustic_Uv = caustic_localPos.xz / vec2(1024.0) + 0.5;
vec4 caustic_color = texture(caustic_sampler, vec3(caustic_Uv*300.0, mod(TIME*14.0, 16.0)));
color *= 1.0 + pow(caustic_color.r, 1.50) * (1.0-depth_blend) * 6.0;
// Foam:
if(depth + VERTEX.z < foam_level && depth > vertex_height-0.1)
{
float foam_noise = clamp(pow(texture(foam_sampler, (uv * 4.0) - uv_offset).r, 10.0)*40.0, 0.0, 0.2);
float foam_mix = clamp(pow((1.0-(depth + VERTEX.z) + foam_noise), 8.0) * foam_noise * 0.4, 0.0, 1.0);
color = mix(color, vec3(1.0), foam_mix);
}
// Set all values:
ALBEDO = color;
METALLIC = 0.1;
ROUGHNESS = 0.2;
SPECULAR = 0.2 + depth_blend_pow * 0.4;
NORMALMAP = normalmap;
NORMALMAP_DEPTH = 0.3;
}

BIN
water/Water_N_A.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 424 KiB

View File

@@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Water_N_A.png-ab0fffc5ebbddbcc10a6a59768d1c169.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://water/Water_N_A.png"
dest_files=[ "res://.import/Water_N_A.png-ab0fffc5ebbddbcc10a6a59768d1c169.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=1
flags/repeat=true
flags/filter=true
flags/mipmaps=true
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=false
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Some files were not shown because too many files have changed in this diff Show More