Blender  V2.93
gpencil_engine.h
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 2017, Blender Foundation.
17  */
18 
23 #pragma once
24 
25 #include "DNA_gpencil_types.h"
26 
27 #include "DRW_render.h"
28 
29 #include "BLI_bitmap.h"
30 
31 #include "GPU_batch.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
38 
39 struct GPENCIL_Data;
40 struct GPENCIL_StorageList;
41 struct GPUBatch;
42 struct GpencilBatchCache;
43 struct Object;
44 struct RenderEngine;
45 struct RenderLayer;
46 struct View3D;
47 struct bGPDstroke;
48 
49 /* used to convert pixel scale. */
50 #define GPENCIL_PIXEL_FACTOR 2000.0f
51 
52 /* used to expand VBOs. Size has a big impact in the speed */
53 #define GPENCIL_VBO_BLOCK_SIZE 128
54 
55 #define GP_MAX_MASKBITS 256
56 
57 /* UBO structure. Watch out for padding. Must match GLSL declaration. */
58 typedef struct gpMaterial {
59  float stroke_color[4];
60  float fill_color[4];
61  float fill_mix_color[4];
66  int flag;
68 
69 /* gpMaterial->flag */
70 /* WATCH Keep in sync with GLSL declaration. */
71 #define GP_STROKE_ALIGNMENT_STROKE 1
72 #define GP_STROKE_ALIGNMENT_OBJECT 2
73 #define GP_STROKE_ALIGNMENT_FIXED 3
74 #define GP_STROKE_ALIGNMENT 0x3
75 #define GP_STROKE_OVERLAP (1 << 2)
76 #define GP_STROKE_TEXTURE_USE (1 << 3)
77 #define GP_STROKE_TEXTURE_STENCIL (1 << 4)
78 #define GP_STROKE_TEXTURE_PREMUL (1 << 5)
79 #define GP_STROKE_DOTS (1 << 6)
80 #define GP_STROKE_HOLDOUT (1 << 7)
81 #define GP_FILL_HOLDOUT (1 << 8)
82 #define GP_FILL_TEXTURE_USE (1 << 10)
83 #define GP_FILL_TEXTURE_PREMUL (1 << 11)
84 #define GP_FILL_TEXTURE_CLIP (1 << 12)
85 #define GP_FILL_GRADIENT_USE (1 << 13)
86 #define GP_FILL_GRADIENT_RADIAL (1 << 14)
87 
88 #define GPENCIL_LIGHT_BUFFER_LEN 128
89 
90 /* UBO structure. Watch out for padding. Must match GLSL declaration. */
91 typedef struct gpLight {
92  float color[3], type;
93  float right[3], spotsize;
94  float up[3], spotblend;
95  float forward[4];
96  float position[4];
98 
99 /* gpLight->type */
100 /* WATCH Keep in sync with GLSL declaration. */
101 #define GP_LIGHT_TYPE_POINT 0.0
102 #define GP_LIGHT_TYPE_SPOT 1.0
103 #define GP_LIGHT_TYPE_SUN 2.0
104 #define GP_LIGHT_TYPE_AMBIENT 3.0
105 
108 
109 /* *********** Draw Datas *********** */
110 typedef struct GPENCIL_MaterialPool {
111  /* Linklist. */
113  /* GPU representation of materials. */
115  /* Matching ubo. */
117  /* Texture per material. NULL means none. */
119  struct GPUTexture *tex_stroke[GP_MATERIAL_BUFFER_LEN];
120  /* Number of material used in this pool. */
123 
124 typedef struct GPENCIL_LightPool {
125  /* GPU representation of materials. */
127  /* Matching ubo. */
129  /* Number of light in the pool. */
132 
133 typedef struct GPENCIL_ViewLayerData {
134  /* GPENCIL_tObject */
136  /* GPENCIL_tLayer */
138  /* GPENCIL_tVfx */
140  /* GPENCIL_MaterialPool */
142  /* GPENCIL_LightPool */
144  /* BLI_bitmap */
147 
148 /* *********** GPencil *********** */
149 
150 typedef struct GPENCIL_tVfx {
154  /* Frame-buffer reference since it may not be allocated yet. */
157 
158 typedef struct GPENCIL_tLayer {
171  int layer_id;
173 
174 typedef struct GPENCIL_tObject {
177 
178  struct {
181 
182  struct {
184  } vfx;
185 
186  /* Distance to camera. Used for sorting. */
187  float camera_z;
188  /* Used for stroke thickness scaling. */
190  /* Normal used for shading. Based on view angle. */
191  float plane_normal[3];
192  /* Used for drawing depth merge pass. */
193  float plane_mat[4][4];
194 
196 
197  /* Use Material Holdout. */
199 
201 
202 /* *********** LISTS *********** */
203 typedef struct GPENCIL_StorageList {
206 
207 typedef struct GPENCIL_PassList {
208  /* Composite the main GPencil buffer onto the rendered image. */
210  /* Composite the object depth to the default depth buffer to occlude overlays. */
212  /* Invert mask buffer content. */
214  /* Anti-Aliasing. */
219 
220 typedef struct GPENCIL_FramebufferList {
230 
231 typedef struct GPENCIL_TextureList {
232  /* Dummy texture to avoid errors cause by empty sampler. */
234  /* Snapshot for smoother drawing. */
238  /* Textures used by Antialiasing. */
241  /* Textures used during render. Containing underlying rendered scene. */
245 
246 typedef struct GPENCIL_Data {
247  void *engine_type; /* Required */
253 
254 /* *********** STATIC *********** */
255 typedef struct GPENCIL_PrivateData {
256  /* Pointers copied from GPENCIL_ViewLayerData. */
263  /* Last used material pool. */
265  /* Last used light pool. */
267  /* Common lightpool containing all lights in the scene. */
269  /* Common lightpool containing one ambient white light. */
271  /* Linked list of tObjects. */
272  struct {
275  /* Temp Textures (shared with other engines). */
280  /* Revealage is 1 - alpha */
284  /* Mask texture */
286  /* Anti-Aliasing. */
289  /* Pointer to dtxl->depth */
292  /* Copy of txl->dummy_tx */
294  /* Copy of v3d->shading.single_color. */
296  /* Copy of v3d->shading.color_type or -1 to ignore. */
298  /* Current frame */
299  int cfra;
300  /* If we are rendering for final render (F12).
301  * NOTE: set to false for viewport and opengl rendering (including VSE scene rendering), but set
302  * to true when rendering in `OB_RENDER` shading mode (viewport or opengl rendering) */
303  bool is_render;
304  /* If we are in viewport display (used for VFX). */
306  /* True in selection and auto_depth drawing */
308  /* Is shading set to wireframe. */
310  /* Used by the depth merge step. */
312  float object_bound_mat[4][4];
313  /* Used for computing object distance to camera. */
315  float camera_pos[3];
316  /* Pseudo depth of field parameter. Used to scale blur radius. */
317  float dof_params[2];
318  /* Used for DoF Setup. */
320  /* Copy of draw_ctx->view_layer for convenience. */
322  /* Copy of draw_ctx->scene for convenience. */
323  struct Scene *scene;
324  /* Copy of draw_ctx->vie3d for convenience. */
325  struct View3D *v3d;
326 
327  /* Active object. */
329  /* Object being in draw mode. */
331  /* Layer to append the temp stroke to. */
333  /* Temporary stroke currently being drawn. */
335  /* List of temp objects containing the stroke. */
336  struct {
339  /* Batches containing the temp stroke. */
344 
345  /* Display onion skinning */
346  bool do_onion;
347  /* Playing animation */
348  bool playing;
349  /* simplify settings */
353  /* Use scene lighting or flat shading (global setting). */
355  /* Use physical lights or just ambient lighting. */
357  /* Do we need additional frame-buffers? */
361  /* Some blend mode needs to add negative values.
362  * This is only supported if target texture is signed. */
364  /* Use only lines for multiedit and not active frame. */
366  /* Layer opacity for fading. */
368  /* Opacity for fading gpencil objects. */
370  /* Opacity for fading 3D objects. */
372  /* Mask opacity uniform. */
374  /* Xray transparency in solid mode. */
375  float xray_alpha;
376  /* Mask invert uniform. */
378  /* Vertex Paint opacity. */
381 
382 /* geometry batch cache functions */
383 struct GpencilBatchCache *gpencil_batch_cache_get(struct Object *ob, int cfra);
384 
387 
389  const Object *ob,
390  const bGPDlayer *gpl,
391  const bGPDframe *gpf,
392  GPENCIL_tObject *tgp_ob);
394 
397  int mat_id,
398  struct GPUTexture **r_tex_stroke,
399  struct GPUTexture **r_tex_fill,
400  struct GPUUniformBuf **r_ubo_mat);
401 
402 void gpencil_light_ambient_add(GPENCIL_LightPool *lightpool, const float color[3]);
406 
407 /* effects */
409 
410 /* Shaders */
424 
425 void GPENCIL_shader_free(void);
426 
427 /* Antialiasing */
428 void GPENCIL_antialiasing_init(struct GPENCIL_Data *vedata);
429 void GPENCIL_antialiasing_draw(struct GPENCIL_Data *vedata);
430 
431 /* main functions */
432 void GPENCIL_engine_init(void *vedata);
433 void GPENCIL_cache_init(void *vedata);
434 void GPENCIL_cache_populate(void *vedata, struct Object *ob);
435 void GPENCIL_cache_finish(void *vedata);
436 void GPENCIL_draw_scene(void *vedata);
437 
438 /* render */
440  struct RenderEngine *engine,
441  struct RenderLayer *render_layer,
442  const struct Depsgraph *depsgraph,
443  const rcti *rect);
444 void GPENCIL_render_to_image(void *vedata,
445  struct RenderEngine *engine,
446  struct RenderLayer *render_layer,
447  const rcti *rect);
448 
449 /* Draw Data. */
450 void gpencil_light_pool_free(void *storage);
451 void gpencil_material_pool_free(void *storage);
453 #ifdef __cplusplus
454 }
455 #endif
#define BLI_STATIC_ASSERT_ALIGN(st, align)
Definition: BLI_assert.h:89
unsigned int BLI_bitmap
Definition: BLI_bitmap.h:32
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
#define GP_MATERIAL_BUFFER_LEN
GPUBatch
Definition: GPU_batch.h:93
struct GPUFrameBuffer GPUFrameBuffer
struct GPUShader GPUShader
Definition: GPU_shader.h:33
struct GPUTexture GPUTexture
Definition: GPU_texture.h:33
struct GPUUniformBuf GPUUniformBuf
EvaluationStage stage
Definition: deg_eval.cc:96
const Depsgraph * depsgraph
struct GPENCIL_Data GPENCIL_Data
struct GPUShader * GPENCIL_shader_fx_colorize_get(void)
void gpencil_vfx_cache_populate(GPENCIL_Data *vedata, Object *ob, GPENCIL_tObject *tgp_ob)
void GPENCIL_antialiasing_draw(struct GPENCIL_Data *vedata)
struct GPUShader * GPENCIL_shader_layer_blend_get(void)
struct GPUShader * GPENCIL_shader_fx_composite_get(void)
GPENCIL_tLayer * gpencil_layer_cache_get(GPENCIL_tObject *tgp_ob, int number)
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
void GPENCIL_engine_init(void *vedata)
struct GPENCIL_FramebufferList GPENCIL_FramebufferList
void GPENCIL_antialiasing_init(struct GPENCIL_Data *vedata)
struct GpencilBatchCache * gpencil_batch_cache_get(struct Object *ob, int cfra)
GPENCIL_ViewLayerData * GPENCIL_view_layer_data_ensure(void)
struct GPUShader * GPENCIL_shader_mask_invert_get(void)
void GPENCIL_cache_init(void *vedata)
void GPENCIL_cache_finish(void *vedata)
GPENCIL_LightPool * gpencil_light_pool_add(GPENCIL_PrivateData *pd)
struct GPENCIL_ViewLayerData GPENCIL_ViewLayerData
void GPENCIL_cache_populate(void *vedata, struct Object *ob)
GPENCIL_tLayer * gpencil_layer_cache_add(GPENCIL_PrivateData *pd, const Object *ob, const bGPDlayer *gpl, const bGPDframe *gpf, GPENCIL_tObject *tgp_ob)
struct gpMaterial gpMaterial
struct GPENCIL_MaterialPool GPENCIL_MaterialPool
struct GPUShader * GPENCIL_shader_fx_shadow_get(void)
struct GPENCIL_PassList GPENCIL_PassList
struct GPENCIL_tLayer GPENCIL_tLayer
void gpencil_light_pool_free(void *storage)
struct GPUShader * GPENCIL_shader_fx_transform_get(void)
void GPENCIL_shader_free(void)
#define GPENCIL_LIGHT_BUFFER_LEN
GPENCIL_LightPool * gpencil_light_pool_create(GPENCIL_PrivateData *pd, Object *ob)
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_rim_get(void)
struct GPUShader * GPENCIL_shader_fx_pixelize_get(void)
struct GPUShader * GPENCIL_shader_fx_blur_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_MaterialPool * gpencil_material_pool_create(GPENCIL_PrivateData *pd, Object *ob, int *ofs)
struct GPUShader * GPENCIL_shader_antialiasing(int stage)
void gpencil_light_ambient_add(GPENCIL_LightPool *lightpool, const float color[3])
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 gpLight gpLight
struct GPUShader * GPENCIL_shader_fx_glow_get(void)
struct GPUShader * GPENCIL_shader_depth_merge_get(void)
struct GPENCIL_PrivateData GPENCIL_PrivateData
GPENCIL_tObject * gpencil_object_cache_add(GPENCIL_PrivateData *pd, Object *ob)
void * engine_type
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
struct GPUUniformBuf * ubo
struct GPENCIL_MaterialPool * next
gpMaterial mat_data[GP_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
GPUTexture * reveal_tx
struct GPENCIL_PrivateData::@212 sbuffer_tobjects
struct BLI_memblock * gp_maskbit_pool
struct BLI_memblock * gp_object_pool
GPUTexture * dummy_tx
GPENCIL_tObject * first
GPUTexture * color_tx
GPUTexture * mask_tx
GPENCIL_LightPool * global_light_pool
GPUTexture * depth_tx
struct BLI_memblock * gp_material_pool
struct View3D * v3d
struct GPENCIL_PrivateData::@211 tobjects_infront
struct GPENCIL_PrivateData::@211 tobjects
GPUFrameBuffer * scene_fb
struct Scene * scene
GPENCIL_tObject * last
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
DRWPass * geom_ps
BLI_bitmap * mask_bits
DRWPass * blend_ps
struct GPENCIL_tLayer * next
float plane_mat[4][4]
struct GPENCIL_tObject::@210 vfx
GPENCIL_tLayer * last
struct GPENCIL_tObject::@209 layers
struct GPENCIL_tObject * next
float plane_normal[3]
GPENCIL_tVfx * first
GPENCIL_tLayer * first
GPUFrameBuffer ** target_fb
DRWPass * vfx_ps
struct GPENCIL_tVfx * next
float type
float up[3]
float spotsize
float forward[4]
float spotblend
float position[4]
float right[3]
float color[3]
float fill_uv_transform[3][2]
float alignment_rot_cos
float alignment_rot_sin
float stroke_texture_mix
float stroke_color[4]
float fill_texture_mix
float fill_mix_color[4]
float stroke_u_scale
float fill_color[4]