您当前的位置: 首页 > 

开发游戏的老王

暂无认证

  • 3浏览

    0关注

    803博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Godot Shader :在一个面片上让鼠标滑过的地方凸起

开发游戏的老王 发布时间:2019-12-24 21:46:41 ,浏览量:3

今天一个朋友问的Unity问题,我试着用 Godot的 Shader实现一下。用Unity实现的话,原理是相同的

效果展示

如果要凸起更圆润的话,增加面片的细分就可以,代码部分应该可以优化,坐标运算搞得自己头晕了

在这里插入图片描述

GDScript部分

extends Camera

const ray_length : int = 1000

func _input(event):
	if event is InputEventMouse:
		var from:Vector3 = project_ray_origin(event.position)
		var to:Vector3 = from + project_ray_normal(event.position) * ray_length
		var state:PhysicsDirectSpaceState = get_world().direct_space_state
		var result:Dictionary  = state.intersect_ray(from,to)
		if result:
			get_tree().call_group("M_LISTENER","on_Mouse_move",result.position)
extends MeshInstance

onready var size : float = get("mesh").size.x
onready var mat = get("material/0")

func _ready():
	add_to_group("M_LISTENER")

func on_Mouse_move(pos : Vector3):
	var p2 = Vector2(0,1) + Vector2(pos.y,pos.x) / size
	mat.set_shader_param("position",p2)

Shader部分

shader_type spatial;
render_mode cull_disabled;

uniform sampler2D  stamp : hint_albedo;
uniform vec2 position;
uniform float bob_scale = 1.0;
uniform vec4 color : hint_color;

varying vec2 vertex_position;

void vertex(){
	vertex_position = UV - position;
	VERTEX.y += texture(stamp,vertex_position).r*bob_scale;
}

void fragment(){
	ALBEDO = color.rgb;
	NORMALMAP = texture(stamp,vertex_position).rgb;
}

stamp贴图

在这里插入图片描述

关注
打赏
1656935939
查看更多评论
立即登录/注册

微信扫码登录

0.0425s