1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
#include "gpu_shader_create_info.hh"
/* -------------------------------------------------------------------- */
/** \name GPencil Object rendering
* \{ */
GPU_SHADER_INTERFACE_INFO(gpencil_geometry_iface, "gp_interp")
.smooth(Type::VEC4, "color_mul")
.smooth(Type::VEC4, "color_add")
.smooth(Type::VEC3, "pos")
.smooth(Type::VEC2, "uv")
.no_perspective(Type::VEC2, "thickness")
.no_perspective(Type::FLOAT, "hardness")
.flat(Type::VEC2, "aspect")
.flat(Type::VEC4, "sspos")
.flat(Type::UINT, "mat_flag")
.flat(Type::FLOAT, "depth");
GPU_SHADER_CREATE_INFO(gpencil_geometry)
.do_static_compilation(true)
.define("GP_LIGHT")
.typedef_source("gpencil_defines.h")
.sampler(0, ImageType::FLOAT_2D, "gpFillTexture")
.sampler(1, ImageType::FLOAT_2D, "gpStrokeTexture")
.sampler(2, ImageType::DEPTH_2D, "gpSceneDepthTexture")
.sampler(3, ImageType::FLOAT_2D, "gpMaskTexture")
.uniform_buf(2, "gpMaterial", "materials[GPENCIL_MATERIAL_BUFFER_LEN]", Frequency::BATCH)
.uniform_buf(3, "gpLight", "lights[GPENCIL_LIGHT_BUFFER_LEN]", Frequency::BATCH)
/* Per Object */
.push_constant(Type::VEC3, "gpNormal")
.push_constant(Type::BOOL, "gpStrokeOrder3d")
.push_constant(Type::INT, "gpMaterialOffset")
/* Per Layer */
.push_constant(Type::FLOAT, "gpVertexColorOpacity")
.push_constant(Type::VEC4, "gpLayerTint")
.push_constant(Type::FLOAT, "gpLayerOpacity")
.push_constant(Type::FLOAT, "gpStrokeIndexOffset")
.fragment_out(0, Type::VEC4, "fragColor")
.fragment_out(1, Type::VEC4, "revealColor")
.vertex_out(gpencil_geometry_iface)
.vertex_source("gpencil_vert.glsl")
.fragment_source("gpencil_frag.glsl")
.additional_info("draw_gpencil");
/** \} */
/* -------------------------------------------------------------------- */
/** \name Fullscreen shaders
* \{ */
GPU_SHADER_CREATE_INFO(gpencil_layer_blend)
.do_static_compilation(true)
.sampler(0, ImageType::FLOAT_2D, "colorBuf")
.sampler(1, ImageType::FLOAT_2D, "revealBuf")
.sampler(2, ImageType::FLOAT_2D, "maskBuf")
.push_constant(Type::INT, "blendMode")
.push_constant(Type::FLOAT, "blendOpacity")
/* 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_layer_blend_frag.glsl")
.additional_info("draw_fullscreen");
GPU_SHADER_CREATE_INFO(gpencil_mask_invert)
.do_static_compilation(true)
.fragment_out(0, Type::VEC4, "fragColor")
.fragment_out(1, Type::VEC4, "fragRevealage")
.fragment_source("gpencil_mask_invert_frag.glsl")
.additional_info("draw_fullscreen");
GPU_SHADER_CREATE_INFO(gpencil_depth_merge)
.do_static_compilation(true)
.push_constant(Type::VEC4, "gpModelMatrix", 4)
.push_constant(Type::BOOL, "strokeOrder3d")
.sampler(0, ImageType::DEPTH_2D, "depthBuf")
.vertex_source("gpencil_depth_merge_vert.glsl")
.fragment_source("gpencil_depth_merge_frag.glsl")
.additional_info("draw_view");
/** \} */
/* -------------------------------------------------------------------- */
/** \name Anti-Aliasing
* \{ */
GPU_SHADER_INTERFACE_INFO(gpencil_antialiasing_iface, "")
.smooth(Type::VEC2, "uvs")
.smooth(Type::VEC2, "pixcoord")
.smooth(Type::VEC4, "offset[3]");
GPU_SHADER_CREATE_INFO(gpencil_antialiasing)
.define("SMAA_GLSL_3")
.define("SMAA_RT_METRICS", "viewportMetrics")
.define("SMAA_PRESET_HIGH")
.define("SMAA_LUMA_WEIGHT", "float4(lumaWeight, lumaWeight, lumaWeight, 0.0)")
.define("SMAA_NO_DISCARD")
.vertex_out(gpencil_antialiasing_iface)
.push_constant(Type::VEC4, "viewportMetrics")
.push_constant(Type::FLOAT, "lumaWeight")
.vertex_source("gpencil_antialiasing_vert.glsl")
.fragment_source("gpencil_antialiasing_frag.glsl");
GPU_SHADER_CREATE_INFO(gpencil_antialiasing_stage_0)
.define("SMAA_STAGE", "0")
.sampler(0, ImageType::FLOAT_2D, "colorTex")
.sampler(1, ImageType::FLOAT_2D, "revealTex")
.fragment_out(0, Type::VEC2, "out_edges")
.additional_info("gpencil_antialiasing")
.do_static_compilation(true);
GPU_SHADER_CREATE_INFO(gpencil_antialiasing_stage_1)
.define("SMAA_STAGE", "1")
.sampler(0, ImageType::FLOAT_2D, "edgesTex")
.sampler(1, ImageType::FLOAT_2D, "areaTex")
.sampler(2, ImageType::FLOAT_2D, "searchTex")
.fragment_out(0, Type::VEC4, "out_weights")
.additional_info("gpencil_antialiasing")
.do_static_compilation(true);
GPU_SHADER_CREATE_INFO(gpencil_antialiasing_stage_2)
.define("SMAA_STAGE", "2")
.sampler(0, ImageType::FLOAT_2D, "colorTex")
.sampler(1, ImageType::FLOAT_2D, "revealTex")
.sampler(2, ImageType::FLOAT_2D, "blendTex")
.push_constant(Type::FLOAT, "mixFactor")
.push_constant(Type::FLOAT, "taaAccumulatedWeight")
.push_constant(Type::BOOL, "doAntiAliasing")
.push_constant(Type::BOOL, "onlyAlpha")
/* Reminder: Blending func is `fragRevealage * DST + fragColor`. */
.fragment_out(0, Type::VEC4, "out_color", DualBlend::SRC_0)
.fragment_out(0, Type::VEC4, "out_reveal", DualBlend::SRC_1)
.additional_info("gpencil_antialiasing")
.do_static_compilation(true);
/** \} */
|