This changes the include directive to use the standard C preprocessor `#include` directive. The regex to applied to all glsl sources is: `pragma BLENDER_REQUIRE\((\w+\.glsl)\)` `include "$1"` This allow C++ linter to parse the code and allow easier codebase traversal. However there is a small catch. While it does work like a standard include directive when the code is treated as C++, it doesn't when compiled by our shader backends. In this case, we still use our dependency concatenation approach instead of file injection. This means that included files will always be prepended when compiled to GLSL and a file cannot be appended more than once. This is why all GLSL lib file should have the `#pragma once` directive and always be included at the start of the file. These requirements are actually already enforced by our code-style in practice. On the implementation, the source needed to be mutated to comment the `#pragma once` and `#include`. This is needed to avoid GLSL compiler error out as this is an extension that not all vendor supports. Rel #127983 Pull Request: https://projects.blender.org/blender/blender/pulls/128076
42 lines
1.2 KiB
GLSL
42 lines
1.2 KiB
GLSL
/* SPDX-FileCopyrightText: 2024 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#pragma once
|
|
|
|
/* Signed distance to rounded box, centered at origin.
|
|
* Reference: https://iquilezles.org/articles/distfunctions2d/ */
|
|
float sdf_rounded_box(vec2 pos, vec2 size, float radius)
|
|
{
|
|
vec2 q = abs(pos) - size + radius;
|
|
return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - radius;
|
|
}
|
|
|
|
void strip_box(float left,
|
|
float right,
|
|
float bottom,
|
|
float top,
|
|
vec2 pos,
|
|
out vec2 r_pos1,
|
|
out vec2 r_pos2,
|
|
out vec2 r_size,
|
|
out vec2 r_center,
|
|
out vec2 r_pos,
|
|
out float r_radius)
|
|
{
|
|
/* Snap to pixel grid coordinates, so that outline/border is non-fractional
|
|
* pixel sizes. */
|
|
r_pos1 = round(vec2(left, bottom));
|
|
r_pos2 = round(vec2(right, top));
|
|
/* Make sure strip is at least 1px wide. */
|
|
r_pos2.x = max(r_pos2.x, r_pos1.x + 1.0);
|
|
r_size = (r_pos2 - r_pos1) * 0.5;
|
|
r_center = (r_pos1 + r_pos2) * 0.5;
|
|
r_pos = round(pos);
|
|
|
|
r_radius = context_data.round_radius;
|
|
if (r_radius > r_size.x) {
|
|
r_radius = 0.0;
|
|
}
|
|
}
|