Godot - Shader で丸を作る

初めて Shader を試した。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
// Godot 4.1

#define diagonal(X, Y) pow(X, 2) + pow(Y, 2)

shader_type canvas_item;

uniform vec2 center = vec2(0.5, 0.5);
uniform float r = 0.5;
uniform vec4 color : source_color = vec4(1.0, 1.0, 1.0, 1.0);

void fragment(){
    COLOR = texture(TEXTURE, UV);
    if(diagonal(abs(center.x - UV.x), abs(center.y - UV.y)) < pow(r, 2)) COLOR = color;
    else COLOR.a = 0.0;
}
Hugo で構築されています。
テーマ StackJimmy によって設計されています。