diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-05-02 00:47:26 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-05-02 00:54:41 +0300 |
commit | 2a7a01b339ad60aec5ffe265411fa2f0b1589137 (patch) | |
tree | 6b472e21edc425d2ceb21c378d248c19bbd558e5 | |
parent | aa34706aacdab45847d7c0e3987b1de4ff0b8760 (diff) |
GPUShader: Port polyline shaders to use shaderCreateInfo
This should have no functional changes.
6 files changed, 66 insertions, 102 deletions
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 68f228e17e0..3cb89f0f233 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -497,6 +497,7 @@ set(SRC_SHADER_CREATE_INFOS shaders/infos/gpu_shader_3D_flat_color_info.hh shaders/infos/gpu_shader_3D_image_modulate_alpha_info.hh shaders/infos/gpu_shader_3D_point_info.hh + shaders/infos/gpu_shader_3D_polyline_info.hh shaders/infos/gpu_shader_3D_smooth_color_info.hh shaders/infos/gpu_shader_3D_uniform_color_info.hh shaders/infos/gpu_shader_gpencil_stroke_info.hh diff --git a/source/blender/gpu/intern/gpu_shader_builtin.c b/source/blender/gpu/intern/gpu_shader_builtin.c index f97ff0bf101..b0e11d85fb9 100644 --- a/source/blender/gpu/intern/gpu_shader_builtin.c +++ b/source/blender/gpu/intern/gpu_shader_builtin.c @@ -227,39 +227,16 @@ static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = { .frag = datatoc_gpu_shader_uniform_color_frag_glsl, }, - [GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR] = - { - .name = "GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR", - .vert = datatoc_gpu_shader_3D_polyline_vert_glsl, - .geom = datatoc_gpu_shader_3D_polyline_geom_glsl, - .frag = datatoc_gpu_shader_3D_polyline_frag_glsl, - .defs = "#define UNIFORM\n", - }, + [GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR] = {.name = "GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR", + .create_info = + "gpu_shader_3D_polyline_uniform_color"}, [GPU_SHADER_3D_POLYLINE_CLIPPED_UNIFORM_COLOR] = - { - .name = "GPU_SHADER_3D_POLYLINE_CLIPPED_UNIFORM_COLOR", - .vert = datatoc_gpu_shader_3D_polyline_vert_glsl, - .geom = datatoc_gpu_shader_3D_polyline_geom_glsl, - .frag = datatoc_gpu_shader_3D_polyline_frag_glsl, - .defs = "#define UNIFORM\n" - "#define CLIP\n", - }, - [GPU_SHADER_3D_POLYLINE_FLAT_COLOR] = - { - .name = "GPU_SHADER_3D_POLYLINE_FLAT_COLOR", - .vert = datatoc_gpu_shader_3D_polyline_vert_glsl, - .geom = datatoc_gpu_shader_3D_polyline_geom_glsl, - .frag = datatoc_gpu_shader_3D_polyline_frag_glsl, - .defs = "#define FLAT\n", - }, - [GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR] = - { - .name = "GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR", - .vert = datatoc_gpu_shader_3D_polyline_vert_glsl, - .geom = datatoc_gpu_shader_3D_polyline_geom_glsl, - .frag = datatoc_gpu_shader_3D_polyline_frag_glsl, - .defs = "#define SMOOTH\n", - }, + {.name = "GPU_SHADER_3D_POLYLINE_CLIPPED_UNIFORM_COLOR", + .create_info = "gpu_shader_3D_polyline_uniform_color_clipped"}, + [GPU_SHADER_3D_POLYLINE_FLAT_COLOR] = {.name = "GPU_SHADER_3D_POLYLINE_FLAT_COLOR", + .create_info = "gpu_shader_3D_polyline_flat_color"}, + [GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR] = {.name = "GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR", + .create_info = "gpu_shader_3D_polyline_smooth_color"}, [GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR] = { diff --git a/source/blender/gpu/shaders/gpu_shader_3D_polyline_frag.glsl b/source/blender/gpu/shaders/gpu_shader_3D_polyline_frag.glsl index 8687763f4c1..27740c8d71b 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_polyline_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_polyline_frag.glsl @@ -1,28 +1,15 @@ -#ifndef USE_GPU_SHADER_CREATE_INFO -uniform float lineWidth; -uniform bool lineSmooth = true; - -in vec4 finalColor; -noperspective in float smoothline; -# ifdef CLIP -in float clip; -# endif - -out vec4 fragColor; -#endif - -#define SMOOTH_WIDTH 1.0 +#pragma BLENDER_REQUIRE(gpu_shader_colorspace_lib.glsl) void main() { #ifdef CLIP - if (clip < 0.0) { + if (interp.clip < 0.0) { discard; } #endif - fragColor = finalColor; + fragColor = interp.color; if (lineSmooth) { - fragColor.a *= clamp((lineWidth + SMOOTH_WIDTH) * 0.5 - abs(smoothline), 0.0, 1.0); + fragColor.a *= clamp((lineWidth + SMOOTH_WIDTH) * 0.5 - abs(interp.smoothline), 0.0, 1.0); } fragColor = blender_srgb_to_framebuffer_space(fragColor); } diff --git a/source/blender/gpu/shaders/gpu_shader_3D_polyline_geom.glsl b/source/blender/gpu/shaders/gpu_shader_3D_polyline_geom.glsl index 627e91af4d6..1c824023234 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_polyline_geom.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_polyline_geom.glsl @@ -1,26 +1,3 @@ -#ifndef USE_GPU_SHADER_CREATE_INFO -layout(lines) in; -layout(triangle_strip, max_vertices = 4) out; - -uniform vec4 color; -uniform vec2 viewportSize; -uniform float lineWidth; -uniform bool lineSmooth = true; - -# if !defined(UNIFORM) -in vec4 finalColor_g[]; -# endif - -# ifdef CLIP -in float clip_g[]; -out float clip; -# endif - -out vec4 finalColor; -noperspective out float smoothline; -#endif - -#define SMOOTH_WIDTH 1.0 /* Clips point to near clip plane before perspective divide. */ vec4 clip_line_point_homogeneous_space(vec4 p, vec4 q) @@ -41,26 +18,26 @@ vec4 clip_line_point_homogeneous_space(vec4 p, vec4 q) void do_vertex(const int i, vec4 pos, vec2 ofs) { #if defined(UNIFORM) - finalColor = color; + interp_out.color = color; #elif defined(FLAT) /* WATCH: Assuming last provoking vertex. */ - finalColor = finalColor_g[1]; + interp_out.color = interp_in[1].color; #elif defined(SMOOTH) - finalColor = finalColor_g[i]; + interp_out.color = interp_in[i].color; #endif #ifdef CLIP - clip = clip_g[i]; + interp_out.clip = interp_in[i].clip; #endif - smoothline = (lineWidth + SMOOTH_WIDTH * float(lineSmooth)) * 0.5; + interp_out.smoothline = (lineWidth + SMOOTH_WIDTH * float(lineSmooth)) * 0.5; gl_Position = pos; gl_Position.xy += ofs * pos.w; EmitVertex(); - smoothline = -(lineWidth + SMOOTH_WIDTH * float(lineSmooth)) * 0.5; + interp_out.smoothline = -(lineWidth + SMOOTH_WIDTH * float(lineSmooth)) * 0.5; gl_Position = pos; gl_Position.xy -= ofs * pos.w; EmitVertex(); diff --git a/source/blender/gpu/shaders/gpu_shader_3D_polyline_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_polyline_vert.glsl index 5c673494870..d4ef3e6142f 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_polyline_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_polyline_vert.glsl @@ -1,29 +1,11 @@ -#ifndef USE_GPU_SHADER_CREATE_INFO -uniform mat4 ModelViewProjectionMatrix; -uniform mat4 ModelMatrix; -uniform vec4 ClipPlane; - -in vec3 pos; - -# if !defined(UNIFORM) -in vec4 color; - -out vec4 finalColor_g; -# endif - -# ifdef CLIP -out float clip_g; -# endif -#endif void main() { gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0); -#if !defined(UNIFORM) - finalColor_g = color; +#ifndef UNIFORM + interp.color = color; #endif - #ifdef CLIP - clip_g = dot(ModelMatrix * vec4(pos, 1.0), ClipPlane); + interp.clip = dot(ModelMatrix * vec4(pos, 1.0), ClipPlane); #endif } diff --git a/source/blender/gpu/shaders/infos/gpu_shader_3D_polyline_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_3D_polyline_info.hh index 33294c8a071..6840dfe25de 100644 --- a/source/blender/gpu/shaders/infos/gpu_shader_3D_polyline_info.hh +++ b/source/blender/gpu/shaders/infos/gpu_shader_3D_polyline_info.hh @@ -8,9 +8,49 @@ #include "gpu_interface_info.hh" #include "gpu_shader_create_info.hh" -/* TODO(jbakker): Skipped as it needs a uniform/storage buffer. */ -GPU_SHADER_CREATE_INFO(gpu_shader_3D_polyline_uniform_color) +GPU_SHADER_INTERFACE_INFO(gpu_shader_3D_polyline_iface, "interp") + .smooth(Type::VEC4, "color") + .smooth(Type::FLOAT, "clip") + .no_perspective(Type::FLOAT, "smoothline"); + +GPU_SHADER_CREATE_INFO(gpu_shader_3D_polyline) + .define("SMOOTH_WIDTH", "1.0") + .push_constant(Type::MAT4, "ModelViewProjectionMatrix") + .push_constant(Type::VEC2, "viewportSize") + .push_constant(Type::FLOAT, "lineWidth") + .push_constant(Type::BOOL, "lineSmooth") + .vertex_in(0, Type::VEC3, "pos") + .vertex_out(gpu_shader_3D_polyline_iface) + .geometry_layout(PrimitiveIn::LINES, PrimitiveOut::TRIANGLE_STRIP, 4) + .geometry_out(gpu_shader_3D_polyline_iface) + .fragment_out(0, Type::VEC4, "fragColor") .vertex_source("gpu_shader_3D_polyline_vert.glsl") .geometry_source("gpu_shader_3D_polyline_geom.glsl") .fragment_source("gpu_shader_3D_polyline_frag.glsl") - .do_static_compilation(true); + .additional_info("gpu_srgb_to_framebuffer_space"); + +GPU_SHADER_CREATE_INFO(gpu_shader_3D_polyline_uniform_color) + .do_static_compilation(true) + .define("UNIFORM") + .push_constant(Type::VEC4, "color") + .additional_info("gpu_shader_3D_polyline"); + +GPU_SHADER_CREATE_INFO(gpu_shader_3D_polyline_uniform_color_clipped) + .do_static_compilation(true) + /* TODO(fclem): Put in an UBO to fit the 128byte requirement. */ + .push_constant(Type::MAT4, "ModelMatrix") + .push_constant(Type::VEC4, "ClipPlane") + .define("CLIP") + .additional_info("gpu_shader_3D_polyline_uniform_color"); + +GPU_SHADER_CREATE_INFO(gpu_shader_3D_polyline_flat_color) + .do_static_compilation(true) + .define("FLAT") + .vertex_in(1, Type::VEC4, "color") + .additional_info("gpu_shader_3D_polyline"); + +GPU_SHADER_CREATE_INFO(gpu_shader_3D_polyline_smooth_color) + .do_static_compilation(true) + .define("SMOOTH") + .vertex_in(1, Type::VEC4, "color") + .additional_info("gpu_shader_3D_polyline"); |