受击形变shader

master
chendian 2 years ago
parent a363d83355
commit 7b0b8335a0

@ -4,7 +4,23 @@ render_mode depth_prepass_alpha,unshaded;
uniform sampler2D tex : source_color,filter_nearest;
uniform float flash_white;
uniform vec2 deformation_dir = vec2(1, 0);
uniform float deformation_rate = 0;
void vertex() {
if (length(deformation_dir)>0.0){
vec2 dir_center = VERTEX.xy;
vec2 dir = normalize(deformation_dir.yx);
vec2 dir1 = dir * deformation_rate;
vec2 dir2 = cross(vec3(0, 0, 1), vec3(dir, 0)).xy * deformation_rate;
vec2 offset1 = -dot(dir1, dir_center) * dir1;
vec2 offset2 = dot(dir2, dir_center) * dir2;
VERTEX.xy += offset1 + offset2;
}
}
void fragment() {
vec4 col = texture(tex, UV);
if(col.a<0.5){discard;}
if(flash_white>0.0){

@ -6,7 +6,7 @@
[ext_resource type="Script" path="res://script/character/move.gd" id="4_66r53"]
[ext_resource type="Texture2D" uid="uid://daqn6aqfp1hva" path="res://resource/animation/character/hero01_long_attack.png" id="4_fcd8a"]
[ext_resource type="Script" path="res://script/character/view.gd" id="4_vijjv"]
[ext_resource type="SpriteFrames" uid="uid://dhfqj1dxldqao" path="res://resource/animation/character/hero01_long_skill01.aseprite" id="5_7jbf8"]
[ext_resource type="SpriteFrames" uid="uid://ce83cuqwgwwi4" path="res://resource/animation/character/hero01_long_attack.aseprite" id="5_m25rr"]
[ext_resource type="Script" path="res://script/character/skill.gd" id="6_h4xqy"]
[ext_resource type="AnimationLibrary" uid="uid://croik07a1qko5" path="res://resource/skill_animation_library/animation_library.tres" id="6_pakq5"]
[ext_resource type="Script" path="res://script/character/battle.gd" id="8_w84sf"]
@ -19,6 +19,8 @@
render_priority = 0
shader = ExtResource("3_ed424")
shader_parameter/flash_white = null
shader_parameter/deformation_dir = Vector2(0, 0)
shader_parameter/deformation_rate = 0.0
shader_parameter/tex = ExtResource("4_fcd8a")
[node name="Character" type="CharacterBody3D"]
@ -43,8 +45,8 @@ gi_mode = 0
double_sided = false
alpha_cut = 2
texture_filter = 0
sprite_frames = ExtResource("5_7jbf8")
animation = &"long_flash"
sprite_frames = ExtResource("5_m25rr")
animation = &"long_attack01"
script = ExtResource("4_vijjv")
[node name="Move" type="Node3D" parent="."]

@ -70,6 +70,9 @@ func settle(hit_info:HitInfo):
#闪白
character_to.add_buff("flash_white",0.1)
#形变
character_to.add_buff("deformation",0.1)
#卡帧
character_from.add_buff("pause",0.1)
character_to.add_buff("pause",0.1)

@ -73,10 +73,19 @@ func on_end_stagger(rate):status.is_stagger = false
func on_end_stun(rate):status.is_stun = false
#表现
func on_second_pause(rate):status.is_pause = true
func on_end_pause(rate):status.is_pause = false
func on_start_flash_white(rate):status.flash_white_rate = 1
func on_update_flash_white(rate):status.flash_white_rate = 1 - rate
func on_end_flash_white(rate):status.flash_white_rate = 0
func on_second_pause(rate):status.is_pause = true
func on_end_pause(rate):status.is_pause = false
func on_update_shake_x(rate):status.shake_offset = Vector3((sin(rate * PI * 4) - 0.5)*0.02,0,0);
func on_end_shake_x(rate):status.shake_offset = Vector3.ZERO
func on_start_deformation(rate):
status.deformation_dir=Vector2(status.hit_back_speed,status.hit_up_speed)
status.deformation_rate = 1;
func on_update_deformation(rate):status.deformation_rate = 1 - rate
func on_end_deformation(rate):status.deformation_rate = 0

@ -20,6 +20,8 @@ class_name Status
@export var shake_offset : Vector3 #抖动偏移值
@export var is_pause : bool #是否暂停
@export var flash_white_rate : float #闪白比例
@export var deformation_dir : Vector2 #形变方向
@export var deformation_rate : float #形变比例
@export_category("移动状态")
@export var move_dir : Vector2 #移动方向

@ -65,8 +65,7 @@ func _process(delta):
if status.is_pause:return
update_flip()
update_trans(false)
update_texture()
update_flash_white()
update_material()
func init(default:SpriteFrames):
sprite_frames = default
@ -130,14 +129,13 @@ func update_view():
func _on_animation_finished():
update_trans(true)
func update_texture():
func update_material():
var tex = sprite_frames.get_frame_texture(animation,frame)
var material = material_override as ShaderMaterial
material.set_shader_parameter("tex",tex)
func update_flash_white():
var material = material_override as ShaderMaterial
material.set_shader_parameter("flash_white",status.flash_white_rate)
material.set_shader_parameter("deformation_dir",status.deformation_dir)
material.set_shader_parameter("deformation_rate",status.deformation_rate*0.4)
func clone(target:AnimatedSprite3D):
target.sprite_frames = sprite_frames

Loading…
Cancel
Save