您当前的位置: 首页 > 

Godot特效:刀光(三)着色器及代码部分 方法一

发布时间:2019-12-15 15:46:30 ,浏览量:5

网上很多Unity版的刀光效果教程,都是基于粒子系统实现的,我这个Godot版使用Shader结合Tween实现的

节点结构

在这里插入图片描述

着色器
shader_type spatial; render_mode unshaded,cull_disabled; uniform float offset = 0.0; uniform sampler2D tex : hint_albedo; void vertex(){ UV += vec2(offset,0); } void fragment(){ vec4 c = texture(tex,UV).rgba; ALBEDO = c.rgb; ALPHA = c.a; } 
Player代码

Player就是模拟一个角色

extends Spatial

onready var vfx_slash = $"vfx_slash" func _input(e): if e is InputEventKey and e.pressed and not e.echo: match e.scancode: KEY_1: vfx_slash.play() 
vfx_mesh代码
extends MeshInstance #var material:Material onready var tween : Tween
var percent : float = 0.0 export var duration :float = 0.3 func _ready(): tween = Tween.new() add_child(tween) hide() func play(): show() tween.interpolate_property(self,"percent",0.0,0.5,duration,Tween.TRANS_LINEAR,Tween.EASE_IN) tween.connect("tween_all_completed",self,"tween_all_completed") tween.start() func _process(delta): get_surface_material(0).set_shader_param("offset",percent) func tween_all_completed(): hide() 
最终效果

在这里插入图片描述

关注
打赏
1688896170
查看更多评论

暂无认证

  • 5浏览

    0关注

    115984博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0506s