diff options
author | Antonio Vazquez <blendergit@gmail.com> | 2019-07-30 20:42:43 +0300 |
---|---|---|
committer | Antonio Vazquez <blendergit@gmail.com> | 2019-07-30 20:43:17 +0300 |
commit | 9d7a03ab1177f7227653ec691e10ce328771a4eb (patch) | |
tree | aa63a5cfda5c0f2527fefeed15325d67ea5eac0d /source/blender/gpencil_modifiers/intern | |
parent | 28bd15cdf01f1a0ad14a320bfe91a16d3f039ba4 (diff) |
Fix T67939: GPencil Noise modifier step is ignored in render
The value of the step was calculated using a variable that was removed when the render frame change.
Now, the step is calculated using the modulus of the current frame and recalculate noise only if the remainder that results from performing integer division is equal to 0.
To calculate current frame, the first used frame is calculated to adjust real frame range.
This approach is more stable in viewport and render.
Diffstat (limited to 'source/blender/gpencil_modifiers/intern')
-rw-r--r-- | source/blender/gpencil_modifiers/intern/MOD_gpencilnoise.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilnoise.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilnoise.c index 54218da9eb5..e0139eac6b2 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencilnoise.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilnoise.c @@ -85,6 +85,21 @@ static bool dependsOnTime(GpencilModifierData *md) return (mmd->flag & GP_NOISE_USE_RANDOM) != 0; } +/* Get the lower number of frame for all layers. */ +static int get_lower_frame(bGPdata *gpd) +{ + int init = 99999; + for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { + if (gpl->frames.first) { + bGPDframe *gpf = gpl->frames.first; + if (gpf->framenum < init) { + init = gpf->framenum; + } + } + } + return init; +} + /* aply noise effect based on stroke direction */ static void deformStroke( GpencilModifierData *md, Depsgraph *depsgraph, Object *ob, bGPDlayer *gpl, bGPDstroke *gps) @@ -103,6 +118,7 @@ static void deformStroke( Object *object_eval = DEG_get_evaluated_object(depsgraph, ob); GpencilModifierData *md_eval = BKE_gpencil_modifiers_findByName(object_eval, md->name); NoiseGpencilModifierData *mmd_eval = (NoiseGpencilModifierData *)md_eval; + bGPdata *gpd = (bGPdata *)ob->data; /* Random generator, only init once. (it uses eval to get same value in render) */ if (mmd_eval->rng == NULL) { @@ -110,6 +126,9 @@ static void deformStroke( rng_seed ^= POINTER_AS_UINT(mmd); mmd_eval->rng = BLI_rng_new(rng_seed); mmd->rng = mmd_eval->rng; + /* Get lower frame number */ + mmd_eval->scene_frame = get_lower_frame(gpd); + mmd->scene_frame = mmd_eval->scene_frame; } if (!is_stroke_affected_by_modifier(ob, @@ -176,19 +195,17 @@ static void deformStroke( sub_v3_v3v3(vec1, &pt1->x, &pt0->x); } vran = len_v3(vec1); - /* vector orthogonal to normal */ + /* Vector orthogonal to normal. */ cross_v3_v3v3(vec2, vec1, normal); normalize_v3(vec2); - /* use random noise */ + /* Use random noise */ if (mmd->flag & GP_NOISE_USE_RANDOM) { - sc_diff = abs(mmd->scene_frame - sc_frame); - /* only recalc if the gp frame change or the number of scene frames is bigger than step */ - if ((!gpl->actframe) || (mmd->gp_frame != gpl->actframe->framenum) || - (sc_diff >= mmd->step)) { + sc_diff = abs(sc_frame - mmd->scene_frame) % mmd->step; + /* Only recalc if the gp frame change or is a step. */ + if ((mmd->gp_frame != sc_frame) && (sc_diff == 0)) { vran = mmd->vrand1 = BLI_rng_get_float(mmd->rng); vdir = mmd->vrand2 = BLI_rng_get_float(mmd->rng); - mmd->gp_frame = gpl->actframe->framenum; - mmd->scene_frame = sc_frame; + mmd->gp_frame = sc_frame; } else { vran = mmd->vrand1; |