2023-08-24 10:54:59 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2019-2023 Blender Authors
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2019-12-02 01:40:58 +01:00
|
|
|
|
2025-09-25 10:57:02 +02:00
|
|
|
#include "infos/overlay_wireframe_infos.hh"
|
2025-02-24 16:17:18 +01:00
|
|
|
|
|
|
|
|
FRAGMENT_SHADER_CREATE_INFO(overlay_wireframe_base)
|
|
|
|
|
|
2024-10-04 15:48:22 +02:00
|
|
|
#include "gpu_shader_utildefines_lib.glsl"
|
2025-01-23 18:06:22 +01:00
|
|
|
#include "overlay_common_lib.glsl"
|
2024-10-04 15:48:22 +02:00
|
|
|
#include "select_lib.glsl"
|
2019-12-02 01:40:58 +01:00
|
|
|
|
|
|
|
|
void main()
|
|
|
|
|
{
|
2024-08-19 12:31:08 +02:00
|
|
|
#if !defined(POINTS) && !defined(CURVES)
|
2019-12-03 01:06:40 +01:00
|
|
|
/* Needed only because of wireframe slider.
|
|
|
|
|
* If we could get rid of it would be nice because of performance drain of discard. */
|
2025-04-24 12:50:45 +02:00
|
|
|
if (edge_start.r == -1.0f) {
|
2025-05-05 09:59:00 +02:00
|
|
|
gpu_discard_fragment();
|
2023-02-07 00:57:54 +01:00
|
|
|
return;
|
2019-12-03 01:06:40 +01:00
|
|
|
}
|
2024-08-19 12:31:08 +02:00
|
|
|
#endif
|
|
|
|
|
|
2025-04-24 12:50:45 +02:00
|
|
|
line_output = float4(0.0f);
|
2024-08-19 12:31:08 +02:00
|
|
|
|
|
|
|
|
#if defined(POINTS)
|
2025-04-14 13:46:41 +02:00
|
|
|
float2 centered = abs(gl_PointCoord - float2(0.5f));
|
2024-08-19 12:31:08 +02:00
|
|
|
float dist = max(centered.x, centered.y);
|
2019-12-03 01:06:40 +01:00
|
|
|
|
2025-04-11 18:28:45 +02:00
|
|
|
float fac = dist * dist * 4.0f;
|
2024-08-19 12:31:08 +02:00
|
|
|
/* Create a small gradient so that dense objects have a small fresnel effect. */
|
|
|
|
|
/* Non linear blend. */
|
2025-04-24 12:50:45 +02:00
|
|
|
float3 rim_col = sqrt(final_color_inner.rgb);
|
|
|
|
|
float3 wire_col = sqrt(final_color.rgb);
|
2025-04-14 13:46:41 +02:00
|
|
|
float3 final_front_col = mix(rim_col, wire_col, 0.35f);
|
2025-04-24 12:50:45 +02:00
|
|
|
frag_color = float4(mix(final_front_col, rim_col, saturate(fac)), 1.0f);
|
|
|
|
|
frag_color *= frag_color;
|
2024-08-19 12:31:08 +02:00
|
|
|
|
2024-12-13 16:04:51 +01:00
|
|
|
#elif !defined(SELECT_ENABLE)
|
2025-04-24 12:50:45 +02:00
|
|
|
line_output = pack_line_data(gl_FragCoord.xy, edge_start, edge_pos);
|
|
|
|
|
frag_color = final_color;
|
2020-03-26 15:36:15 +01:00
|
|
|
|
2024-08-19 12:31:08 +02:00
|
|
|
# if !defined(CURVES)
|
2025-08-08 15:51:42 +02:00
|
|
|
gl_FragDepth = gl_FragCoord.z;
|
2024-08-19 12:31:08 +02:00
|
|
|
if (use_custom_depth_bias) {
|
2025-04-24 12:50:45 +02:00
|
|
|
float2 dir = line_output.xy * 2.0f - 1.0f;
|
2024-08-19 12:31:08 +02:00
|
|
|
bool dir_horiz = abs(dir.x) > abs(dir.y);
|
2020-03-26 15:36:15 +01:00
|
|
|
|
2025-04-26 11:28:24 +02:00
|
|
|
float2 uv = gl_FragCoord.xy * uniform_buf.size_viewport_inv;
|
2025-04-24 12:50:45 +02:00
|
|
|
float depth_occluder = texture(depth_tx, uv).r;
|
2024-08-19 12:31:08 +02:00
|
|
|
float depth_min = depth_occluder;
|
2025-04-26 11:28:24 +02:00
|
|
|
float2 uv_offset = uniform_buf.size_viewport_inv;
|
2024-08-19 12:31:08 +02:00
|
|
|
if (dir_horiz) {
|
2025-04-11 18:28:45 +02:00
|
|
|
uv_offset.y = 0.0f;
|
2024-08-19 12:31:08 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2025-04-11 18:28:45 +02:00
|
|
|
uv_offset.x = 0.0f;
|
2024-08-19 12:31:08 +02:00
|
|
|
}
|
2020-03-26 15:36:15 +01:00
|
|
|
|
2025-04-24 12:50:45 +02:00
|
|
|
depth_min = min(depth_min, texture(depth_tx, uv - uv_offset).r);
|
|
|
|
|
depth_min = min(depth_min, texture(depth_tx, uv + uv_offset).r);
|
2024-10-16 17:01:00 +02:00
|
|
|
|
2024-08-19 12:31:08 +02:00
|
|
|
float delta = abs(depth_occluder - depth_min);
|
2020-03-26 15:36:15 +01:00
|
|
|
|
2024-08-19 12:31:08 +02:00
|
|
|
# ifndef SELECT_ENABLE
|
|
|
|
|
if (gl_FragCoord.z < (depth_occluder + delta) && gl_FragCoord.z > depth_occluder) {
|
|
|
|
|
gl_FragDepth = depth_occluder;
|
|
|
|
|
}
|
|
|
|
|
# endif
|
2020-03-26 15:36:15 +01:00
|
|
|
}
|
|
|
|
|
# endif
|
2019-12-03 01:06:40 +01:00
|
|
|
#endif
|
2024-08-19 12:31:08 +02:00
|
|
|
|
|
|
|
|
select_id_output(select_id);
|
2019-12-02 01:40:58 +01:00
|
|
|
}
|