This avoid having to guards functions that are only available in fragment shader stage. Calling the function inside another stage is still invalid and will yield a compile error on Metal. The vulkan and opengl glsl patch need to be modified per stage to allow the fragment specific function to be defined. This is not yet widely used, but a good example is the change in `film_display_depth_amend`. Rel #137261 Pull Request: https://projects.blender.org/blender/blender/pulls/138280
34 lines
767 B
GLSL
34 lines
767 B
GLSL
/* SPDX-FileCopyrightText: 2019-2022 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
void node_wireframe(float size, out float fac)
|
|
{
|
|
float3 barys = g_data.barycentric_coords.xyy;
|
|
barys.z = 1.0f - barys.x - barys.y;
|
|
|
|
size *= 0.5f;
|
|
float3 s = step(-size, -barys * g_data.barycentric_dists);
|
|
|
|
fac = max(s.x, max(s.y, s.z));
|
|
}
|
|
|
|
void node_wireframe_screenspace(float size, out float fac)
|
|
{
|
|
float3 barys = g_data.barycentric_coords.xyy;
|
|
barys.z = 1.0f - barys.x - barys.y;
|
|
|
|
#ifdef GPU_FRAGMENT_SHADER
|
|
size *= (1.0f / 3.0f);
|
|
float3 dx = gpu_dfdx(barys);
|
|
float3 dy = gpu_dfdy(barys);
|
|
float3 deltas = sqrt(dx * dx + dy * dy);
|
|
|
|
float3 s = step(-deltas * size, -barys);
|
|
|
|
fac = max(s.x, max(s.y, s.z));
|
|
#else
|
|
fac = 1.0f;
|
|
#endif
|
|
}
|