Added DMC paged terrain test scene

master
Marc Gilleron 2019-04-28 01:35:15 +01:00
parent 0c441eca6b
commit 68af715c08
8 changed files with 323 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 MiB

View File

@ -0,0 +1,36 @@
[remap]
importer="texture"
type="StreamTexture"
path.s3tc="res://.import/dirt_albedo.png-75b50e042275a94a5dad2f9e0c994d5e.s3tc.stex"
path.etc2="res://.import/dirt_albedo.png-75b50e042275a94a5dad2f9e0c994d5e.etc2.stex"
metadata={
"imported_formats": [ "s3tc", "etc2" ],
"vram_texture": true
}
[deps]
source_file="res://dmc_terrain/dirt_albedo.png"
dest_files=[ "res://.import/dirt_albedo.png-75b50e042275a94a5dad2f9e0c994d5e.s3tc.stex", "res://.import/dirt_albedo.png-75b50e042275a94a5dad2f9e0c994d5e.etc2.stex" ]
[params]
compress/mode=2
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=1
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

View File

@ -0,0 +1,37 @@
shader_type spatial;
uniform sampler2D u_texture_top : hint_albedo;
uniform sampler2D u_texture_sides : hint_albedo;
varying vec3 v_world_pos;
varying vec3 v_world_normal;
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;
}
void vertex() {
v_world_pos = VERTEX;
v_world_normal = NORMAL;
}
void fragment() {
vec3 normal = v_world_normal;
vec3 wpos = v_world_pos * 0.2;
vec3 blending = get_triplanar_blend(normal);
vec3 top_col = texture_triplanar(u_texture_top, wpos, blending).rgb;
vec3 side_col = texture_triplanar(u_texture_sides, wpos, blending).rgb;
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));
}

View File

@ -0,0 +1,10 @@
[gd_resource type="ShaderMaterial" load_steps=4 format=2]
[ext_resource path="res://dmc_terrain/dmc_terrain.shader" type="Shader" id=1]
[ext_resource path="res://dmc_terrain/grass_albedo.png" type="Texture" id=2]
[ext_resource path="res://dmc_terrain/dirt_albedo.png" type="Texture" id=3]
[resource]
shader = ExtResource( 1 )
shader_param/u_texture_top = ExtResource( 2 )
shader_param/u_texture_sides = ExtResource( 3 )

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 MiB

View File

@ -0,0 +1,36 @@
[remap]
importer="texture"
type="StreamTexture"
path.s3tc="res://.import/grass_albedo.png-919a5785cc1d44de952c7e630d907cd2.s3tc.stex"
path.etc2="res://.import/grass_albedo.png-919a5785cc1d44de952c7e630d907cd2.etc2.stex"
metadata={
"imported_formats": [ "s3tc", "etc2" ],
"vram_texture": true
}
[deps]
source_file="res://dmc_terrain/grass_albedo.png"
dest_files=[ "res://.import/grass_albedo.png-919a5785cc1d44de952c7e630d907cd2.s3tc.stex", "res://.import/grass_albedo.png-919a5785cc1d44de952c7e630d907cd2.etc2.stex" ]
[params]
compress/mode=2
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=1
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

View File

@ -0,0 +1,128 @@
extends Node
var _action_place = false
var _action_remove = false
var _head = null
var _terrain = null
func _ready():
_head = get_parent().get_node("Camera")
_terrain = get_parent().get_parent().get_node("VoxelTerrain")
func _input(event):
return
if not Input.is_key_pressed(KEY_CONTROL):
return
if event is InputEventMouseButton:
if event.pressed:
if event.button_index == BUTTON_LEFT:
_action_place = true
elif event.button_index == BUTTON_RIGHT:
_action_remove = true
elif event is InputEventKey:
if event.pressed:
if event.scancode == KEY_P:
print_map_slice()
func _process(delta):
var head_trans = _head.global_transform
var pointed_pos = head_trans.origin - 6.0 * head_trans.basis.z
if _action_place:
do_sphere(pointed_pos, 3.5, true)
elif _action_remove:
do_sphere(pointed_pos, 3.5, false)
_action_place = false
_action_remove = false
func do_sphere(center, fradius, add):
var storage = _terrain.get_storage()
var r = int(floor(fradius)) + 2
var channel = VoxelBuffer.CHANNEL_ISOLEVEL
var xc = int(floor(center.x))
var yc = int(floor(center.y))
var zc = int(floor(center.z))
for zi in range(-r, r):
for xi in range(-r, r):
for yi in range(-r, r):
var x = xi + xc
var y = yi + yc
var z = zi + zc
var pos = Vector3(x, y, z)
var d = pos.distance_to(center) - fradius
var e = storage.get_voxel_f(x, y, z, channel)
var res
if add:
res = min(d, e)
else:
res = max(d, e)
#print(res)
storage.set_voxel_f(res, x, y, z, channel)
_terrain.make_area_dirty(AABB(center - Vector3(r,r,r), 2*Vector3(r,r,r)))
func print_map_slice():
var storage = _terrain.get_storage()
var h = 8
var r = 16
var pos = _head.global_transform.origin
var buffer = VoxelBuffer.new()
buffer.create(2*r, h, 2*r)
var channel = VoxelBuffer.CHANNEL_ISOLEVEL
var minp = pos - Vector3(r, h/2, r)
#print("Printing ", minp, " ; ", buffer.get_size())
#storage.get_buffer_copy(minp, buffer, channel)
for rx in buffer.get_size_x():
for ry in buffer.get_size_y():
for rz in buffer.get_size_z():
var x = rx + int(minp.x)
var y = ry + int(minp.y)
var z = rz + int(minp.z)
var v = storage.get_voxel_f(x, y, z, channel)
buffer.set_voxel_iso(v, rx, ry, rz, channel)
print("Going to print")
print_buffer_to_images(buffer, channel, "isolevel", 10)
static func print_buffer_to_images(voxels, channel, fname, upscale):
for y in voxels.get_size_y():
var im = Image.new()
im.create(voxels.get_size_x(), voxels.get_size_z(), false, Image.FORMAT_RGB8)
im.lock()
for z in voxels.get_size_z():
for x in voxels.get_size_x():
var r = 0.5 * voxels.get_voxel_iso(x, y, z, channel) + 0.5
if r < 0.5:
im.set_pixel(x, z, Color(r, r, r*0.5 + 0.5))
else:
im.set_pixel(x, z, Color(r, r, r))
im.unlock()
if upscale > 1:
im.resize(im.get_width() * upscale, im.get_height() * upscale, Image.INTERPOLATE_NEAREST)
var fname_png = str(fname, "_", y, ".png")
print("Saved ", fname_png)
im.save_png(fname_png)
print("Printed")

View File

@ -0,0 +1,76 @@
[gd_scene load_steps=13 format=2]
[ext_resource path="res://dmc_terrain/interaction.gd" type="Script" id=1]
[ext_resource path="res://dmc_terrain/dmc_terrain_material.tres" type="Material" id=2]
[ext_resource path="res://blocky_terrain/noise_distorted.png" type="Image" id=3]
[ext_resource path="res://spectator_avatar.tscn" type="PackedScene" id=4]
[ext_resource path="res://axes.tscn" type="PackedScene" id=5]
[sub_resource type="ProceduralSky" id=1]
sky_top_color = Color( 0.388235, 0.533333, 0.615686, 1 )
sun_curve = 0.018301
[sub_resource type="Environment" id=2]
background_mode = 2
background_sky = SubResource( 1 )
ambient_light_sky_contribution = 0.5
[sub_resource type="VoxelProviderImage" id=3]
image = ExtResource( 3 )
channel = 1
[sub_resource type="Voxel" id=4]
transparent = true
[sub_resource type="Voxel" id=5]
geometry_type = 1
cube_geometry/padding_y = 0.0
cube_tiles/left = Vector2( 0, 0 )
cube_tiles/right = Vector2( 0, 0 )
cube_tiles/bottom = Vector2( 0, 0 )
cube_tiles/top = Vector2( 0, 0 )
cube_tiles/back = Vector2( 0, 0 )
cube_tiles/front = Vector2( 0, 0 )
[sub_resource type="VoxelLibrary" id=6]
voxels/0 = SubResource( 4 )
voxels/1 = SubResource( 5 )
[sub_resource type="SphereMesh" id=7]
[node name="Node" type="Node"]
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource( 2 )
[node name="DirectionalLight" type="DirectionalLight" parent="."]
transform = Transform( 0.912457, -0.352848, 0.207171, 0, 0.506317, 0.862348, -0.409172, -0.786855, 0.461992, 14.4885, 6.21497, 0 )
shadow_enabled = true
shadow_bias = 0.05
[node name="Axes" parent="." instance=ExtResource( 5 )]
[node name="SpectatorAvatar" parent="." instance=ExtResource( 4 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 19.9349, 17.285 )
speed = 20.0
[node name="Camera" parent="SpectatorAvatar" index="0"]
far = 800.0
[node name="Interaction" type="Node" parent="SpectatorAvatar"]
script = ExtResource( 1 )
[node name="VoxelTerrain" type="VoxelTerrain" parent="."]
provider = SubResource( 3 )
voxel_library = SubResource( 6 )
view_distance = 256
viewer_path = NodePath("../SpectatorAvatar")
smooth_meshing_enabled = true
material/0 = ExtResource( 2 )
[node name="MeshInstance" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.0254497 )
mesh = SubResource( 7 )
material/0 = ExtResource( 2 )
[editable path="SpectatorAvatar"]