Blender  V2.93
gpencil_antialiasing.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2019, Blender Foundation.
17  */
18 
23 #include "DRW_render.h"
24 
25 #include "gpencil_engine.h"
26 
27 #include "smaa_textures.h"
28 
30 {
31  GPENCIL_PrivateData *pd = vedata->stl->pd;
32  GPENCIL_FramebufferList *fbl = vedata->fbl;
33  GPENCIL_TextureList *txl = vedata->txl;
34  GPENCIL_PassList *psl = vedata->psl;
35  DRWShadingGroup *grp;
36 
37  const float *size = DRW_viewport_size_get();
38  const float *sizeinv = DRW_viewport_invert_size_get();
39  const float metrics[4] = {sizeinv[0], sizeinv[1], size[0], size[1]};
40 
41  if (pd->simplify_antialias) {
42  /* No AA fallback. */
44 
46  grp = DRW_shgroup_create(sh, psl->smaa_resolve_ps);
47  DRW_shgroup_uniform_texture(grp, "blendTex", pd->color_tx);
48  DRW_shgroup_uniform_texture(grp, "colorTex", pd->color_tx);
49  DRW_shgroup_uniform_texture(grp, "revealTex", pd->reveal_tx);
50  DRW_shgroup_uniform_bool_copy(grp, "doAntiAliasing", false);
51  DRW_shgroup_uniform_bool_copy(grp, "onlyAlpha", pd->draw_wireframe);
52  DRW_shgroup_uniform_vec4_copy(grp, "viewportMetrics", metrics);
53 
55  return;
56  }
57 
58  if (txl->smaa_search_tx == NULL) {
60  "smaa_search", SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT, 1, GPU_R8, NULL);
62 
64  "smaa_area", AREATEX_WIDTH, AREATEX_HEIGHT, 1, GPU_RG8, NULL);
66 
69  }
70 
71  {
76 
77  GPU_framebuffer_ensure_config(&fbl->smaa_edge_fb,
78  {
79  GPU_ATTACHMENT_NONE,
80  GPU_ATTACHMENT_TEXTURE(pd->smaa_edge_tx),
81  });
82 
83  GPU_framebuffer_ensure_config(&fbl->smaa_weight_fb,
84  {
85  GPU_ATTACHMENT_NONE,
86  GPU_ATTACHMENT_TEXTURE(pd->smaa_weight_tx),
87  });
88  }
89 
90  {
91  /* Stage 1: Edge detection. */
93 
95  grp = DRW_shgroup_create(sh, psl->smaa_edge_ps);
96  DRW_shgroup_uniform_texture(grp, "colorTex", pd->color_tx);
97  DRW_shgroup_uniform_texture(grp, "revealTex", pd->reveal_tx);
98  DRW_shgroup_uniform_vec4_copy(grp, "viewportMetrics", metrics);
100  grp, "lumaWeight", pd->scene->grease_pencil_settings.smaa_threshold);
101 
102  DRW_shgroup_clear_framebuffer(grp, GPU_COLOR_BIT, 0, 0, 0, 0, 0.0f, 0x0);
104  }
105  {
106  /* Stage 2: Blend Weight/Coord. */
108 
110  grp = DRW_shgroup_create(sh, psl->smaa_weight_ps);
111  DRW_shgroup_uniform_texture(grp, "edgesTex", pd->smaa_edge_tx);
112  DRW_shgroup_uniform_texture(grp, "areaTex", txl->smaa_area_tx);
113  DRW_shgroup_uniform_texture(grp, "searchTex", txl->smaa_search_tx);
114  DRW_shgroup_uniform_vec4_copy(grp, "viewportMetrics", metrics);
115 
116  DRW_shgroup_clear_framebuffer(grp, GPU_COLOR_BIT, 0, 0, 0, 0, 0.0f, 0x0);
118  }
119  {
120  /* Stage 3: Resolve. */
122 
124  grp = DRW_shgroup_create(sh, psl->smaa_resolve_ps);
125  DRW_shgroup_uniform_texture(grp, "blendTex", pd->smaa_weight_tx);
126  DRW_shgroup_uniform_texture(grp, "colorTex", pd->color_tx);
127  DRW_shgroup_uniform_texture(grp, "revealTex", pd->reveal_tx);
128  DRW_shgroup_uniform_bool_copy(grp, "doAntiAliasing", true);
129  DRW_shgroup_uniform_bool_copy(grp, "onlyAlpha", pd->draw_wireframe);
130  DRW_shgroup_uniform_vec4_copy(grp, "viewportMetrics", metrics);
131 
133  }
134 }
135 
137 {
138  GPENCIL_FramebufferList *fbl = vedata->fbl;
139  GPENCIL_PrivateData *pd = vedata->stl->pd;
140  GPENCIL_PassList *psl = vedata->psl;
141 
142  if (!pd->simplify_antialias) {
145 
148  }
149 
152 }
@ DRW_STATE_WRITE_COLOR
Definition: DRW_render.h:315
@ DRW_STATE_BLEND_CUSTOM
Definition: DRW_render.h:348
#define DRW_PASS_CREATE(pass, state)
Definition: DRW_render.h:593
@ GPU_COLOR_BIT
void GPU_framebuffer_bind(GPUFrameBuffer *fb)
struct GPUShader GPUShader
Definition: GPU_shader.h:33
@ GPU_DATA_UBYTE
Definition: GPU_texture.h:175
void GPU_texture_update(GPUTexture *tex, eGPUDataFormat data_format, const void *data)
Definition: gpu_texture.cc:391
void GPU_texture_filter_mode(GPUTexture *tex, bool use_filter)
Definition: gpu_texture.cc:468
GPUTexture * GPU_texture_create_2d(const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data)
Definition: gpu_texture.cc:250
@ GPU_RG8
Definition: GPU_texture.h:98
@ GPU_R8
Definition: GPU_texture.h:108
@ GPU_RGBA8
Definition: GPU_texture.h:88
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
const float * DRW_viewport_size_get(void)
Definition: draw_manager.c:439
const float * DRW_viewport_invert_size_get(void)
Definition: draw_manager.c:444
void DRW_shgroup_uniform_float_copy(DRWShadingGroup *shgroup, const char *name, const float value)
void DRW_shgroup_uniform_texture(DRWShadingGroup *shgroup, const char *name, const GPUTexture *tex)
void DRW_shgroup_call_procedural_triangles(DRWShadingGroup *shgroup, Object *ob, uint tri_count)
DRWShadingGroup * DRW_shgroup_create(struct GPUShader *shader, DRWPass *pass)
void DRW_shgroup_uniform_vec4_copy(DRWShadingGroup *shgroup, const char *name, const float *value)
void DRW_shgroup_clear_framebuffer(DRWShadingGroup *shgroup, eGPUFrameBufferBits channels, uchar r, uchar g, uchar b, uchar a, float depth, uchar stencil)
void DRW_shgroup_uniform_bool_copy(DRWShadingGroup *shgroup, const char *name, const bool value)
void DRW_draw_pass(DRWPass *pass)
GPUTexture * DRW_texture_pool_query_2d(int w, int h, eGPUTextureFormat format, DrawEngineType *engine_type)
void GPENCIL_antialiasing_draw(struct GPENCIL_Data *vedata)
void GPENCIL_antialiasing_init(struct GPENCIL_Data *vedata)
DrawEngineType draw_engine_gpencil_type
struct GPUShader * GPENCIL_shader_antialiasing(int stage)
#define SEARCHTEX_HEIGHT
static const unsigned char searchTexBytes[]
#define SEARCHTEX_WIDTH
#define AREATEX_HEIGHT
Definition: smaa_textures.h:32
static const unsigned char areaTexBytes[]
Definition: smaa_textures.h:43
#define AREATEX_WIDTH
Definition: smaa_textures.h:31
struct GPENCIL_TextureList * txl
struct GPENCIL_PassList * psl
struct GPENCIL_StorageList * stl
struct GPENCIL_FramebufferList * fbl
struct GPUFrameBuffer * smaa_weight_fb
struct GPUFrameBuffer * smaa_edge_fb
struct DRWPass * smaa_weight_ps
struct DRWPass * smaa_resolve_ps
struct DRWPass * smaa_edge_ps
GPUTexture * smaa_weight_tx
GPUTexture * reveal_tx
GPUTexture * color_tx
GPUFrameBuffer * scene_fb
struct Scene * scene
GPUTexture * smaa_edge_tx
struct GPENCIL_PrivateData * pd
struct GPUTexture * smaa_area_tx
struct GPUTexture * smaa_search_tx
struct SceneGpencil grease_pencil_settings