2 Commits 8ee759fe9f ... 423d75416a

Author SHA1 Message Date
  sl@cccfr.de 423d75416a add ground material 2 years ago
  sl@cccfr.de bad9754765 smooth rotation 2 years ago
8 changed files with 282 additions and 8 deletions
  1. 22 3
      Main.tscn
  2. 3 2
      Player.gd
  3. 4 3
      Tile.gd
  4. 29 0
      materials/ground_mat.tres
  5. 12 0
      materials/particle_mat.tres
  6. 26 0
      materials/rock_mat.tres
  7. 119 0
      shader/ground_shader.tres
  8. 67 0
      shader/particle_shader.tres

+ 22 - 3
Main.tscn

@@ -1,9 +1,10 @@
-[gd_scene load_steps=11 format=2]
+[gd_scene load_steps=13 format=2]
 
 
 [ext_resource path="res://Main.gd" type="Script" id=1]
 [ext_resource path="res://Main.gd" type="Script" id=1]
 [ext_resource path="res://Player.gd" type="Script" id=2]
 [ext_resource path="res://Player.gd" type="Script" id=2]
 [ext_resource path="res://ChunkSystem.gd" type="Script" id=3]
 [ext_resource path="res://ChunkSystem.gd" type="Script" id=3]
 [ext_resource path="res://tex/eso.jpg" type="Texture" id=4]
 [ext_resource path="res://tex/eso.jpg" type="Texture" id=4]
+[ext_resource path="res://shader/ground_shader.tres" type="Material" id=5]
 
 
 [sub_resource type="PanoramaSky" id=9]
 [sub_resource type="PanoramaSky" id=9]
 panorama = ExtResource( 4 )
 panorama = ExtResource( 4 )
@@ -11,7 +12,9 @@ panorama = ExtResource( 4 )
 [sub_resource type="Environment" id=10]
 [sub_resource type="Environment" id=10]
 background_mode = 2
 background_mode = 2
 background_sky = SubResource( 9 )
 background_sky = SubResource( 9 )
+background_energy = 4.61
 ambient_light_color = Color( 1, 1, 1, 1 )
 ambient_light_color = Color( 1, 1, 1, 1 )
+tonemap_mode = 3
 glow_enabled = true
 glow_enabled = true
 
 
 [sub_resource type="CapsuleShape" id=8]
 [sub_resource type="CapsuleShape" id=8]
@@ -20,12 +23,19 @@ glow_enabled = true
 
 
 [sub_resource type="SpatialMaterial" id=6]
 [sub_resource type="SpatialMaterial" id=6]
 albedo_color = Color( 0.168627, 0.164706, 0.913725, 1 )
 albedo_color = Color( 0.168627, 0.164706, 0.913725, 1 )
+detail_enabled = true
+detail_blend_mode = 0
+detail_uv_layer = 0
 
 
 [sub_resource type="SphereMesh" id=5]
 [sub_resource type="SphereMesh" id=5]
 material = SubResource( 6 )
 material = SubResource( 6 )
 radius = 7.0
 radius = 7.0
 height = 14.0
 height = 14.0
 
 
+[sub_resource type="PlaneMesh" id=11]
+material = ExtResource( 5 )
+size = Vector2( 20, 20 )
+
 [node name="root" type="Spatial"]
 [node name="root" type="Spatial"]
 script = ExtResource( 1 )
 script = ExtResource( 1 )
 __meta__ = {
 __meta__ = {
@@ -35,11 +45,15 @@ __meta__ = {
 [node name="WorldEnvironment" type="WorldEnvironment" parent="."]
 [node name="WorldEnvironment" type="WorldEnvironment" parent="."]
 environment = SubResource( 10 )
 environment = SubResource( 10 )
 
 
+[node name="DirectionalLight" type="DirectionalLight" parent="WorldEnvironment"]
+transform = Transform( 1, 0, 0, 0, 0.81189, 0.583811, 0, -0.583811, 0.81189, 14.964, 0, 0 )
+visible = false
+
 [node name="Player" type="KinematicBody" parent="."]
 [node name="Player" type="KinematicBody" parent="."]
 script = ExtResource( 2 )
 script = ExtResource( 2 )
 
 
 [node name="Camera" type="Camera" parent="Player"]
 [node name="Camera" type="Camera" parent="Player"]
-transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.67414, 0 )
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.67414, -1.02577 )
 far = 50000.0
 far = 50000.0
 
 
 [node name="CollisionShape" type="CollisionShape" parent="Player"]
 [node name="CollisionShape" type="CollisionShape" parent="Player"]
@@ -58,7 +72,7 @@ material/0 = null
 
 
 [node name="SpotLight" type="SpotLight" parent="Player/MeshInstance"]
 [node name="SpotLight" type="SpotLight" parent="Player/MeshInstance"]
 transform = Transform( 1, 0, 0, 0, 0.573905, -0.818922, 0, 0.818922, 0.573905, -0.00356923, 0.433873, 1.27676 )
 transform = Transform( 1, 0, 0, 0, 0.573905, -0.818922, 0, 0.818922, 0.573905, -0.00356923, 0.433873, 1.27676 )
-light_energy = 7.3
+light_color = Color( 0.552941, 0.482353, 0.298039, 1 )
 spot_range = 179.547
 spot_range = 179.547
 spot_angle = 33.3247
 spot_angle = 33.3247
 
 
@@ -115,3 +129,8 @@ text = "4"
 visible = false
 visible = false
 mesh = SubResource( 5 )
 mesh = SubResource( 5 )
 material/0 = null
 material/0 = null
+
+[node name="plane" type="MeshInstance" parent="."]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 2.98035, 2.37647, 0.319568 )
+mesh = SubResource( 11 )
+material/0 = null

+ 3 - 2
Player.gd

@@ -69,6 +69,7 @@ func _physics_process(delta):
 	up = global_transform.origin.normalized()
 	up = global_transform.origin.normalized()
 	right = forward.cross(up).normalized()
 	right = forward.cross(up).normalized()
 	forward = up.cross(right).normalized()
 	forward = up.cross(right).normalized()
+	transform.basis = Basis(right, up, -forward)
 	
 	
 	if can_move and (is_on_floor() or allow_fall_input):
 	if can_move and (is_on_floor() or allow_fall_input):
 		
 		
@@ -108,10 +109,10 @@ func _physics_process(delta):
 
 
 	velocity = velocity.linear_interpolate(dir * (move_speed_sprint if move_sprint else move_speed), move_acceleration * delta)
 	velocity = velocity.linear_interpolate(dir * (move_speed_sprint if move_sprint else move_speed), move_acceleration * delta)
 	if !is_on_floor():
 	if !is_on_floor():
-		velocity += -up * gravaty * delta
+		velocity -= up * gravaty
 	velocity = move_and_slide(velocity, up)
 	velocity = move_and_slide(velocity, up)
 	
 	
-	transform = transform.looking_at(transform.origin + forward, up)
+	
 	
 	
 	
 	
 	#Smooth movement
 	#Smooth movement

+ 4 - 3
Tile.gd

@@ -3,7 +3,8 @@ extends MeshInstance
 var Point = preload("res://point.tscn")
 var Point = preload("res://point.tscn")
 var TopoLoader = preload("res://TopoLoader.gd")
 var TopoLoader = preload("res://TopoLoader.gd")
 var TextureLoader = preload("res://TextureLoader.gd")
 var TextureLoader = preload("res://TextureLoader.gd")
-#var grid = load("res://tex/grid.png")
+
+var groundShader = preload("res://shader/ground_shader.tres") as ShaderMaterial
 
 
 var latMin:float = 0
 var latMin:float = 0
 var latMax:float = 1
 var latMax:float = 1
@@ -46,10 +47,10 @@ func genMesh():
 	arr[Mesh.ARRAY_INDEX] = genIndex()
 	arr[Mesh.ARRAY_INDEX] = genIndex()
 	mesh = Mesh.new()
 	mesh = Mesh.new()
 	mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arr)
 	mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arr)
-	var mat = SpatialMaterial.new()
+	var mat = groundShader.duplicate()
 	#mat.albedo_color = Color(0.7,0.7,0.7,1)
 	#mat.albedo_color = Color(0.7,0.7,0.7,1)
 	var texl = TextureLoader.new()
 	var texl = TextureLoader.new()
-	mat.albedo_texture = texl.loadTexture(latMin, lonMin)
+	mat.set_shader_param("texture_albedo_big", texl.loadTexture(latMin, lonMin))
 	mesh.surface_set_material(0,mat)
 	mesh.surface_set_material(0,mat)
 	.create_trimesh_collision()
 	.create_trimesh_collision()
 	
 	

+ 29 - 0
materials/ground_mat.tres

@@ -0,0 +1,29 @@
+[gd_resource type="SpatialMaterial" load_steps=7 format=2]
+
+[ext_resource path="res://tex/ground/gravel_path_Height.png" type="Texture" id=1]
+[ext_resource path="res://tex/ground/gravel_path_Roughness.png" type="Texture" id=2]
+[ext_resource path="res://tex/ground/gravel_path-albedo.png" type="Texture" id=3]
+[ext_resource path="res://tex/ground/gravel_path-ao.png" type="Texture" id=4]
+[ext_resource path="res://tex/ground/gravel_path_Metallic.png" type="Texture" id=5]
+[ext_resource path="res://tex/ground/gravel_path_Normal-dx.png" type="Texture" id=6]
+
+[resource]
+albedo_texture = ExtResource( 3 )
+metallic_texture = ExtResource( 5 )
+roughness_texture = ExtResource( 2 )
+normal_enabled = true
+normal_scale = 1.0
+normal_texture = ExtResource( 6 )
+ao_enabled = true
+ao_light_affect = 0.0
+ao_texture = ExtResource( 4 )
+ao_on_uv2 = false
+ao_texture_channel = 0
+depth_enabled = true
+depth_scale = 0.05
+depth_deep_parallax = true
+depth_min_layers = 8
+depth_max_layers = 32
+depth_flip_tangent = false
+depth_flip_binormal = false
+depth_texture = ExtResource( 1 )

+ 12 - 0
materials/particle_mat.tres

@@ -0,0 +1,12 @@
+[gd_resource type="ShaderMaterial" load_steps=4 format=2]
+
+[ext_resource path="res://particle_shader.tres" type="Shader" id=1]
+[ext_resource path="res://noise_texture.png" type="Texture" id=2]
+[ext_resource path="res://marble/Marble016_2K_Displacement.jpg" type="Texture" id=3]
+
+[resource]
+shader = ExtResource( 1 )
+shader_param/rows = 4.0
+shader_param/spacing = 5.0
+shader_param/heightmap = ExtResource( 3 )
+shader_param/noisemap = ExtResource( 2 )

+ 26 - 0
materials/rock_mat.tres

@@ -0,0 +1,26 @@
+[gd_resource type="SpatialMaterial" load_steps=5 format=2]
+
+[ext_resource path="res://lunar-rock/lunar_rock2_albedo.png" type="Texture" id=1]
+[ext_resource path="res://lunar-rock/lunar_rock2_ao.png" type="Texture" id=2]
+[ext_resource path="res://lunar-rock/lunar_rock2_Height.png" type="Texture" id=3]
+[ext_resource path="res://lunar-rock/lunar_rock2_Normal-ogl.png" type="Texture" id=4]
+
+[resource]
+albedo_color = Color( 0.643137, 0.643137, 0.643137, 1 )
+albedo_texture = ExtResource( 1 )
+normal_enabled = true
+normal_scale = 1.0
+normal_texture = ExtResource( 4 )
+ao_enabled = true
+ao_light_affect = 0.0
+ao_texture = ExtResource( 2 )
+ao_on_uv2 = false
+ao_texture_channel = 4
+depth_enabled = true
+depth_scale = 0.05
+depth_deep_parallax = true
+depth_min_layers = 8
+depth_max_layers = 32
+depth_flip_tangent = false
+depth_flip_binormal = true
+depth_texture = ExtResource( 3 )

+ 119 - 0
shader/ground_shader.tres

@@ -0,0 +1,119 @@
+[gd_resource type="ShaderMaterial" load_steps=9 format=2]
+
+[ext_resource path="res://tex/ground/gravel_path_Height.png" type="Texture" id=1]
+[ext_resource path="res://tex/ground/gravel_path-ao.png" type="Texture" id=2]
+[ext_resource path="res://tex/ground/gravel_path_Metallic.png" type="Texture" id=3]
+[ext_resource path="res://tex/ground/gravel_path_Roughness.png" type="Texture" id=4]
+[ext_resource path="res://tex/ground/gravel_path_Normal-dx.png" type="Texture" id=5]
+[ext_resource path="res://tex/ground/gravel_path-albedo.png" type="Texture" id=6]
+[ext_resource path="res://tex/180-91.png" type="Texture" id=7]
+
+[sub_resource type="Shader" id=1]
+code = "// NOTE: Shader automatically converted from Godot Engine 3.4.4.stable's SpatialMaterial.
+
+shader_type spatial;
+render_mode blend_mix,depth_draw_opaque,cull_back,diffuse_burley,specular_schlick_ggx;
+uniform vec4 albedo : hint_color;
+uniform sampler2D texture_albedo_big;
+uniform sampler2D texture_albedo : hint_albedo;
+uniform float specular;
+uniform float metallic;
+uniform float roughness : hint_range(0,1);
+uniform float point_size : hint_range(0,128);
+uniform sampler2D texture_metallic : hint_white;
+uniform vec4 metallic_texture_channel;
+uniform sampler2D texture_roughness : hint_white;
+uniform vec4 roughness_texture_channel;
+uniform sampler2D texture_normal : hint_normal;
+uniform float normal_scale : hint_range(-16,16);
+uniform sampler2D texture_ambient_occlusion : hint_white;
+uniform vec4 ao_texture_channel;
+uniform float ao_light_affect;
+uniform sampler2D texture_depth : hint_black;
+uniform float depth_scale;
+uniform int depth_min_layers;
+uniform int depth_max_layers;
+uniform vec2 depth_flip;
+uniform vec3 uv1_scale;
+uniform vec3 uv1_offset;
+uniform vec3 uv2_scale;
+uniform vec3 uv2_offset;
+
+
+void vertex() {
+	UV=UV*uv1_scale.xy+uv1_offset.xy;
+}
+
+
+
+
+void fragment() {
+	vec2 base_uv = UV;
+	/*
+	{
+		vec3 view_dir = normalize(normalize(-VERTEX)*mat3(TANGENT*depth_flip.x,-BINORMAL*depth_flip.y,NORMAL));
+		float num_layers = mix(float(depth_max_layers),float(depth_min_layers), abs(dot(vec3(0.0, 0.0, 1.0), view_dir)));
+		float layer_depth = 1.0 / num_layers;
+		float current_layer_depth = 0.0;
+		vec2 P = view_dir.xy * depth_scale;
+		vec2 delta = P / num_layers;
+		vec2 ofs = base_uv;
+		float depth = textureLod(texture_depth, ofs, 0.0).r;
+		float current_depth = 0.0;
+		while(current_depth < depth) {
+			ofs -= delta;
+			depth = textureLod(texture_depth, ofs, 0.0).r;
+			current_depth += layer_depth;
+		}
+		vec2 prev_ofs = ofs + delta;
+		float after_depth  = depth - current_depth;
+		float before_depth = textureLod(texture_depth, prev_ofs, 0.0).r - current_depth + layer_depth;
+		float weight = after_depth / (after_depth - before_depth);
+		ofs = mix(ofs,prev_ofs,weight);
+		//base_uv=ofs;
+	}*/
+	
+	vec2 scaled_uv = base_uv*vec2(512,512);
+	vec4 albedo_tex = texture(texture_albedo,scaled_uv);
+	vec4 albedo_tex_big = texture(texture_albedo_big,base_uv);
+	ALBEDO = albedo.rgb * (albedo_tex.rgb + albedo_tex_big.rgb);
+	
+	float metallic_tex = dot(texture(texture_metallic,scaled_uv),metallic_texture_channel);
+	METALLIC = metallic_tex * metallic;
+	float roughness_tex = dot(texture(texture_roughness,scaled_uv),roughness_texture_channel);
+	ROUGHNESS = roughness_tex * roughness;
+	SPECULAR = specular;
+	NORMALMAP = texture(texture_normal,scaled_uv).rgb;
+	NORMALMAP_DEPTH = normal_scale;
+	AO = dot(texture(texture_ambient_occlusion,scaled_uv),ao_texture_channel);
+	AO_LIGHT_AFFECT = ao_light_affect;
+}
+"
+
+[resource]
+shader = SubResource( 1 )
+shader_param/albedo = Color( 1, 1, 1, 1 )
+shader_param/specular = 0.5
+shader_param/metallic = 0.0
+shader_param/roughness = 1.0
+shader_param/point_size = 1.0
+shader_param/metallic_texture_channel = Plane( 1, 0, 0, 0 )
+shader_param/roughness_texture_channel = Plane( 1, 0, 0, 0 )
+shader_param/normal_scale = 1.0
+shader_param/ao_texture_channel = Plane( 1, 0, 0, 0 )
+shader_param/ao_light_affect = 0.0
+shader_param/depth_scale = 0.05
+shader_param/depth_min_layers = 8
+shader_param/depth_max_layers = 32
+shader_param/depth_flip = Vector2( 1, 1 )
+shader_param/uv1_scale = Vector3( 1, 1, 1 )
+shader_param/uv1_offset = Vector3( 0, 0, 0 )
+shader_param/uv2_scale = Vector3( 1, 1, 1 )
+shader_param/uv2_offset = Vector3( 0, 0, 0 )
+shader_param/texture_albedo_big = ExtResource( 7 )
+shader_param/texture_albedo = ExtResource( 6 )
+shader_param/texture_metallic = ExtResource( 3 )
+shader_param/texture_roughness = ExtResource( 4 )
+shader_param/texture_normal = ExtResource( 5 )
+shader_param/texture_ambient_occlusion = ExtResource( 2 )
+shader_param/texture_depth = ExtResource( 1 )

+ 67 - 0
shader/particle_shader.tres

@@ -0,0 +1,67 @@
+[gd_resource type="Shader" format=2]
+
+[resource]
+code = "shader_type particles;
+
+uniform float rows = 16;
+uniform float spacing = 1.0;
+
+uniform sampler2D heightmap;
+//uniform float amplitude = 15.0;
+//uniform vec2 heightmap_size = vec2(300.0, 300.0);
+
+uniform sampler2D noisemap;
+
+//float get_height(vec2 pos) {
+//	pos -= 0.5 * heightmap_size;
+//	pos /= heightmap_size;
+	
+//	return amplitude * texture(heightmap, pos).r;
+//}
+
+void vertex() {
+	// obtain our position based on which particle we're rendering
+	vec3 pos = vec3(0.0, 0.0, 0.0);
+	pos.z = float(INDEX);
+	pos.x = mod(pos.z, rows);
+	pos.z = (pos.z - pos.x) / rows;
+	
+	// center this
+	pos.x -= rows * 0.5;
+	pos.z -= rows * 0.5;
+	
+	// and now apply our spacing
+	pos *= spacing;
+	
+	// now center on our particle location but within our spacing
+	//pos.x += EMISSION_TRANSFORM[3][0] - mod(EMISSION_TRANSFORM[3][0], spacing);
+	//pos.z += EMISSION_TRANSFORM[3][2] - mod(EMISSION_TRANSFORM[3][2], spacing);
+	
+	// now add some noise based on our _world_ position
+	vec3 noise = texture(noisemap, pos.xz * 0.001).rgb;
+	pos.x += noise.x * spacing;
+	pos.z += noise.y * spacing;
+	
+	// apply our height
+	pos.y = 1.0;//get_height(pos.xz);
+	
+	float y2 = 1.0;//get_height(pos.xz + vec2(1.0, 0.0));
+	float y3 = 1.0;//get_height(pos.xz + vec2(0.0, 1.0));
+	
+	if (abs(y2 - pos.y) > 0.5) {
+		pos.y = -10000.0;
+	} else if (abs(y3 - pos.y) > 0.5) {
+		pos.y = -10000.0;
+	}
+	
+	// rotate our transform
+	TRANSFORM[0][0] = cos(noise.z * 3.0);
+	TRANSFORM[0][2] = -sin(noise.z * 3.0);
+	TRANSFORM[2][0] = sin(noise.z * 3.0);
+	TRANSFORM[2][2] = cos(noise.z * 3.0);
+	
+	// update our transform to place
+	TRANSFORM[3][0] = pos.x;
+	TRANSFORM[3][1] = pos.y;
+	TRANSFORM[3][2] = pos.z;
+}"