GPU: Patch GPencil shader for metal support.
The stoke shader of grease pencil uses a geometry shader stage. Apple devices don't support shaders with geometry shader stage. In the OpenGL driver there was a pass-through implemented so it didn't fail. When using the metal backend this needs to be solved more explicitly. This change patches the grease pencil shader to support both the backends supporting a geometry stage and those without. Fixes #105059 Pull Request #105116
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "GPU_capabilities.h"
|
||||
#include "GPU_shader.h"
|
||||
|
||||
/* Cache of built-in shaders (each is created on first use). */
|
||||
@@ -84,7 +85,8 @@ static const char *builtin_shader_create_info_name(eGPUBuiltinShader shader)
|
||||
case GPU_SHADER_2D_NODELINK_INST:
|
||||
return "gpu_shader_2D_nodelink_inst";
|
||||
case GPU_SHADER_GPENCIL_STROKE:
|
||||
return "gpu_shader_gpencil_stroke";
|
||||
return GPU_geometry_shader_support() ? "gpu_shader_gpencil_stroke_geom" :
|
||||
"gpu_shader_gpencil_stroke_nogeom";
|
||||
default:
|
||||
BLI_assert_unreachable();
|
||||
return "";
|
||||
|
||||
@@ -1,12 +1,33 @@
|
||||
#ifdef USE_GEOMETRY_SHADER
|
||||
vec4 fragment_in_color()
|
||||
{
|
||||
return geometry_out.mColor;
|
||||
}
|
||||
|
||||
vec2 fragment_in_tex_coord()
|
||||
{
|
||||
return geometry_out.mTexCoord;
|
||||
}
|
||||
#else
|
||||
vec4 fragment_in_color()
|
||||
{
|
||||
return geometry_in.finalColor;
|
||||
}
|
||||
|
||||
vec2 fragment_in_tex_coord()
|
||||
{
|
||||
return vec2(0.5);
|
||||
}
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
const vec2 center = vec2(0, 0.5);
|
||||
vec4 tColor = vec4(geometry_out.mColor);
|
||||
vec4 tColor = fragment_in_color();
|
||||
/* if alpha < 0, then encap */
|
||||
if (geometry_out.mColor.a < 0) {
|
||||
if (tColor.a < 0) {
|
||||
tColor.a = tColor.a * -1.0;
|
||||
float dist = length(geometry_out.mTexCoord - center);
|
||||
float dist = length(fragment_in_tex_coord() - center);
|
||||
if (dist > 0.25) {
|
||||
discard;
|
||||
}
|
||||
|
||||
@@ -14,13 +14,11 @@ GPU_SHADER_INTERFACE_INFO(gpencil_stroke_geom_iface, "geometry_out")
|
||||
.smooth(Type::VEC4, "mColor")
|
||||
.smooth(Type::VEC2, "mTexCoord");
|
||||
|
||||
GPU_SHADER_CREATE_INFO(gpu_shader_gpencil_stroke)
|
||||
GPU_SHADER_CREATE_INFO(gpu_shader_gpencil_stroke_base)
|
||||
.vertex_in(0, Type::VEC4, "color")
|
||||
.vertex_in(1, Type::VEC3, "pos")
|
||||
.vertex_in(2, Type::FLOAT, "thickness")
|
||||
.vertex_out(gpencil_stroke_vert_iface)
|
||||
.geometry_layout(PrimitiveIn::LINES_ADJACENCY, PrimitiveOut::TRIANGLE_STRIP, 13)
|
||||
.geometry_out(gpencil_stroke_geom_iface)
|
||||
.fragment_out(0, Type::VEC4, "fragColor")
|
||||
|
||||
.uniform_buf(0, "GPencilStrokeData", "gpencil_stroke_data")
|
||||
@@ -28,7 +26,16 @@ GPU_SHADER_CREATE_INFO(gpu_shader_gpencil_stroke)
|
||||
.push_constant(Type::MAT4, "ModelViewProjectionMatrix")
|
||||
.push_constant(Type::MAT4, "ProjectionMatrix")
|
||||
.vertex_source("gpu_shader_gpencil_stroke_vert.glsl")
|
||||
.geometry_source("gpu_shader_gpencil_stroke_geom.glsl")
|
||||
.fragment_source("gpu_shader_gpencil_stroke_frag.glsl")
|
||||
.typedef_source("GPU_shader_shared.h")
|
||||
.typedef_source("GPU_shader_shared.h");
|
||||
|
||||
GPU_SHADER_CREATE_INFO(gpu_shader_gpencil_stroke_geom)
|
||||
.additional_info("gpu_shader_gpencil_stroke_base")
|
||||
.geometry_layout(PrimitiveIn::LINES_ADJACENCY, PrimitiveOut::TRIANGLE_STRIP, 13)
|
||||
.geometry_out(gpencil_stroke_geom_iface)
|
||||
.geometry_source("gpu_shader_gpencil_stroke_geom.glsl")
|
||||
.do_static_compilation(true);
|
||||
|
||||
GPU_SHADER_CREATE_INFO(gpu_shader_gpencil_stroke_nogeom)
|
||||
.additional_info("gpu_shader_gpencil_stroke_base")
|
||||
.do_static_compilation(true);
|
||||
|
||||
Reference in New Issue
Block a user