Meddle with ground squish amounts

This commit is contained in:
Spencer Killen 2022-12-29 14:09:36 -07:00
parent a1412c198e
commit 7f43cd00b3
Signed by: sjkillen
GPG Key ID: F307025B65C860BA
4 changed files with 50 additions and 13 deletions

Binary file not shown.

View File

@ -0,0 +1,30 @@
[gd_scene load_steps=5 format=2]
[sub_resource type="Shader" id=1]
code = "shader_type canvas_item;
uniform sampler2D curve;
void fragment() {
COLOR.rgb = vec3(0.0, 0.0, 0.0);
COLOR.r = texture(curve, vec2(SCREEN_UV.x, 0.0)).r;
}"
[sub_resource type="Curve" id=3]
_data = [ Vector2( 0, 0 ), 0.0, 0.0, 0, 0, Vector2( 1, 1 ), 0.0, 0.0, 0, 0 ]
[sub_resource type="CurveTexture" id=4]
curve = SubResource( 3 )
[sub_resource type="ShaderMaterial" id=2]
shader = SubResource( 1 )
shader_param/curve = SubResource( 4 )
[node name="Node2D" type="Node2D"]
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="ColorRect" type="ColorRect" parent="CanvasLayer"]
material = SubResource( 2 )
anchor_right = 1.0
anchor_bottom = 1.0

View File

@ -1,6 +1,4 @@
extends MeshInstance
onready var player = $"/root".find_node("Player", true, false)
func _process(_delta):
get_active_material(0).set_shader_param("player_pos", player.camera_position())
get_active_material(0).set_shader_param("player_pos", Util.player.camera_position())

View File

@ -1,4 +1,4 @@
[gd_resource type="ShaderMaterial" load_steps=3 format=2]
[gd_resource type="ShaderMaterial" load_steps=5 format=2]
[ext_resource path="res://tests/ground_squish/stringy_meat.jpg" type="Texture" id=1]
@ -6,6 +6,7 @@
code = "// NOTE: Shader automatically converted from Godot Engine 3.5.1.stable.mono's SpatialMaterial.
shader_type spatial;
// Needs world_vertex_coords
render_mode world_vertex_coords,async_visible,blend_mix,depth_draw_opaque,cull_disabled,diffuse_burley,specular_schlick_ggx;
uniform vec4 albedo : hint_color;
uniform sampler2D texture_albedo : hint_albedo;
@ -19,16 +20,15 @@ uniform vec3 uv2_scale;
uniform vec3 uv2_offset;
uniform vec3 player_pos;
const float MAX_DISTANCE = 2.5;
const float MAX_SINK = .3;
uniform sampler2D curve;
uniform float sink_factor : hint_range(1.0, 10.0, 0.1);
uniform float end_distance : hint_range(1.0, 30.0, 0.1);
void vertex() {
UV=UV*uv1_scale.xy+uv1_offset.xy;
float d = clamp(distance(VERTEX.xz, player_pos.xz), 0.0, MAX_DISTANCE) / MAX_DISTANCE;
d = smoothstep(0.0, 1.0, d);
float decrease = mix(MAX_SINK, 0.0, d);
float y_dist = mix(0.0, MAX_SINK, clamp(player_pos.y - VERTEX.y, 0.0, MAX_SINK)/MAX_SINK);
VERTEX.y -= decrease + y_dist;
float w = clamp(distance(player_pos.xz, VERTEX.xz), 0.0, end_distance) / end_distance;
float amount = texture(curve, vec2(w, 0.0)).r;
VERTEX.y -= (1.0-w) * sink_factor;
}
@ -43,6 +43,12 @@ void fragment() {
}
"
[sub_resource type="Curve" id=5]
_data = [ Vector2( 0, 0 ), 0.0, -0.454261, 0, 0, Vector2( 0.292308, 0.525 ), 2.53247, 2.53247, 0, 0, Vector2( 1, 1 ), -0.454844, 0.0, 0, 0 ]
[sub_resource type="CurveTexture" id=6]
curve = SubResource( 5 )
[resource]
resource_name = "TestMeat"
shader = SubResource( 4 )
@ -56,4 +62,7 @@ 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/player_pos = null
shader_param/sink_factor = 1.8
shader_param/end_distance = 5.2
shader_param/texture_albedo = ExtResource( 1 )
shader_param/curve = SubResource( 6 )