1
1

GPencil: Use ShaderCreateInfo for vfx shaders

Simple port. Shouldn't break anything.
This commit is contained in:
2022-03-19 12:11:49 +01:00
parent d7ecd4a0f3
commit 337343ecc9
5 changed files with 108 additions and 107 deletions

View File

@@ -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;
}

View File

@@ -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))

View File

@@ -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);

View File

@@ -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");

View File

@@ -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