[Bf-blender-cvs] [da9dc1518f3] temp-greasepencil-vfx: Refactor Effects loop to reduce complexity
Antonio Vazquez
noreply at git.blender.org
Mon Jul 2 12:42:58 CEST 2018
Commit: da9dc1518f3e18bf15b380665f37626e4e2b4f06
Author: Antonio Vazquez
Date: Mon Jul 2 10:48:35 2018 +0200
Branches: temp-greasepencil-vfx
https://developer.blender.org/rBda9dc1518f3e18bf15b380665f37626e4e2b4f06
Refactor Effects loop to reduce complexity
This is the first step to allow multiple effects of the same type.
===================================================================
M source/blender/draw/engines/gpencil/gpencil_shader_fx.c
M source/blender/makesdna/DNA_shader_fx_types.h
===================================================================
diff --git a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
index ce47c7d4b63..fd19083013b 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
@@ -247,7 +247,7 @@ static void DRW_gpencil_fx_colorize(
DRW_shgroup_uniform_int(fx_shgrp, "mode", &stl->fx[ob_idx].fx_colorize.mode, 1);
DRW_shgroup_uniform_float(fx_shgrp, "factor", &stl->fx[ob_idx].fx_colorize.factor, 1);
- cache->fx_colorize_sh = fx_shgrp;
+ fxd->runtime.fx_sh = fx_shgrp;
}
/* Flip FX */
@@ -284,7 +284,7 @@ static void DRW_gpencil_fx_flip(
DRW_shgroup_uniform_vec2(fx_shgrp, "wsize", DRW_viewport_size_get(), 1);
- cache->fx_flip_sh = fx_shgrp;
+ fxd->runtime.fx_sh = fx_shgrp;
}
/* Light FX */
@@ -342,7 +342,7 @@ static void DRW_gpencil_fx_light(
DRW_shgroup_uniform_float(fx_shgrp, "pixelsize", &U.pixelsize, 1);
DRW_shgroup_uniform_float(fx_shgrp, "pixfactor", &gpd->pixfactor, 1);
- cache->fx_light_sh = fx_shgrp;
+ fxd->runtime.fx_sh = fx_shgrp;
}
/* Pixelate FX */
@@ -381,7 +381,7 @@ static void DRW_gpencil_fx_pixel(
DRW_shgroup_uniform_float(fx_shgrp, "pixelsize", &U.pixelsize, 1);
DRW_shgroup_uniform_float(fx_shgrp, "pixfactor", &gpd->pixfactor, 1);
- cache->fx_pixel_sh = fx_shgrp;
+ fxd->runtime.fx_sh = fx_shgrp;
}
/* Rim FX */
@@ -422,7 +422,7 @@ static void DRW_gpencil_fx_rim(
DRW_shgroup_uniform_float(fx_shgrp, "pixelsize", &U.pixelsize, 1);
DRW_shgroup_uniform_float(fx_shgrp, "pixfactor", &gpd->pixfactor, 1);
- cache->fx_rim_sh = fx_shgrp;
+ fxd->runtime.fx_sh = fx_shgrp;
}
/* Swirl FX */
@@ -467,7 +467,7 @@ static void DRW_gpencil_fx_swirl(
DRW_shgroup_uniform_float(fx_shgrp, "pixelsize", &U.pixelsize, 1);
DRW_shgroup_uniform_float(fx_shgrp, "pixfactor", &gpd->pixfactor, 1);
- cache->fx_swirl_sh = fx_shgrp;
+ fxd->runtime.fx_sh = fx_shgrp;
}
/* Wave Distorsion FX */
@@ -500,7 +500,7 @@ static void DRW_gpencil_fx_wave(
DRW_shgroup_uniform_int(fx_shgrp, "orientation", &stl->fx[ob_idx].fx_wave.orientation, 1);
DRW_shgroup_uniform_vec2(fx_shgrp, "wsize", DRW_viewport_size_get(), 1);
- cache->fx_wave_sh = fx_shgrp;
+ fxd->runtime.fx_sh = fx_shgrp;
}
/* ************************************************************** */
@@ -607,9 +607,13 @@ void DRW_gpencil_fx_prepare(
/* helper to draw one FX pass and do ping-pong copy */
static void gpencil_draw_fx_pass(GPENCIL_e_data *e_data,
- DRWPass *fxpass, DRWPass *copypass,
- GPENCIL_FramebufferList *fbl, DRWShadingGroup *shgrp)
+ GPENCIL_PassList *psl, GPENCIL_FramebufferList *fbl,
+ DRWShadingGroup *shgrp)
{
+ if (shgrp == NULL) {
+ return;
+ }
+
static float clearcol[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
GPU_framebuffer_bind(fbl->temp_fb_b);
@@ -617,7 +621,7 @@ static void gpencil_draw_fx_pass(GPENCIL_e_data *e_data,
/* draw effect pass in temp texture (B) using as source the previous image
* existing in the other temp texture (A) */
- DRW_draw_pass_subset(fxpass, shgrp, shgrp);
+ DRW_draw_pass_subset(psl->fx_shader_pass, shgrp, shgrp);
/* copy pass from b to a for ping-pong frame buffers */
e_data->input_depth_tx = e_data->temp_depth_tx_b;
@@ -625,14 +629,19 @@ static void gpencil_draw_fx_pass(GPENCIL_e_data *e_data,
GPU_framebuffer_bind(fbl->temp_fb_a);
GPU_framebuffer_clear_color_depth(fbl->temp_fb_a, clearcol, 1.0f);
- DRW_draw_pass(copypass);
+ DRW_draw_pass(psl->mix_pass_noblend);
}
/* helper to manage gaussian blur passes */
static void gpencil_blur_passes(struct GPENCIL_e_data *e_data,
struct GPENCIL_Data *vedata,
- struct tGPencilObjectCache *cache)
+ struct tGPencilObjectCache *cache,
+ struct DRWShadingGroup *shgrp)
{
+ if (shgrp == NULL) {
+ return;
+ }
+
GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
GPENCIL_FramebufferList *fbl = ((GPENCIL_Data *)vedata)->fbl;
@@ -654,17 +663,13 @@ static void gpencil_blur_passes(struct GPENCIL_e_data *e_data,
if (bx > 0) {
stl->fx[ob_idx].fx_blur.radius[0] = bx;
stl->fx[ob_idx].fx_blur.radius[1] = 0;
- gpencil_draw_fx_pass(e_data, psl->fx_shader_pass,
- psl->mix_pass_noblend,
- fbl, cache->fx_blur_sh);
+ gpencil_draw_fx_pass(e_data, psl, fbl, shgrp);
}
/* vertical */
if (by > 0) {
stl->fx[ob_idx].fx_blur.radius[0] = 0;
stl->fx[ob_idx].fx_blur.radius[1] = by;
- gpencil_draw_fx_pass(e_data, psl->fx_shader_pass,
- psl->mix_pass_noblend,
- fbl, cache->fx_blur_sh);
+ gpencil_draw_fx_pass(e_data, psl, fbl, shgrp);
}
}
}
@@ -679,63 +684,57 @@ void DRW_gpencil_fx_draw(struct GPENCIL_e_data *e_data,
Object *ob = cache->ob;
/* loop FX modifiers */
- for (ShaderFxData *md = ob->shader_fx.first; md; md = md->next) {
- if (effect_is_active(ob, md, stl->storage->is_render)) {
- switch (md->type) {
+ for (ShaderFxData *fx = ob->shader_fx.first; fx; fx = fx->next) {
+ if (effect_is_active(ob, fx, stl->storage->is_render)) {
+ switch (fx->type) {
case eShaderFxType_Blur:
- if (cache->fx_blur_sh) {
- gpencil_blur_passes(e_data, vedata, cache);
- }
+ {
+ BlurShaderFxData * fxd = (BlurShaderFxData *)fx;
+ gpencil_blur_passes(e_data, vedata, cache, fxd->runtime.fx_sh);
break;
+ }
case eShaderFxType_Colorize:
- if (cache->fx_colorize_sh) {
- gpencil_draw_fx_pass(e_data, psl->fx_shader_pass,
- psl->mix_pass_noblend,
- fbl, cache->fx_colorize_sh);
- }
+ {
+ ColorizeShaderFxData * fxd = (ColorizeShaderFxData *)fx;
+ gpencil_draw_fx_pass(e_data, psl, fbl, fxd->runtime.fx_sh);
break;
+ }
case eShaderFxType_Flip:
- if (cache->fx_flip_sh) {
- gpencil_draw_fx_pass(e_data, psl->fx_shader_pass,
- psl->mix_pass_noblend,
- fbl, cache->fx_flip_sh);
- }
+ {
+ FlipShaderFxData *fxd = (FlipShaderFxData *)fx;
+ gpencil_draw_fx_pass(e_data, psl, fbl, fxd->runtime.fx_sh);
break;
+ }
case eShaderFxType_Light:
- if (cache->fx_light_sh) {
- gpencil_draw_fx_pass(e_data, psl->fx_shader_pass,
- psl->mix_pass_noblend,
- fbl, cache->fx_light_sh);
- }
+ {
+ LightShaderFxData *fxd = (LightShaderFxData *)fx;
+ gpencil_draw_fx_pass(e_data, psl, fbl, fxd->runtime.fx_sh);
break;
+ }
case eShaderFxType_Pixel:
- if (cache->fx_pixel_sh) {
- gpencil_draw_fx_pass(e_data, psl->fx_shader_pass,
- psl->mix_pass_noblend,
- fbl, cache->fx_pixel_sh);
- }
+ {
+ PixelShaderFxData *fxd = (PixelShaderFxData *)fx;
+ gpencil_draw_fx_pass(e_data, psl, fbl, fxd->runtime.fx_sh);
break;
+ }
case eShaderFxType_Rim:
- if (cache->fx_rim_sh) {
- gpencil_draw_fx_pass(e_data, psl->fx_shader_pass,
- psl->mix_pass_noblend,
- fbl, cache->fx_rim_sh);
- }
+ {
+ RimShaderFxData *fxd = (RimShaderFxData *)fx;
+ gpencil_draw_fx_pass(e_data, psl, fbl, fxd->runtime.fx_sh);
break;
+ }
case eShaderFxType_Swirl:
- if (cache->fx_swirl_sh) {
- gpencil_draw_fx_pass(e_data, psl->fx_shader_pass,
- psl->mix_pass_noblend,
- fbl, cache->fx_swirl_sh);
- }
+ {
+ SwirlShaderFxData * fxd = (SwirlShaderFxData *)fx;
+ gpencil_draw_fx_pass(e_data, psl, fbl, fxd->runtime.fx_sh);
break;
+ }
case eShaderFxType_Wave:
- if (cache->fx_wave_sh) {
- gpencil_draw_fx_pass(e_data, psl->fx_shader_pass,
- psl->mix_pass_noblend,
- fbl, cache->fx_wave_sh);
- }
+ {
+ WaveShaderFxData *fxd = (WaveShaderFxData *)fx;
+ gpencil_draw_fx_pass(e_data, psl, fbl, fxd->runtime.fx_sh);
break;
+ }
default:
break;
}
diff --git a/source/blender/makesdna/DNA_shader_fx_types.h b/source/blender/makesdna/DNA_shader_fx_types.h
index 483f0250542..09e59419474 100644
--- a/source/blender/makesdna/DNA_shader_fx_types.h
+++ b/source/blender/makesdna/DNA_shader_fx_types.h
@@ -28,6 +28,8 @@
#include "DNA_defs.h"
#include "DNA_listBase.h"
+struct DRWShadingGroup;
+
/* WARNING ALERT! TYPEDEF VALUES ARE WRITTEN IN FILES! SO DO NOT CHANGE!
* (ONLY ADD NEW ITEMS AT THE END)
*/
@@ -69,6 +71,11 @@ typedef struct ShaderFxData {
char *error;
} ShaderFxData;
+/* Runtime temp data */
+typedef struct ShaderFxData_runtime {
+ struct DRWShadingGroup *fx_sh;
+} ShaderFxData_runtime;
+
typedef struct BlurShaderFxData {
ShaderFxData shaderfx;
int radius[2];
@@ -76,6 +83,7 @@ typedef struct BlurShaderFxData {
int samples; /* number of samples */
float coc; /* circle of confusion */
char pad[4];
+ ShaderFxData_runtime runtime;
} BlurShaderFxData;
typedef enum eBlurShaderFx_Flag {
@@ -90,6 +98,7 @@ typedef struct ColorizeShaderFxData {
float factor;
int flag; /* flags */
char pad[4];
+ ShaderFxData_runtime runtime;
} ColorizeShaderFxData;
typedef enum ColorizeShaderFxModes {
@@ -99,16 +108,27 @@ typedef enum ColorizeShaderFxModes {
eShaderFxColorizeMode_Custom = 3,
} ColorizeShaderFxModes;
+typedef struct FlipShaderFxData {
+ ShaderFxData shaderfx;
+ int flag; /* flags */
+ char pad[4];
+ ShaderFxData_runtime runtime;
+} FlipShaderFxData;
-typedef struct WaveShaderFxData {
+typedef enum eFlipShaderFx_Flag {
+ FX_FLIP_HORIZONTAL = (1 << 0),
+ FX_FLIP_VERTICAL = (1 << 1),
+} eFlipShaderFx_Flag;
+
+typedef struct LightShaderFxData {
ShaderFxData shaderfx;
- float amplitude;
- float period;
- float phase;
- int orientation;
+ struct Object *object;
int flag; /* flags */
+ float energy;
+ float ambient;
char pad[4];
-} WaveShaderFxData;
+ ShaderFxData_runtime runtime;
+} LightShaderFxData;
typedef struct PixelShaderFxData {
ShaderFxData shaderfx;
@@ -116,6 +136,7 @@ typedef struct PixelShaderFxData {
int flag; /* flags */
float rgba[4];
char pad[4];
+ ShaderFxData_runtime runtime;
} PixelShaderFxData;
typedef enum ePixelShaderFx_Flag {
@@ -129,6 +150,7 @@ typedef struct RimShaderFxData {
float rim_rgba[4];
float mask_rgba[4];
i
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list