上篇筆記《Godot Shader特效:3D描邊(outline)效果 原理篇》介紹了Godot實(shí)現(xiàn)3D描邊的原理示罗,該文中是用Godot自帶的SpatialShader通過(guò)調(diào)整參數(shù)實(shí)現(xiàn)的蝙斜,由于這個(gè)效果在3D游戲中還是很常用的,所以干脆自己寫(xiě)了一個(gè)專(zhuān)用Shader,非常簡(jiǎn)單鲤嫡。把它添加到材質(zhì)上并作為一個(gè)Next Pass,就可以實(shí)現(xiàn)描邊了。
shader_type spatial;
render_mode cull_front,unshaded;
uniform vec4 color : hint_color = vec4(1.0,0.0,0.0,1.0);
uniform float grow = 0.05;
void vertex() {
VERTEX+=NORMAL*grow;
}
void fragment() {
ALBEDO = color.rgb;
}
效果圖
自定義Shader實(shí)現(xiàn)3D描邊效果