diff --git a/project.godot b/project.godot index 15d33c5..3ec1e5c 100644 --- a/project.godot +++ b/project.godot @@ -9,7 +9,7 @@ config_version=4 _global_script_classes=[ { -"base": "CameraOutline", +"base": "Camera", "class": "CameraController", "language": "GDScript", "path": "res://utils/camera/CameraController.gd" diff --git a/utils/camera/CameraController.gd b/utils/camera/CameraController.gd index 27ac236..bd4007f 100644 --- a/utils/camera/CameraController.gd +++ b/utils/camera/CameraController.gd @@ -1,4 +1,4 @@ -extends CameraOutline +extends Camera class_name CameraController signal camera_moved(new_location) diff --git a/world/default_env.tres b/world/default_env.tres index 20207a4..5489f73 100644 --- a/world/default_env.tres +++ b/world/default_env.tres @@ -5,3 +5,5 @@ [resource] background_mode = 2 background_sky = SubResource( 1 ) +fog_color = Color( 1, 1, 1, 0.145098 ) +fog_depth_end = 328.6 diff --git a/world/game.tscn b/world/game.tscn index ead788d..2302bbc 100644 --- a/world/game.tscn +++ b/world/game.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=11 format=2] +[gd_scene load_steps=14 format=2] [ext_resource path="res://ui/ui.tscn" type="PackedScene" id=1] +[ext_resource path="res://world/materials/world2.material" type="Material" id=2] [ext_resource path="res://world/World3d.gd" type="Script" id=4] [ext_resource path="res://utils/camera/CamBase.tscn" type="PackedScene" id=5] @@ -130,6 +131,7 @@ seamless = true noise = SubResource( 6 ) [sub_resource type="ShaderMaterial" id=3] +render_priority = 1 shader = SubResource( 2 ) shader_param/speed = 0.003 shader_param/color = Color( 0.054902, 0.533333, 0.741176, 1 ) @@ -146,6 +148,11 @@ shader_param/time_factor = Vector2( 1, 2 ) shader_param/noise1 = SubResource( 5 ) shader_param/noise2 = SubResource( 7 ) +[sub_resource type="QuadMesh" id=8] +size = Vector2( 2, 2 ) + +[sub_resource type="CubeMesh" id=9] + [node name="Game" type="Node"] [node name="UI" parent="." instance=ExtResource( 1 )] @@ -181,6 +188,19 @@ transform = Transform( 0.971628, 0.168947, -0.16552, 0, 0.699825, 0.714314, 0.23 light_energy = 0.1 shadow_enabled = true +[node name="Spatial" type="Spatial" parent="World3d"] + +[node name="MeshInstance" type="MeshInstance" parent="World3d/Spatial"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 6.29265, 7.41201, 29.3021 ) +extra_cull_margin = 3653.19 +mesh = SubResource( 8 ) +skeleton = NodePath("../..") +material/0 = ExtResource( 2 ) + +[node name="MeshInstance" type="MeshInstance" parent="World3d"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 2.0515, 0.388711, 13.3283 ) +mesh = SubResource( 9 ) + [connection signal="map_clicked" from="UI/Map" to="World3d/CamBase/Camera" method="_on_Map_map_clicked"] [connection signal="camera_moved" from="World3d/CamBase/Camera" to="UI/Map/Cursor" method="_on_Camera_camera_moved"] diff --git a/world/materials/outilne_1.tres b/world/materials/outilne_1.tres new file mode 100644 index 0000000..4c29fb3 --- /dev/null +++ b/world/materials/outilne_1.tres @@ -0,0 +1,21 @@ +[gd_resource type="Shader" format=2] + +[resource] +code = "// Edge-Detection Shader Pass 1 +// Here we simply pass the vertex normals to the albedo +// so we can access it through the SCREEN_TEXTURE in our Shader Pass 2 +// LICENSE: MIT + +shader_type spatial; +render_mode blend_mix,depth_draw_opaque,cull_back,diffuse_toon,specular_disabled,shadows_disabled; + +varying vec3 world_normal; + +void vertex() { + world_normal = NORMAL; +} + +void fragment() { + ALBEDO = world_normal.rgb; +} +" diff --git a/world/materials/outilne_2.tres b/world/materials/outilne_2.tres new file mode 100644 index 0000000..a0ae7ef --- /dev/null +++ b/world/materials/outilne_2.tres @@ -0,0 +1,57 @@ +[gd_resource type="Shader" format=2] + +[resource] +code = "// Edge-Detection Shader Pass 2 +// Here's our fully lit and shaded model, +// but through the SCREEN_TEXTURE, we also have the world normals +// of all the visible parts of our model that the first pass gives us. +// LICENSE: MIT + +shader_type spatial; +render_mode blend_mix,depth_draw_alpha_prepass,cull_back,diffuse_lambert,specular_disabled; +uniform vec4 albedo : hint_color; +uniform sampler2D texture_albedo : hint_albedo; +uniform float specular; +uniform float metallic; +uniform float roughness : hint_range(0,1); +uniform float edge_strength : hint_range(0,1) = 0.2; +uniform vec4 edge_color : hint_color = vec4(0.5, 0.5, 0.5, 1.0); + +// essentially a cheap \"lightness\" function +// returns the average of red, green and blue color channels +float vec3_avg(vec3 color) { + return (color.r + color.g + color.b) / 3.0; +} + +// transform a pixel coordinate to screen UV +vec2 pixel_to_screen_uv(vec2 viewport_size, vec2 pixel) { + return vec2(pixel.x / viewport_size.x, pixel.y / viewport_size.y); +} + +void fragment() { + vec4 albedo_tex = texture(texture_albedo, UV); + + vec2 iuv = vec2(SCREEN_UV.x * VIEWPORT_SIZE.x, SCREEN_UV.y * VIEWPORT_SIZE.y); + + vec3 neighbour_left = texture(SCREEN_TEXTURE, pixel_to_screen_uv(VIEWPORT_SIZE, iuv + vec2(0, 0))).rgb; + vec3 neighbour_right = texture(SCREEN_TEXTURE, pixel_to_screen_uv(VIEWPORT_SIZE, iuv + vec2(0.5, 0))).rgb; + + vec3 neighbour_top = texture(SCREEN_TEXTURE, pixel_to_screen_uv(VIEWPORT_SIZE, iuv + vec2(0, 0.0))).rgb; + vec3 neighbour_bottom = texture(SCREEN_TEXTURE, pixel_to_screen_uv(VIEWPORT_SIZE, iuv + vec2(0, 0.5))).rgb; + + ALBEDO = albedo.rgb * texture(texture_albedo, UV).rgb; + + // compare normals: if they differ, we draw an edge + // by mixing in the edge_color, by edge_strength amount + // feel free to try other ways to mix, such as multiply for more textured objects. + if (abs(vec3_avg(neighbour_left) - vec3_avg(neighbour_right)) > 0.0) { + ALBEDO = mix(ALBEDO, edge_color.rgb, edge_strength); + }else if (abs(vec3_avg(neighbour_top) - vec3_avg(neighbour_bottom)) > 0.0) { + ALBEDO = mix(ALBEDO, edge_color.rgb, edge_strength); + } + + METALLIC = metallic; + ROUGHNESS = roughness; + SPECULAR = specular; +} +" diff --git a/world/materials/test.tres b/world/materials/test.tres new file mode 100644 index 0000000..adf2fcd --- /dev/null +++ b/world/materials/test.tres @@ -0,0 +1,63 @@ +[gd_resource type="Shader" format=2] + +[resource] +code = "//THIS SHADER MUST BE APPLIED TO A QUAD (MeshInstance) WITH A SIZE OF (2, 2) +//Extra Cull Margin on the quad should be turned up all the way! + +shader_type spatial; +render_mode unshaded; + +uniform int outline_mode : hint_range(1, 3, 1) = 3; +uniform float outline_intensity : hint_range(0, 5) = 1; +uniform bool _round = false; +uniform float outline_bias : hint_range(-10, 10) = 0; + +uniform vec4 outline_color : hint_color = vec4(0.0, 0.0, 0.0, 1.0); + +void vertex() { + POSITION = vec4(VERTEX, 1.0); +} + +void fragment() { + ALBEDO = outline_color.rgb; + + vec2 screen_size = vec2(textureSize(SCREEN_TEXTURE, 1)); + + float px = 0.5/screen_size.x; + float py = 0.5/screen_size.y; + + float d = texture(DEPTH_TEXTURE, SCREEN_UV).x; + float du = texture(DEPTH_TEXTURE, SCREEN_UV+vec2(0.0, py)).x; + float dd = texture(DEPTH_TEXTURE, SCREEN_UV+vec2(0.0, -py)).x; + float dr = texture(DEPTH_TEXTURE, SCREEN_UV+vec2(px, 0.0)).x; + float dl = texture(DEPTH_TEXTURE, SCREEN_UV+vec2(-px, 0.0)).x; + + if (outline_mode == 1){ + ALPHA = 0.0 + abs(abs(d)-abs(du)) + abs(abs(d)-abs(dd)) + abs(abs(d)-abs(dl)) + abs(abs(d)-abs(dr)); + + ALPHA *= 1000.0*outline_intensity; + } else if (outline_mode == 2) { + ALPHA = 0.0 + abs(abs(abs(d)-abs(du)) - abs(abs(d)-abs(dd))) + abs(abs(abs(d)-abs(dl)) - abs(abs(d)-abs(dr))); + + ALPHA *= 3.0*50000.0*outline_intensity; + } else if (outline_mode == 3) { + float dq = texture(DEPTH_TEXTURE, SCREEN_UV+vec2(-px, py)).x; + float de = texture(DEPTH_TEXTURE, SCREEN_UV+vec2(px, py)).x; + float dz = texture(DEPTH_TEXTURE, SCREEN_UV+vec2(-px, -py)).x; + float dc = texture(DEPTH_TEXTURE, SCREEN_UV+vec2(px, -py)).x; + + ALPHA = 0.0 + abs(abs(abs(d)-abs(du)) - abs(abs(d)-abs(dd))) + abs(abs(abs(d)-abs(dl)) - abs(abs(d)-abs(dr))) + abs(abs(abs(d)-abs(dq)) - abs(abs(d)-abs(dc))) + abs(abs(abs(d)-abs(dz)) - abs(abs(d)-abs(de))); + + ALPHA *= 50000.0*outline_intensity; + } + + ALPHA += outline_bias; + + if (_round) { + ALPHA = round(ALPHA); + } + + ALPHA *= outline_color.a; +} + +//Written by Warren Jennings" diff --git a/world/materials/world2.material b/world/materials/world2.material new file mode 100644 index 0000000..65cd81f Binary files /dev/null and b/world/materials/world2.material differ