diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-03-19 14:11:49 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-03-20 00:05:34 +0300 |
commit | 337343ecc95b08a198c5fc44d269bd92d4de72e0 (patch) | |
tree | 94fcb6a9cc354f628863a5a2305f7ba2df3156c9 /source | |
parent | d7ecd4a0f3ba87781edec45b03c99eb9e354608a (diff) |
GPencil: Use ShaderCreateInfo for vfx shaders
Simple port. Shouldn't break anything.
Diffstat (limited to 'source')
5 files changed, 108 insertions, 107 deletions
diff --git a/source/blender/draw/engines/gpencil/gpencil_shader.c b/source/blender/draw/engines/gpencil/gpencil_shader.c index d61bbe146d4..557844534ae 100644 --- a/source/blender/draw/engines/gpencil/gpencil_shader.c +++ b/source/blender/draw/engines/gpencil/gpencil_shader.c @@ -218,8 +218,7 @@ GPUShader *GPENCIL_shader_depth_merge_get(void) GPUShader *GPENCIL_shader_fx_blur_get(void) { if (!g_shaders.fx_blur_sh) { - g_shaders.fx_blur_sh = DRW_shader_create_fullscreen(datatoc_gpencil_vfx_frag_glsl, - "#define BLUR\n"); + g_shaders.fx_blur_sh = GPU_shader_create_from_info_name("gpencil_fx_blur"); } return g_shaders.fx_blur_sh; } @@ -227,8 +226,7 @@ GPUShader *GPENCIL_shader_fx_blur_get(void) GPUShader *GPENCIL_shader_fx_colorize_get(void) { if (!g_shaders.fx_colorize_sh) { - g_shaders.fx_colorize_sh = DRW_shader_create_fullscreen(datatoc_gpencil_vfx_frag_glsl, - "#define COLORIZE\n"); + g_shaders.fx_colorize_sh = GPU_shader_create_from_info_name("gpencil_fx_colorize"); } return g_shaders.fx_colorize_sh; } @@ -236,8 +234,7 @@ GPUShader *GPENCIL_shader_fx_colorize_get(void) GPUShader *GPENCIL_shader_fx_composite_get(void) { if (!g_shaders.fx_composite_sh) { - g_shaders.fx_composite_sh = DRW_shader_create_fullscreen(datatoc_gpencil_vfx_frag_glsl, - "#define COMPOSITE\n"); + g_shaders.fx_composite_sh = GPU_shader_create_from_info_name("gpencil_fx_composite"); } return g_shaders.fx_composite_sh; } @@ -245,24 +242,7 @@ GPUShader *GPENCIL_shader_fx_composite_get(void) GPUShader *GPENCIL_shader_fx_glow_get(void) { if (!g_shaders.fx_glow_sh) { - g_shaders.fx_glow_sh = GPU_shader_create_from_arrays({ - .vert = - (const char *[]){ - datatoc_common_fullscreen_vert_glsl, - NULL, - }, - .frag = - (const char *[]){ - datatoc_gpencil_common_lib_glsl, - datatoc_gpencil_vfx_frag_glsl, - NULL, - }, - .defs = - (const char *[]){ - "#define GLOW\n", - NULL, - }, - }); + g_shaders.fx_glow_sh = GPU_shader_create_from_info_name("gpencil_fx_glow"); } return g_shaders.fx_glow_sh; } @@ -270,8 +250,7 @@ GPUShader *GPENCIL_shader_fx_glow_get(void) GPUShader *GPENCIL_shader_fx_pixelize_get(void) { if (!g_shaders.fx_pixel_sh) { - g_shaders.fx_pixel_sh = DRW_shader_create_fullscreen(datatoc_gpencil_vfx_frag_glsl, - "#define PIXELIZE\n"); + g_shaders.fx_pixel_sh = GPU_shader_create_from_info_name("gpencil_fx_pixelize"); } return g_shaders.fx_pixel_sh; } @@ -279,24 +258,7 @@ GPUShader *GPENCIL_shader_fx_pixelize_get(void) GPUShader *GPENCIL_shader_fx_rim_get(void) { if (!g_shaders.fx_rim_sh) { - g_shaders.fx_rim_sh = GPU_shader_create_from_arrays({ - .vert = - (const char *[]){ - datatoc_common_fullscreen_vert_glsl, - NULL, - }, - .frag = - (const char *[]){ - datatoc_gpencil_common_lib_glsl, - datatoc_gpencil_vfx_frag_glsl, - NULL, - }, - .defs = - (const char *[]){ - "#define RIM\n", - NULL, - }, - }); + g_shaders.fx_rim_sh = GPU_shader_create_from_info_name("gpencil_fx_rim"); } return g_shaders.fx_rim_sh; } @@ -304,8 +266,7 @@ GPUShader *GPENCIL_shader_fx_rim_get(void) GPUShader *GPENCIL_shader_fx_shadow_get(void) { if (!g_shaders.fx_shadow_sh) { - g_shaders.fx_shadow_sh = DRW_shader_create_fullscreen(datatoc_gpencil_vfx_frag_glsl, - "#define SHADOW\n"); + g_shaders.fx_shadow_sh = GPU_shader_create_from_info_name("gpencil_fx_shadow"); } return g_shaders.fx_shadow_sh; } @@ -313,8 +274,7 @@ GPUShader *GPENCIL_shader_fx_shadow_get(void) GPUShader *GPENCIL_shader_fx_transform_get(void) { if (!g_shaders.fx_transform_sh) { - g_shaders.fx_transform_sh = DRW_shader_create_fullscreen(datatoc_gpencil_vfx_frag_glsl, - "#define TRANSFORM\n"); + g_shaders.fx_transform_sh = GPU_shader_create_from_info_name("gpencil_fx_transform"); } return g_shaders.fx_transform_sh; } diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl index b4a26ec8103..cf38c1fc12c 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl @@ -149,6 +149,8 @@ void blend_mode_output( } } +#ifndef USE_GPU_SHADER_CREATE_INFO + IN_OUT ShaderStageInterface { vec4 finalColorMul; @@ -165,6 +167,8 @@ IN_OUT ShaderStageInterface flat float depth; }; +#endif + #ifdef GPU_FRAGMENT_SHADER # define linearstep(p0, p1, v) (clamp(((v) - (p0)) / abs((p1) - (p0)), 0.0, 1.0)) diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_vfx_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_vfx_frag.glsl index 269ed49c4d0..5bae00b070f 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_vfx_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_vfx_frag.glsl @@ -1,13 +1,5 @@ -uniform sampler2D colorBuf; -uniform sampler2D revealBuf; - -in vec4 uvcoordsvar; - -/* Reminder: This is considered SRC color in blend equations. - * Same operation on all buffers. */ -layout(location = 0) out vec4 fragColor; -layout(location = 1) out vec4 fragRevealage; +#pragma BLENDER_REQUIRE(gpencil_common_lib.glsl) float gaussian_weight(float x) { @@ -16,8 +8,6 @@ float gaussian_weight(float x) #if defined(COMPOSITE) -uniform bool isFirstPass; - void main() { if (isFirstPass) { @@ -35,11 +25,6 @@ void main() #elif defined(COLORIZE) -uniform vec3 lowColor; -uniform vec3 highColor; -uniform float factor; -uniform int mode; - const mat3 sepia_mat = mat3( vec3(0.393, 0.349, 0.272), vec3(0.769, 0.686, 0.534), vec3(0.189, 0.168, 0.131)); @@ -80,9 +65,6 @@ void main() #elif defined(BLUR) -uniform vec2 offset; -uniform int sampCount; - void main() { vec2 pixel_size = 1.0 / vec2(textureSize(revealBuf, 0).xy); @@ -108,14 +90,6 @@ void main() #elif defined(TRANSFORM) -uniform vec2 axisFlip = vec2(1.0); -uniform vec2 waveDir = vec2(0.0); -uniform vec2 waveOffset = vec2(0.0); -uniform float wavePhase = 0.0; -uniform vec2 swirlCenter = vec2(0.0); -uniform float swirlAngle = 0.0; -uniform float swirlRadius = 0.0; - void main() { vec2 uv = (uvcoordsvar.xy - 0.5) * axisFlip + 0.5; @@ -142,14 +116,6 @@ void main() #elif defined(GLOW) -uniform vec4 glowColor; -uniform vec2 offset; -uniform int sampCount; -uniform vec4 threshold; -uniform bool firstPass; -uniform bool glowUnder; -uniform int blendMode; - void main() { vec2 pixel_size = 1.0 / vec2(textureSize(revealBuf, 0).xy); @@ -210,14 +176,6 @@ void main() #elif defined(RIM) -uniform vec2 blurDir; -uniform vec2 uvOffset; -uniform vec3 rimColor; -uniform vec3 maskColor; -uniform int sampCount; -uniform int blendMode; -uniform bool isFirstPass; - void main() { /* Blur revealage buffer. */ @@ -260,17 +218,6 @@ void main() #elif defined(SHADOW) -uniform vec4 shadowColor; -uniform vec2 uvRotX; -uniform vec2 uvRotY; -uniform vec2 uvOffset; -uniform vec2 blurDir; -uniform vec2 waveDir; -uniform vec2 waveOffset; -uniform float wavePhase; -uniform int sampCount; -uniform bool isFirstPass; - vec2 compute_uvs(float x) { vec2 uv = uvcoordsvar.xy; @@ -327,11 +274,6 @@ void main() #elif defined(PIXELIZE) -uniform vec2 targetPixelSize; -uniform vec2 targetPixelOffset; -uniform vec2 accumOffset; -uniform int sampCount; - void main() { vec2 pixel = floor((uvcoordsvar.xy - targetPixelOffset) / targetPixelSize); diff --git a/source/blender/draw/engines/gpencil/shaders/infos/gpencil_vfx_info.hh b/source/blender/draw/engines/gpencil/shaders/infos/gpencil_vfx_info.hh new file mode 100644 index 00000000000..165b47f82f8 --- /dev/null +++ b/source/blender/draw/engines/gpencil/shaders/infos/gpencil_vfx_info.hh @@ -0,0 +1,94 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpencil_fx_common) + .sampler(0, ImageType::FLOAT_2D, "colorBuf") + .sampler(1, ImageType::FLOAT_2D, "revealBuf") + /* Reminder: This is considered SRC color in blend equations. + * Same operation on all buffers. */ + .fragment_out(0, Type::VEC4, "fragColor") + .fragment_out(1, Type::VEC4, "fragRevealage") + .fragment_source("gpencil_vfx_frag.glsl"); + +GPU_SHADER_CREATE_INFO(gpencil_fx_composite) + .do_static_compilation(true) + .define("COMPOSITE") + .push_constant(Type::BOOL, "isFirstPass") + .additional_info("gpencil_fx_common", "draw_fullscreen"); + +GPU_SHADER_CREATE_INFO(gpencil_fx_colorize) + .do_static_compilation(true) + .define("COLORIZE") + .push_constant(Type::VEC3, "lowColor") + .push_constant(Type::VEC3, "highColor") + .push_constant(Type::FLOAT, "factor") + .push_constant(Type::INT, "mode") + .additional_info("gpencil_fx_common", "draw_fullscreen"); + +GPU_SHADER_CREATE_INFO(gpencil_fx_blur) + .do_static_compilation(true) + .define("BLUR") + .push_constant(Type::VEC2, "offset") + .push_constant(Type::INT, "sampCount") + .additional_info("gpencil_fx_common", "draw_fullscreen"); + +GPU_SHADER_CREATE_INFO(gpencil_fx_transform) + .do_static_compilation(true) + .define("TRANSFORM") + .push_constant(Type::VEC2, "axisFlip") + .push_constant(Type::VEC2, "waveDir") + .push_constant(Type::VEC2, "waveOffset") + .push_constant(Type::FLOAT, "wavePhase") + .push_constant(Type::VEC2, "swirlCenter") + .push_constant(Type::FLOAT, "swirlAngle") + .push_constant(Type::FLOAT, "swirlRadius") + .additional_info("gpencil_fx_common", "draw_fullscreen"); + +GPU_SHADER_CREATE_INFO(gpencil_fx_glow) + .do_static_compilation(true) + .define("GLOW") + .push_constant(Type::VEC4, "glowColor") + .push_constant(Type::VEC2, "offset") + .push_constant(Type::INT, "sampCount") + .push_constant(Type::VEC4, "threshold") + .push_constant(Type::BOOL, "firstPass") + .push_constant(Type::BOOL, "glowUnder") + .push_constant(Type::INT, "blendMode") + .additional_info("gpencil_fx_common", "draw_fullscreen"); + +GPU_SHADER_CREATE_INFO(gpencil_fx_rim) + .do_static_compilation(true) + .define("RIM") + .push_constant(Type::VEC2, "blurDir") + .push_constant(Type::VEC2, "uvOffset") + .push_constant(Type::VEC3, "rimColor") + .push_constant(Type::VEC3, "maskColor") + .push_constant(Type::INT, "sampCount") + .push_constant(Type::INT, "blendMode") + .push_constant(Type::BOOL, "isFirstPass") + .additional_info("gpencil_fx_common", "draw_fullscreen"); + +GPU_SHADER_CREATE_INFO(gpencil_fx_shadow) + .do_static_compilation(true) + .define("SHADOW") + .push_constant(Type::VEC4, "shadowColor") + .push_constant(Type::VEC2, "uvRotX") + .push_constant(Type::VEC2, "uvRotY") + .push_constant(Type::VEC2, "uvOffset") + .push_constant(Type::VEC2, "blurDir") + .push_constant(Type::VEC2, "waveDir") + .push_constant(Type::VEC2, "waveOffset") + .push_constant(Type::FLOAT, "wavePhase") + .push_constant(Type::INT, "sampCount") + .push_constant(Type::BOOL, "isFirstPass") + .additional_info("gpencil_fx_common", "draw_fullscreen"); + +GPU_SHADER_CREATE_INFO(gpencil_fx_pixelize) + .do_static_compilation(true) + .define("PIXELIZE") + .push_constant(Type::VEC2, "targetPixelSize") + .push_constant(Type::VEC2, "targetPixelOffset") + .push_constant(Type::VEC2, "accumOffset") + .push_constant(Type::INT, "sampCount") + .additional_info("gpencil_fx_common", "draw_fullscreen"); diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index ad59da4c072..1fa166a207c 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -388,6 +388,7 @@ list(APPEND SRC ${glsl_source_list_file}) list(APPEND INC ${CMAKE_CURRENT_BINARY_DIR}) set(SRC_SHADER_CREATE_INFOS + ../draw/engines/gpencil/shaders/infos/gpencil_vfx_info.hh ../draw/engines/workbench/shaders/infos/workbench_composite_info.hh ../draw/engines/workbench/shaders/infos/workbench_effect_antialiasing_info.hh ../draw/engines/workbench/shaders/infos/workbench_effect_cavity_info.hh |