(摘) Godot收集到几个Shader

声明:内容源自网络,版权归原作者所有。若有侵权请在网页聊天中联系我

Shader是个神奇的存在,之前也有过收集,这次继续收集官方示例中的着色器.

outline.gdshader 黑色外部边线(第1排第2图效果)

shader_type canvas_item;

uniform float outline_width = 2.0;
uniform vec4 outline_color : source_color;

void fragment() {
	vec4 col = texture(TEXTURE, UV);
	vec2 ps = TEXTURE_PIXEL_SIZE;
	float a;
	float maxa = col.a;
	float mina = col.a;

	a = texture(TEXTURE, UV + vec2(0.0, -outline_width) * ps).a;
	maxa = max(a, maxa);
	mina = min(a, mina);

	a = texture(TEXTURE, UV + vec2(0.0, outline_width) * ps).a;
	maxa = max(a, maxa);
	mina = min(a, mina);

	a = texture(TEXTURE, UV + vec2(-outline_width, 0.0) * ps).a;
	maxa = max(a, maxa);
	mina = min(a, mina);

	a = texture(TEXTURE, UV + vec2(outline_width, 0.0) * ps).a;
	maxa = max(a, maxa);
	mina = min(a, mina);

	COLOR = mix(col, outline_color, maxa - mina);
}

aura.gdshader 外部光环(第1排第3个效果,类似上方效果)

shader_type canvas_item;
render_mode blend_premul_alpha;

// This shader only works properly with premultiplied alpha blend mode.
uniform float aura_width = 2.0;
uniform vec4 aura_color : source_color;

void fragment() {
	vec4 col = texture(TEXTURE, UV);
	vec2 ps = TEXTURE_PIXEL_SIZE;
	float a;
	float maxa = col.a;
	float mina = col.a;

	a = texture(TEXTURE, UV + vec2(0.0, -aura_width) * ps).a;
	maxa = max(a, maxa);
	mina = min(a, mina);

	a = texture(TEXTURE, UV + vec2(0.0, aura_width) * ps).a;
	maxa = max(a, maxa);
	mina = min(a, mina);

	a = texture(TEXTURE, UV + vec2(-aura_width, 0.0) * ps).a;
	maxa = max(a, maxa);
	mina = min(a, mina);

	a = texture(TEXTURE, UV + vec2(aura_width, 0.0) * ps).a;
	maxa = max(a, maxa);
	mina = min(a, mina);

	col.rgb *= col.a;

	COLOR = col;
	COLOR.rgb += aura_color.rgb * (maxa - mina);
}

模糊效果(第1排第4个)

shader_type canvas_item;
render_mode blend_mix;

uniform float radius = 4.0;

void fragment() {
	vec4 col = texture(TEXTURE, UV);
	vec2 ps = TEXTURE_PIXEL_SIZE;

	col += texture(TEXTURE, UV + vec2(0.0, -radius) * ps);
	col += texture(TEXTURE, UV + vec2(0.0, radius) * ps);
	col += texture(TEXTURE, UV + vec2(-radius, 0.0) * ps);
	col += texture(TEXTURE, UV + vec2(radius, 0.0) * ps);
	col /= 5.0;

	COLOR = col;
}

阴影效果(第2排第2个)

shader_type canvas_item;
render_mode blend_mix;

uniform vec2 offset = vec2(8.0, 8.0);
uniform vec4 modulate : source_color;

void fragment() {
	vec2 ps = TEXTURE_PIXEL_SIZE;

	vec4 shadow = vec4(modulate.rgb, texture(TEXTURE, UV - offset * ps).a * modulate.a);
	vec4 col = texture(TEXTURE, UV);

	COLOR = mix(shadow, col, col.a);
}

剪影效果(第2排第3个)

shader_type canvas_item;

render_mode blend_mix;
uniform vec4 modulate : source_color;

void fragment() {
	COLOR = vec4(modulate.rgb, texture(TEXTURE, UV).a * modulate.a);
}

辉光效果(第2排第4个)

shader_type canvas_item;
render_mode blend_premul_alpha;

uniform float radius = 5.0;
uniform float amount = 0.25;

void fragment() {
	float r = radius;
	vec2 ps = TEXTURE_PIXEL_SIZE;
	vec4 col = texture(TEXTURE, UV);
	vec4 glow = col;

	glow += texture(TEXTURE, UV + vec2(-r, -r) * ps);
	glow += texture(TEXTURE, UV + vec2(-r, 0.0) * ps);
	glow += texture(TEXTURE, UV + vec2(-r, r) * ps);
	glow += texture(TEXTURE, UV + vec2(0.0, -r) * ps);
	glow += texture(TEXTURE, UV + vec2(0.0, r) * ps);
	glow += texture(TEXTURE, UV + vec2(r, -r) * ps);
	glow += texture(TEXTURE, UV + vec2(r, 0.0) * ps);
	glow += texture(TEXTURE, UV + vec2(r, r) * ps);

	r *= 2.0;
	glow += texture(TEXTURE, UV + vec2(-r, -r) * ps);
	glow += texture(TEXTURE, UV + vec2(-r, 0.0) * ps);
	glow += texture(TEXTURE, UV + vec2(-r, r) * ps);
	glow += texture(TEXTURE, UV + vec2(0.0, -r) * ps);
	glow += texture(TEXTURE, UV + vec2(0.0, r) * ps);
	glow += texture(TEXTURE, UV + vec2(r, -r) * ps);
	glow += texture(TEXTURE, UV + vec2(r, 0.0) * ps);
	glow += texture(TEXTURE, UV + vec2(r, r) * ps);

	glow /= 17.0;
	glow *= amount;
	col.rgb *= col.a;

	COLOR = glow + col;
}

分解效果(最后一个)

shader_type canvas_item;
render_mode blend_mix;

uniform float amount = 20.0;

void fragment() {
	vec2 uv = UV * 0.05;
	float a = fract(sin(dot(UV, vec2(12.9898, 78.233))) * 438.5453);
	vec4 col = texture(TEXTURE, UV);

	col.a *= pow(a, amount);

	COLOR = col;
}

另:旋转的黑洞

shader_type canvas_item;

uniform float offset : hint_range(0.0, 20.0, 0.01);
uniform float speed : hint_range(0.0, 1.0, 0.01);
uniform float mask : hint_range(0.0, 1.0, 0.01);

vec2 rotate(vec2 p, float angle){
	return vec2(cos(angle)*p.x-sin(angle)*p.y, sin(angle)*p.x + cos(angle)*p.y);
}

void fragment(){
	
	vec2 uv = UV;
	float c = length(UV - vec2(0.5));
	
	uv = rotate(uv-vec2(0.5),offset * c) + vec2(0.5);
	uv.x = abs((uv.x-0.5)*2.0);
	uv.x = fract(uv.x + speed*TIME);
	
	vec4 tex_color = texture(TEXTURE,uv);
	
	COLOR = tex_color;
	float mask_color = 1.0-step(mask,c);
	//COLOR = vec4(mask_color,0.0,0.0,1.0);
	COLOR.a = COLOR.a * mask_color;
	
}

相关文章