Blender V4.3
gpencil_engine.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2017 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#pragma once
10
12
13#include "DRW_render.hh"
14
15#include "BLI_bitmap.h"
16#include "BLI_bounds.hh"
17
18#include "BKE_grease_pencil.hh"
19
20#include "GPU_batch.hh"
21
22#define GP_LIGHT
23
24#include "gpencil_defines.h"
26
28
29struct GPENCIL_Data;
31namespace blender::gpu {
32class Batch;
33}
35struct Object;
36struct RenderEngine;
37struct RenderLayer;
38struct View3D;
39struct bGPDstroke;
40
41/* used to convert pixel scale. */
42#define GPENCIL_PIXEL_FACTOR 2000.0f
43
44/* used to expand VBOs. Size has a big impact in the speed */
45#define GPENCIL_VBO_BLOCK_SIZE 128
46
47#define GP_MAX_MASKBITS 256
48
49/* *********** Draw Data *********** */
50typedef struct GPENCIL_MaterialPool {
51 /* Single linked-list. */
53 /* GPU representation of materials. */
55 /* Matching ubo. */
56 struct GPUUniformBuf *ubo;
57 /* Texture per material. NULL means none. */
60 /* Number of material used in this pool. */
63
64typedef struct GPENCIL_LightPool {
65 /* GPU representation of materials. */
67 /* Matching ubo. */
68 struct GPUUniformBuf *ubo;
69 /* Number of light in the pool. */
72
73typedef struct GPENCIL_ViewLayerData {
74 /* GPENCIL_tObject */
76 /* GPENCIL_tLayer */
78 /* GPENCIL_tVfx */
80 /* GPENCIL_MaterialPool */
82 /* GPENCIL_LightPool */
84 /* BLI_bitmap */
87
88/* *********** GPencil *********** */
89
90typedef struct GPENCIL_tVfx {
94 /* Frame-buffer reference since it may not be allocated yet. */
95 GPUFrameBuffer **target_fb;
97
115
116typedef struct GPENCIL_tObject {
119
120 struct {
123
124 struct {
127
128 /* Distance to camera. Used for sorting. */
129 float camera_z;
130 /* Used for stroke thickness scaling. */
132 /* Normal used for shading. Based on view angle. */
133 float plane_normal[3];
134 /* Used for drawing depth merge pass. */
135 float plane_mat[4][4];
136
138
139 /* Use Material Holdout. */
141
143
144/* *********** LISTS *********** */
148
149typedef struct GPENCIL_PassList {
150 /* Composite the main GPencil buffer onto the rendered image. */
152 /* Composite the object depth to the default depth buffer to occlude overlays. */
154 /* Invert mask buffer content. */
156 /* Anti-Aliasing. */
161
163 struct GPUFrameBuffer *render_fb;
164 struct GPUFrameBuffer *gpencil_fb;
165 struct GPUFrameBuffer *snapshot_fb;
166 struct GPUFrameBuffer *layer_fb;
167 struct GPUFrameBuffer *object_fb;
168 struct GPUFrameBuffer *mask_fb;
169 struct GPUFrameBuffer *smaa_edge_fb;
170 struct GPUFrameBuffer *smaa_weight_fb;
172
173typedef struct GPENCIL_TextureList {
174 /* Dummy texture to avoid errors cause by empty sampler. */
175 struct GPUTexture *dummy_texture;
176 /* Snapshot for smoother drawing. */
177 struct GPUTexture *snapshot_depth_tx;
178 struct GPUTexture *snapshot_color_tx;
179 struct GPUTexture *snapshot_reveal_tx;
180 /* Textures used by Antialiasing. */
181 struct GPUTexture *smaa_area_tx;
182 struct GPUTexture *smaa_search_tx;
183 /* Textures used during render. Containing underlying rendered scene. */
184 struct GPUTexture *render_depth_tx;
185 struct GPUTexture *render_color_tx;
187
195
196/* *********** STATIC *********** */
197typedef struct GPENCIL_PrivateData {
198 /* Pointers copied from GPENCIL_ViewLayerData. */
205 /* Last used material pool. */
207 /* Last used light pool. */
209 /* Common lightpool containing all lights in the scene. */
211 /* Common lightpool containing one ambient white light. */
213 /* Linked list of tObjects. */
214 struct {
217 /* Temp Textures (shared with other engines). */
218 GPUTexture *depth_tx;
219 GPUTexture *color_tx;
220 GPUTexture *color_layer_tx;
221 GPUTexture *color_object_tx;
222 /* Revealage is 1 - alpha */
223 GPUTexture *reveal_tx;
224 GPUTexture *reveal_layer_tx;
225 GPUTexture *reveal_object_tx;
226 /* Mask texture */
227 GPUTexture *mask_tx;
228 /* Anti-Aliasing. */
229 GPUTexture *smaa_edge_tx;
230 GPUTexture *smaa_weight_tx;
231 /* Pointer to dtxl->depth */
232 GPUTexture *scene_depth_tx;
233 GPUFrameBuffer *scene_fb;
234 /* Copy of txl->dummy_tx */
235 GPUTexture *dummy_tx;
236 /* Copy of v3d->shading.single_color. */
238 /* Copy of v3d->shading.color_type or -1 to ignore. */
240 /* Current frame */
241 int cfra;
242 /* If we are rendering for final render (F12).
243 * NOTE: set to false for viewport and opengl rendering (including sequencer scene rendering),
244 * but set to true when rendering in #OB_RENDER shading mode (viewport or opengl rendering). */
246 /* If we are in viewport display (used for VFX). */
248 /* True in selection and auto_depth drawing */
250 /* Is shading set to wire-frame. */
252 /* Used by the depth merge step. */
254 float object_bound_mat[4][4];
255 /* Used for computing object distance to camera. */
257 float camera_pos[3];
258 /* Pseudo depth of field parameter. Used to scale blur radius. */
259 float dof_params[2];
260 /* Used for DoF Setup. */
262 /* Copy of draw_ctx->view_layer for convenience. */
264 /* Copy of draw_ctx->scene for convenience. */
265 struct Scene *scene;
266 /* Copy of draw_ctx->vie3d for convenience. */
267 struct View3D *v3d;
268
269 /* Active object. */
271 /* Object being in draw mode. */
273 /* Layer to append the temp stroke to. */
275 /* Temporary stroke currently being drawn. */
277 /* List of temp objects containing the stroke. */
278 struct {
279 GPENCIL_tObject *first, *last;
281 /* Batches containing the temp stroke. */
282 blender::gpu::Batch *stroke_batch;
283 blender::gpu::Batch *fill_batch;
286
287 /* Display onion skinning */
289 /* Playing animation */
291 /* simplify settings */
295 /* Use scene lighting or flat shading (global setting). */
297 /* Use physical lights or just ambient lighting. */
299 /* Do we need additional frame-buffers? */
303 /* Some blend mode needs to add negative values.
304 * This is only supported if target texture is signed. */
306 /* Use only lines for multiedit and not active frame. */
308 /* Layer opacity for fading. */
310 /* Opacity for fading gpencil objects. */
312 /* Opacity for fading 3D objects. */
314 /* Mask opacity uniform. */
316 /* X-ray transparency in solid mode. */
318 /* Mask invert uniform. */
320 /* Vertex Paint opacity. */
323
324/* geometry batch cache functions */
326
328 Object *ob,
329 bool is_stroke_order_3d,
332
334 const Object *ob,
335 const bGPDlayer *gpl,
336 const bGPDframe *gpf,
337 GPENCIL_tObject *tgp_ob);
339 int layer_id,
340 bool skip_onion);
341
343 const Object *ob,
345 int onion_id,
346 bool is_used_as_mask,
347 GPENCIL_tObject *tgp_ob);
354 Object *ob,
355 int *ofs,
356 bool is_vertex_mode);
358 int mat_id,
359 struct GPUTexture **r_tex_stroke,
360 struct GPUTexture **r_tex_fill,
361 struct GPUUniformBuf **r_ubo_mat);
362
363void gpencil_light_ambient_add(GPENCIL_LightPool *lightpool, const float color[3]);
370
371/* effects */
373 Object *ob,
374 GPENCIL_tObject *tgp_ob,
375 const bool is_edit_mode);
376
377/* Shaders */
391
392void GPENCIL_shader_free(void);
393
394/* Antialiasing */
395void GPENCIL_antialiasing_init(struct GPENCIL_Data *vedata);
396void GPENCIL_antialiasing_draw(struct GPENCIL_Data *vedata);
397
398/* main functions */
399void GPENCIL_engine_init(void *vedata);
400void GPENCIL_cache_init(void *vedata);
401void GPENCIL_cache_populate(void *vedata, struct Object *ob);
402void GPENCIL_cache_finish(void *vedata);
403void GPENCIL_draw_scene(void *vedata);
404
405/* render */
406
411 struct RenderEngine *engine,
412 struct RenderLayer *render_layer,
413 const struct Depsgraph *depsgraph,
414 const rcti *rect);
415void GPENCIL_render_to_image(void *vedata,
416 struct RenderEngine *engine,
417 struct RenderLayer *render_layer,
418 const rcti *rect);
419
420/* Draw Data. */
421void gpencil_light_pool_free(void *storage);
422void gpencil_material_pool_free(void *storage);
Low-level operations for grease pencil.
unsigned int BLI_bitmap
Definition BLI_bitmap.h:17
struct GPUShader GPUShader
static btDbvtVolume bounds(btDbvtNode **leaves, int count)
Definition btDbvt.cpp:299
EvaluationStage stage
Definition deg_eval.cc:83
const Depsgraph * depsgraph
#define GPENCIL_MATERIAL_BUFFER_LEN
#define GPENCIL_LIGHT_BUFFER_LEN
struct GPENCIL_Data GPENCIL_Data
void GPENCIL_antialiasing_draw(struct GPENCIL_Data *vedata)
struct GPUShader * GPENCIL_shader_fx_composite_get(void)
struct GPUShader * GPENCIL_shader_mask_invert_get(void)
struct GPUShader * GPENCIL_shader_fx_transform_get(void)
GPENCIL_ViewLayerData * GPENCIL_view_layer_data_ensure(void)
void gpencil_vfx_cache_populate(GPENCIL_Data *vedata, Object *ob, GPENCIL_tObject *tgp_ob, const bool is_edit_mode)
void gpencil_material_resources_get(GPENCIL_MaterialPool *first_pool, int mat_id, struct GPUTexture **r_tex_stroke, struct GPUTexture **r_tex_fill, struct GPUUniformBuf **r_ubo_mat)
struct GPENCIL_tVfx GPENCIL_tVfx
void gpencil_light_pool_populate(GPENCIL_LightPool *lightpool, Object *ob)
struct GPENCIL_tObject GPENCIL_tObject
GPENCIL_LightPool * gpencil_light_pool_add(GPENCIL_PrivateData *pd)
void GPENCIL_engine_init(void *vedata)
struct GPENCIL_FramebufferList GPENCIL_FramebufferList
void GPENCIL_antialiasing_init(struct GPENCIL_Data *vedata)
struct GPUShader * GPENCIL_shader_fx_shadow_get(void)
GPENCIL_tLayer * grease_pencil_layer_cache_get(GPENCIL_tObject *tgp_ob, int layer_id, bool skip_onion)
struct GPUShader * GPENCIL_shader_fx_blur_get(void)
void GPENCIL_cache_init(void *vedata)
GPENCIL_tObject * gpencil_object_cache_add(GPENCIL_PrivateData *pd, Object *ob, bool is_stroke_order_3d, blender::Bounds< float3 > bounds)
struct GPUShader * GPENCIL_shader_depth_merge_get(void)
void GPENCIL_cache_finish(void *vedata)
struct GPENCIL_ViewLayerData GPENCIL_ViewLayerData
void GPENCIL_cache_populate(void *vedata, struct Object *ob)
GPENCIL_MaterialPool * gpencil_material_pool_create(GPENCIL_PrivateData *pd, Object *ob, int *ofs, bool is_vertex_mode)
struct GPUShader * GPENCIL_shader_fx_glow_get(void)
struct GPENCIL_MaterialPool GPENCIL_MaterialPool
struct GPUShader * GPENCIL_shader_fx_rim_get(void)
struct GpencilBatchCache * gpencil_batch_cache_get(struct Object *ob, int cfra)
GPENCIL_tLayer * grease_pencil_layer_cache_add(GPENCIL_PrivateData *pd, const Object *ob, const blender::bke::greasepencil::Layer &layer, int onion_id, bool is_used_as_mask, GPENCIL_tObject *tgp_ob)
struct GPENCIL_PassList GPENCIL_PassList
struct GPENCIL_tLayer GPENCIL_tLayer
GPENCIL_LightPool * gpencil_light_pool_create(GPENCIL_PrivateData *pd, Object *ob)
void gpencil_light_pool_free(void *storage)
void GPENCIL_shader_free(void)
struct GPUShader * GPENCIL_shader_layer_blend_get(void)
void GPENCIL_render_init(struct GPENCIL_Data *ved, struct RenderEngine *engine, struct RenderLayer *render_layer, const struct Depsgraph *depsgraph, const rcti *rect)
struct GPENCIL_StorageList GPENCIL_StorageList
void gpencil_material_pool_free(void *storage)
struct GPUShader * GPENCIL_shader_fx_colorize_get(void)
void gpencil_object_cache_sort(GPENCIL_PrivateData *pd)
struct GPENCIL_LightPool GPENCIL_LightPool
DrawEngineType draw_engine_gpencil_type
struct GPENCIL_TextureList GPENCIL_TextureList
GPENCIL_tLayer * gpencil_layer_cache_add(GPENCIL_PrivateData *pd, const Object *ob, const bGPDlayer *gpl, const bGPDframe *gpf, GPENCIL_tObject *tgp_ob)
void gpencil_light_ambient_add(GPENCIL_LightPool *lightpool, const float color[3])
struct GPUShader * GPENCIL_shader_fx_pixelize_get(void)
struct GPUShader * GPENCIL_shader_geometry_get(void)
void GPENCIL_draw_scene(void *vedata)
void GPENCIL_render_to_image(void *vedata, struct RenderEngine *engine, struct RenderLayer *render_layer, const rcti *rect)
struct GPENCIL_PrivateData GPENCIL_PrivateData
struct GPUShader * GPENCIL_shader_antialiasing(int stage)
struct gpLight gpLight
struct GPENCIL_TextureList * txl
struct GPENCIL_PassList * psl
struct GPENCIL_StorageList * stl
struct GPENCIL_FramebufferList * fbl
struct GPUFrameBuffer * smaa_weight_fb
struct GPUFrameBuffer * render_fb
struct GPUFrameBuffer * smaa_edge_fb
struct GPUFrameBuffer * snapshot_fb
struct GPUFrameBuffer * mask_fb
struct GPUFrameBuffer * gpencil_fb
struct GPUFrameBuffer * object_fb
struct GPUFrameBuffer * layer_fb
gpLight light_data[GPENCIL_LIGHT_BUFFER_LEN]
struct GPUUniformBuf * ubo
gpMaterial mat_data[GPENCIL_MATERIAL_BUFFER_LEN]
struct GPUTexture * tex_fill[GPENCIL_MATERIAL_BUFFER_LEN]
struct GPUUniformBuf * ubo
struct GPENCIL_MaterialPool * next
struct GPUTexture * tex_stroke[GPENCIL_MATERIAL_BUFFER_LEN]
struct DRWPass * mask_invert_ps
struct DRWPass * smaa_weight_ps
struct DRWPass * merge_depth_ps
struct DRWPass * composite_ps
struct DRWPass * smaa_resolve_ps
struct DRWPass * smaa_edge_ps
float object_bound_mat[4][4]
GPENCIL_LightPool * last_light_pool
struct BLI_memblock * gp_vfx_pool
GPUTexture * scene_depth_tx
struct bGPDstroke * sbuffer_stroke
struct BLI_memblock * gp_layer_pool
GPUTexture * color_object_tx
GPENCIL_LightPool * shadeless_light_pool
GPUTexture * smaa_weight_tx
struct bGPDlayer * sbuffer_layer
struct ViewLayer * view_layer
struct GPENCIL_PrivateData::@202 tobjects_infront
struct BLI_memblock * gp_maskbit_pool
blender::gpu::Batch * fill_batch
struct BLI_memblock * gp_object_pool
GPENCIL_tObject * first
blender::gpu::Batch * stroke_batch
GPENCIL_LightPool * global_light_pool
struct GPENCIL_PrivateData::@203 sbuffer_tobjects
struct BLI_memblock * gp_material_pool
struct View3D * v3d
struct GPENCIL_PrivateData::@202 tobjects
GPUFrameBuffer * scene_fb
struct Scene * scene
GPUTexture * smaa_edge_tx
GPUTexture * reveal_layer_tx
struct bGPdata * sbuffer_gpd
GPUTexture * color_layer_tx
struct BLI_memblock * gp_light_pool
GPENCIL_MaterialPool * last_material_pool
GPUTexture * reveal_object_tx
struct GPENCIL_PrivateData * pd
struct GPUTexture * snapshot_reveal_tx
struct GPUTexture * smaa_area_tx
struct GPUTexture * snapshot_depth_tx
struct GPUTexture * snapshot_color_tx
struct GPUTexture * smaa_search_tx
struct GPUTexture * render_depth_tx
struct GPUTexture * render_color_tx
struct GPUTexture * dummy_texture
struct BLI_memblock * gp_vfx_pool
struct BLI_memblock * gp_material_pool
struct BLI_memblock * gp_maskbit_pool
struct BLI_memblock * gp_light_pool
struct BLI_memblock * gp_layer_pool
struct BLI_memblock * gp_object_pool
DRWShadingGroup * base_shgrp
BLI_bitmap * mask_invert_bits
BLI_bitmap * mask_bits
struct GPENCIL_tLayer * next
float plane_mat[4][4]
GPENCIL_tLayer * last
struct GPENCIL_tObject::@201 vfx
struct GPENCIL_tObject * next
GPENCIL_tVfx * first
GPENCIL_tLayer * first
struct GPENCIL_tObject::@200 layers
GPUFrameBuffer ** target_fb
DRWPass * vfx_ps
struct GPENCIL_tVfx * next