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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright 2019, Blender Foundation.
*/
/** \file
* \ingroup draw
*/
#include "DRW_render.h"
#include "gpencil_engine.h"
extern char datatoc_gpencil_common_lib_glsl[];
extern char datatoc_gpencil_frag_glsl[];
extern char datatoc_gpencil_vert_glsl[];
extern char datatoc_gpencil_antialiasing_frag_glsl[];
extern char datatoc_gpencil_antialiasing_vert_glsl[];
extern char datatoc_gpencil_layer_blend_frag_glsl[];
extern char datatoc_gpencil_mask_invert_frag_glsl[];
extern char datatoc_gpencil_depth_merge_frag_glsl[];
extern char datatoc_gpencil_depth_merge_vert_glsl[];
extern char datatoc_gpencil_vfx_frag_glsl[];
extern char datatoc_common_colormanagement_lib_glsl[];
extern char datatoc_common_fullscreen_vert_glsl[];
extern char datatoc_common_smaa_lib_glsl[];
extern char datatoc_common_view_lib_glsl[];
static struct {
/* SMAA antialiasing */
GPUShader *antialiasing_sh[3];
/* GPencil Object rendering */
GPUShader *gpencil_sh;
/* Final Compositing over rendered background. */
GPUShader *composite_sh;
/* All layer blend types in one shader! */
GPUShader *layer_blend_sh;
/* Merge the final object depth to the depth buffer. */
GPUShader *depth_merge_sh;
/* Invert the content of the mask buffer. */
GPUShader *mask_invert_sh;
/* Effects. */
GPUShader *fx_composite_sh;
GPUShader *fx_colorize_sh;
GPUShader *fx_blur_sh;
GPUShader *fx_glow_sh;
GPUShader *fx_pixel_sh;
GPUShader *fx_rim_sh;
GPUShader *fx_shadow_sh;
GPUShader *fx_transform_sh;
/* general drawing shaders */
GPUShader *gpencil_fill_sh;
GPUShader *gpencil_stroke_sh;
GPUShader *gpencil_point_sh;
GPUShader *gpencil_edit_point_sh;
GPUShader *gpencil_line_sh;
GPUShader *gpencil_drawing_fill_sh;
GPUShader *gpencil_fullscreen_sh;
GPUShader *gpencil_simple_fullscreen_sh;
GPUShader *gpencil_blend_fullscreen_sh;
GPUShader *gpencil_background_sh;
GPUShader *gpencil_paper_sh;
} g_shaders = {{NULL}};
void GPENCIL_shader_free(void)
{
GPUShader **sh_data_as_array = (GPUShader **)&g_shaders;
for (int i = 0; i < (sizeof(g_shaders) / sizeof(GPUShader *)); i++) {
DRW_SHADER_FREE_SAFE(sh_data_as_array[i]);
}
}
GPUShader *GPENCIL_shader_antialiasing(int stage)
{
BLI_assert(stage < 3);
if (!g_shaders.antialiasing_sh[stage]) {
char stage_define[32];
BLI_snprintf(stage_define, sizeof(stage_define), "#define SMAA_STAGE %d\n", stage);
g_shaders.antialiasing_sh[stage] = GPU_shader_create_from_arrays({
.vert =
(const char *[]){
"#define SMAA_INCLUDE_VS 1\n",
"#define SMAA_INCLUDE_PS 0\n",
"uniform vec4 viewportMetrics;\n",
datatoc_common_smaa_lib_glsl,
datatoc_gpencil_antialiasing_vert_glsl,
NULL,
},
.frag =
(const char *[]){
"#define SMAA_INCLUDE_VS 0\n",
"#define SMAA_INCLUDE_PS 1\n",
"uniform vec4 viewportMetrics;\n",
datatoc_common_smaa_lib_glsl,
datatoc_gpencil_antialiasing_frag_glsl,
NULL,
},
.defs =
(const char *[]){
"#define SMAA_GLSL_3\n",
"#define SMAA_RT_METRICS viewportMetrics\n",
"#define SMAA_PRESET_HIGH\n",
"#define SMAA_LUMA_WEIGHT float4(1.0, 1.0, 1.0, 0.0)\n",
"#define SMAA_NO_DISCARD\n",
stage_define,
NULL,
},
});
}
return g_shaders.antialiasing_sh[stage];
}
GPUShader *GPENCIL_shader_geometry_get(void)
{
if (!g_shaders.gpencil_sh) {
g_shaders.gpencil_sh = GPU_shader_create_from_arrays({
.vert =
(const char *[]){
datatoc_common_view_lib_glsl,
datatoc_gpencil_common_lib_glsl,
datatoc_gpencil_vert_glsl,
NULL,
},
.frag =
(const char *[]){
datatoc_common_colormanagement_lib_glsl,
datatoc_gpencil_common_lib_glsl,
datatoc_gpencil_frag_glsl,
NULL,
},
.defs =
(const char *[]){
"#define GP_MATERIAL_BUFFER_LEN " STRINGIFY(GP_MATERIAL_BUFFER_LEN) "\n",
"#define GPENCIL_LIGHT_BUFFER_LEN " STRINGIFY(GPENCIL_LIGHT_BUFFER_LEN) "\n",
"#define UNIFORM_RESOURCE_ID\n",
NULL,
},
});
}
return g_shaders.gpencil_sh;
}
GPUShader *GPENCIL_shader_layer_blend_get(void)
{
if (!g_shaders.layer_blend_sh) {
g_shaders.layer_blend_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_layer_blend_frag_glsl,
NULL,
},
});
}
return g_shaders.layer_blend_sh;
}
GPUShader *GPENCIL_shader_mask_invert_get(void)
{
if (!g_shaders.mask_invert_sh) {
g_shaders.mask_invert_sh = DRW_shader_create_fullscreen(datatoc_gpencil_mask_invert_frag_glsl,
NULL);
}
return g_shaders.mask_invert_sh;
}
GPUShader *GPENCIL_shader_depth_merge_get(void)
{
if (!g_shaders.depth_merge_sh) {
g_shaders.depth_merge_sh = GPU_shader_create_from_arrays({
.vert =
(const char *[]){
datatoc_common_view_lib_glsl,
datatoc_gpencil_depth_merge_vert_glsl,
NULL,
},
.frag =
(const char *[]){
datatoc_gpencil_depth_merge_frag_glsl,
NULL,
},
});
}
return g_shaders.depth_merge_sh;
}
/* ------- FX Shaders --------- */
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");
}
return g_shaders.fx_blur_sh;
}
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");
}
return g_shaders.fx_colorize_sh;
}
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");
}
return g_shaders.fx_composite_sh;
}
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,
},
});
}
return g_shaders.fx_glow_sh;
}
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");
}
return g_shaders.fx_pixel_sh;
}
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,
},
});
}
return g_shaders.fx_rim_sh;
}
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");
}
return g_shaders.fx_shadow_sh;
}
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");
}
return g_shaders.fx_transform_sh;
}
|