Files
project-vivi/Assets/Visuals/Shaders/slice_ring.gdshader
T
2026-09-19 10:06:28 -04:00

48 lines
2.1 KiB
Plaintext

shader_type spatial;
render_mode blend_mix, unshaded, depth_draw_never, cull_disabled, diffuse_burley, specular_disabled, fog_disabled, shadows_disabled, ambient_light_disabled, specular_occlusion_disabled;
uniform lowp vec4 albedo : source_color;
uniform lowp float intersection_thickness : hint_range(0.0f, 0.1f) = 0.02f;
uniform sampler2D pattern : filter_linear_mipmap, repeat_enable;
uniform lowp float pattern_tiling : hint_range(1.0f, 64.0f, 1.0f) = 16.0f;
uniform sampler2D depth_texture : hint_depth_texture;
void fragment()
{
ALBEDO = albedo.rgb;
METALLIC = 0.0f;
SPECULAR = 0.0f;
ROUGHNESS = 1.0f;
lowp float depth = texture(depth_texture, SCREEN_UV).x;
lowp vec3 ndc = vec3(SCREEN_UV * 2.0 - 1.0, depth);
lowp vec4 view = INV_PROJECTION_MATRIX * vec4(ndc, 1.0);
view.xyz /= view.w;
lowp float linear_depth = -view.z;
lowp float object_depth = FRAGCOORD.z;
lowp vec3 object_ndc = vec3(SCREEN_UV * 2.0 - 1.0, object_depth);
lowp vec4 object_view = INV_PROJECTION_MATRIX * vec4(object_ndc, 1.0);
object_view.xyz /= object_view.w;
lowp float linear_object_depth = -object_view.z;
highp vec2 uv = clamp(vec2(atan(1.0 - UV.y, 1.0 - UV.x) / (PI / 2.0f), distance(vec2(1.0f, 1.0f), UV)), 0.0f, 1.0f);
lowp float cross_hatch = smoothstep(0.25f, 0.75f, texture(pattern, uv * pattern_tiling).r);
lowp float add_edging = clamp(cross_hatch + smoothstep(0.98f, 0.999f, distance(vec2(1.0f), UV)), 0.0f, 1.0f);
lowp vec2 edging_fade = smoothstep(vec2(0.0f, 0.1f), vec2(0.333333333333333333333333333333333f, 1.0f), uv);
lowp float fresnel = abs(dot(NORMAL, VIEW));
lowp float view_angle_fresnel = (1.0f - smoothstep(0.01f, 0.015f, fresnel));
lowp float fade_edges = (add_edging * edging_fade.x * edging_fade.y) + view_angle_fresnel;
lowp float intersection_fresnel = pow(1.0f - fresnel, 20.0f);
lowp float intersection = step(distance(linear_depth, linear_object_depth), intersection_thickness + intersection_fresnel);
lowp float final_mask = step(distance(vec2(1.0f, 1.0f), UV), 1.0f);
ALPHA = clamp(fade_edges + intersection, 0.0f, 1.0f) * albedo.a * final_mask;
}