stick-the-quick/vfx/underlay.gdshader

28 lines
733 B
Plaintext
Raw Normal View History

shader_type spatial;
render_mode unshaded;
#include "res://vfx/util.gdshaderinc"
uniform sampler2D viewport_texture: source_color, hint_screen_texture;
uniform sampler2D viewport_depth_texture: source_color, hint_depth_texture;
uniform sampler2D image: source_color, hint_default_transparent;
uniform float far = 4000.0;
void vertex() {
POSITION = vec4(VERTEX.xyz, 1.0);
}
void fragment() {
DEPTH = texture(viewport_depth_texture, SCREEN_UV).x;
float linear_depth = linearize_depth(
DEPTH, SCREEN_UV, INV_PROJECTION_MATRIX
);
if (linear_depth > far) {
ALBEDO = alpha_blend(
texture(image, SCREEN_UV),
texture(viewport_texture, SCREEN_UV)
).rgb;
} else {
ALBEDO = texture(viewport_texture, SCREEN_UV).rgb;
}
}