[Bf-blender-cvs] [3d2d9c7c5ab] greasepencil-refactor: GPencil: Refactor: Implement "Use Lights" toggle
Clément Foucault
noreply at git.blender.org
Thu Dec 19 22:39:22 CET 2019
Commit: 3d2d9c7c5ab244491b0d2377849063f078ce6cb5
Author: Clément Foucault
Date: Thu Dec 19 22:38:22 2019 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB3d2d9c7c5ab244491b0d2377849063f078ce6cb5
GPencil: Refactor: Implement "Use Lights" toggle
We use a ubo containing only a white ambient light to simulate no lighting.
===================================================================
M source/blender/draw/engines/gpencil/gpencil_draw_data.c
M source/blender/draw/engines/gpencil/gpencil_engine.c
M source/blender/draw/engines/gpencil/gpencil_engine.h
===================================================================
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_data.c b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
index b030ef3fbf1..e4d45d7ad21 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_data.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
@@ -37,7 +37,6 @@
GPENCIL_LightPool *gpencil_light_pool_add(GPENCIL_PrivateData *pd)
{
GPENCIL_LightPool *lightpool = BLI_memblock_alloc(pd->gp_light_pool);
- lightpool->next = NULL;
lightpool->light_used = 0;
/* Tag light list end. */
lightpool->light_data[0].color[0] = -1.0;
@@ -223,6 +222,23 @@ void gpencil_material_resources_get(GPENCIL_MaterialPool *first_pool,
}
}
+void gpencil_light_ambient_add(GPENCIL_LightPool *lightpool, const float color[3])
+{
+ if (lightpool->light_used >= GPENCIL_LIGHT_BUFFER_LEN) {
+ return;
+ }
+
+ gpLight *gp_light = &lightpool->light_data[lightpool->light_used];
+ gp_light->type = GP_LIGHT_TYPE_SUN;
+ copy_v3_v3(gp_light->color, color);
+ lightpool->light_used++;
+
+ if (lightpool->light_used < GPENCIL_LIGHT_BUFFER_LEN) {
+ /* Tag light list end. */
+ gp_light[1].color[0] = -1.0f;
+ }
+}
+
void gpencil_light_pool_populate(GPENCIL_LightPool *lightpool, Object *ob)
{
Light *la = (Light *)ob->data;
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 9e5ce788b3c..b9fc311e809 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -314,10 +314,13 @@ static void GPENCIL_engine_init_new(void *ved)
stl->pd->scene_depth_tx = stl->pd->draw_depth_only ? txl->dummy_texture : dtxl->depth;
stl->pd->is_render = true; /* TODO */
stl->pd->global_light_pool = gpencil_light_pool_add(stl->pd);
+ stl->pd->shadeless_light_pool = gpencil_light_pool_add(stl->pd);
/* Small HACK: we don't want the global pool to be reused,
* so we set the last light pool to NULL. */
stl->pd->last_light_pool = NULL;
+ gpencil_light_ambient_add(stl->pd->shadeless_light_pool, (float[3]){1.0f, 1.0f, 1.0f});
+
float viewmatinv[4][4];
DRW_view_viewmat_get(NULL, viewmatinv, true);
copy_v3_v3(stl->pd->camera_z_axis, viewmatinv[2]);
@@ -802,6 +805,7 @@ typedef struct gpIterPopulateData {
int mat_ofs;
/* Last material UBO bound. Used to avoid uneeded buffer binding. */
GPUUniformBuffer *ubo_mat;
+ GPUUniformBuffer *ubo_lights;
/* Last texture bound. */
GPUTexture *tex_fill;
GPUTexture *tex_stroke;
@@ -824,7 +828,7 @@ static void gp_layer_cache_populate(bGPDlayer *gpl,
}
GPUUniformBuffer *ubo_mat;
- gpencil_material_resources_get(iter->matpool, 0, NULL, NULL, &ubo_mat);
+ gpencil_material_resources_get(iter->matpool, 0, NULL, NULL, &iter->ubo_mat);
const bool is_stroke_order_3d = (gpd->draw_mode == GP_DRAWMODE_3D) || iter->pd->draw_depth_only;
const bool is_screenspace = (gpd->flag & GP_DATA_STROKE_KEEPTHICKNESS) != 0;
@@ -834,10 +838,14 @@ static void gp_layer_cache_populate(bGPDlayer *gpl,
* Convert to world units (by default, 1 meter = 2000 px). */
float thickness_scale = (is_screenspace) ? -1.0f : (gpd->pixfactor / GPENCIL_PIXEL_FACTOR);
+ const bool use_lights = (gpl->flag & GP_LAYER_USE_LIGHTS) != 0;
+ iter->ubo_lights = (use_lights) ? iter->pd->global_light_pool->ubo :
+ iter->pd->shadeless_light_pool->ubo;
+
struct GPUShader *sh = GPENCIL_shader_geometry_get(&en_data);
iter->grp = DRW_shgroup_create(sh, tgp_layer->geom_ps);
- DRW_shgroup_uniform_block(iter->grp, "gpMaterialBlock", ubo_mat);
- DRW_shgroup_uniform_block(iter->grp, "gpLightBlock", iter->pd->global_light_pool->ubo);
+ DRW_shgroup_uniform_block(iter->grp, "gpLightBlock", iter->ubo_lights);
+ DRW_shgroup_uniform_block(iter->grp, "gpMaterialBlock", iter->ubo_mat);
DRW_shgroup_uniform_texture(iter->grp, "gpFillTexture", iter->tex_fill);
DRW_shgroup_uniform_texture(iter->grp, "gpStrokeTexture", iter->tex_stroke);
DRW_shgroup_uniform_texture(iter->grp, "gpSceneDepthTexture", iter->pd->scene_depth_tx);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index d0556a92c1d..82e46bd5a81 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -175,8 +175,6 @@ typedef struct GPENCIL_MaterialPool {
} GPENCIL_MaterialPool;
typedef struct GPENCIL_LightPool {
- /* Linklist. */
- struct GPENCIL_LightPool *next;
/* GPU representatin of materials. */
gpLight light_data[GPENCIL_LIGHT_BUFFER_LEN];
/* Matching ubo. */
@@ -452,6 +450,8 @@ typedef struct GPENCIL_PrivateData {
GPENCIL_LightPool *last_light_pool;
/* Common lightpool containing all lights in the scene. */
GPENCIL_LightPool *global_light_pool;
+ /* Common lightpool containing one ambient white light. */
+ GPENCIL_LightPool *shadeless_light_pool;
/* Linked list of tObjects. */
struct {
GPENCIL_tObject *first, *last;
@@ -731,6 +731,7 @@ void gpencil_material_resources_get(GPENCIL_MaterialPool *first_pool,
struct GPUTexture **r_tex_fill,
struct GPUUniformBuffer **r_ubo_mat);
/* Meh, TODO fix naming...*/
+void gpencil_light_ambient_add(GPENCIL_LightPool *lightpool, const float color[3]);
void gpencil_light_pool_populate(GPENCIL_LightPool *matpool, Object *ob);
GPENCIL_LightPool *gpencil_light_pool_add(GPENCIL_PrivateData *pd);
GPENCIL_LightPool *gpencil_light_pool_create(GPENCIL_PrivateData *pd, Object *ob);
More information about the Bf-blender-cvs
mailing list