Page MenuHome

Line Art feature update: Cached calculation for multiple line art modifiers in the same stack
ClosedPublic

Authored by YimingWu (NicksBest) on May 18 2021, 4:21 PM.

Details

Summary

This allows line art to run only once for each modifier stacks, with an option to toggle a specific line art modifier should use cache or re-do their own calculations.

This doesn't really need statistic files because you can just add multiple modifiers and by default the whole modifier stack will only run line art once. There's an Use Cache option on top of line art modifiers (if you have multiple), disable that to have that specific modifier run line art again for maximum flexibility (Chaining and several other options are not separately adjustable when using cache mode).

If need to see cache in action, simply use my 727 test file: https://cloud.blender.org/p/gallery/608da4565f9fe397b1944ba2

Diff Detail

Repository
rB Blender

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes

Seems like you uploaded the wrong patch?
This seems to be the list -> array patch.

Sebastian Parborg (zeddb) requested changes to this revision.May 19 2021, 7:56 PM
This revision now requires changes to proceed.May 19 2021, 7:56 PM

Now it's the correct patch... I must have clicked the wrong one

Updated to include recent naming changes.

Updated to include context.

Updated for latest master

Fix wrong mempool allocation

source/blender/blenkernel/intern/gpencil_modifier.c
206

This is not really global, right?

This is the limit per object modifier stack limit.

So perhaps BKE_gpencil_get_lineart_modifier_limits ?

219

Same as above. But instead of assign you should use set instead.
The get/set combo is used quite a bit in programming so we should change to that so it is obvious that these to are directly related with each other.
BKE_gpencil_set_lineart_modifier_limits

222

Add a BLI_assert check here to check if the modifier we pass really is a LineArt modifier.

228

This name is also not good I think.

To me it seemed like this would check if the cache was populated already or something.

Also I think we can make this a general function, no?
We take the input modifier and use the modifier type from it as the type we are looking for.

Then the function name could be something like:

BKE_gpencil_is_md_first_type_in_stack

Gah... Perhaps a bit overly verbose, I'm open for more naming discussion as I'm not quite happy with what I came up with either.

source/blender/makesrna/intern/rna_gpencil_modifier.c
2936

Used -> Use

2937

No period at the end of the sentence.

Besides that, I also think that this should be a bit more descriptive to that the user can the the description here and know that the result is from the first line art modifier in the stack. So this is per object and not scene global.

YimingWu (NicksBest) marked 6 inline comments as done.

Updated to fix stuff commented.

source/blender/blenloader/intern/versioning_300.c
275 ↗(On Diff #38266)

As discussed in the chat, this shouldn't be here as it has the potential to break older files if you set this to on when loading them.

source/blender/makesdna/DNA_gpencil_modifier_types.h
940

Because we can potentially only compute features lines once per modifier stack (Use Cache), we need to have these override values to ensure that we have the data we need is computed and stored in the cache.

946

Keep a pointer to the render buffer...

source/blender/blenkernel/intern/gpencil_modifier.c
219

You forgot to change global here to modifier

source/blender/makesrna/intern/rna_gpencil_modifier.c
2938

Use cached line art data from the first line art modifier in the stack.
Certain settings will be unavailable when using cached data.

source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
254

This is a bit of a run on sentence.

I think:

This is just a pointer to LineartCache::chain_data_pool, which acts as a cache for line chains.

321

A copy of rb->chains so we have that data available after rb has been destroyed.

327

Hmm, why is this still a TODO shouldn't you know which feature edges you have in the cache?

Shouldn't it just contain the edge types that are in "limit" info data type?

YimingWu (NicksBest) marked 7 inline comments as done.
source/blender/makesdna/DNA_gpencil_modifier_types.h
947

Isn't it better to name it ptr instead of onetime?

As discussed in the chat, the current logic needs some more work as well.

Currently the "limit settings" is used for all modifiers in the stack even if non of them are using the cache.
This means that settings will be changed even if there is no need to. This needs to be fixed.

Fix bake crashing

YimingWu (NicksBest) marked an inline comment as done.Jun 14 2021, 6:30 PM
YimingWu (NicksBest) added inline comments.
source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
327

The TODO is not relevant any more. Removed.

Modifier behaviour restored.

These are proposed UI changes for cache mode.

Note the crease slider placement is to be aligned with later light contour functionality (which is not in this patch at the moment), this way it looks nicer than current placement.

And @Hans Goudey (HooglyBoogly) would you like to give some opinions on the UI changes above? (this patch applies to master)

  • Moved line types into a sub panel so it's more clear
  • Fixed override flags behavior.

I think this looks good from the code side of things now.

However we should probably have one from the UI team take a look at the UI changes before we merge this.
@Hans Goudey (HooglyBoogly) do you have time?

This revision is now accepted and ready to land.Jun 15 2021, 5:39 PM
Hans Goudey (HooglyBoogly) requested changes to this revision.Jun 16 2021, 6:43 AM
Hans Goudey (HooglyBoogly) added inline comments.
source/blender/blenkernel/BKE_gpencil_modifier.h
297

It would help readers if you added a very short comment describing what is stored in here.

source/blender/blenkernel/intern/gpencil_modifier.c
206

Use const arguments.

206

GpencilLineartLimitInfo is a very small struct and should be returned by value, so:

GpencilLineartLimitInfo BKE_gpencil_get_lineart_modifier_limits(const Object *object);

223

No need to use struct here.

240

Use const arguments

255

If this isn't expected to happen, then add an assert to test your assumption.

source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
360

Flip the condition, add the label and then return early instead of indenting the rest of the function.

361

Put these four boolean options in a column, right now they have too much white space between them.

367

Replace these with "Cached from the first line art modifier."

471

Flip the condition, add the label and then return early instead of indenting the rest of the function.

497

Flip the condition, add the label and then return early instead of indenting the rest of the function.

547

"Options" is a very vague name for a panel, I think we can do much better than that.

All of the properties seem to be controlling things related to the source mesh data, so I think "Source Data" would be a good name.

source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
3869

There should be no need for parentheses here.

source/blender/makesrna/intern/rna_gpencil_modifier.c
2936

I think this name is confusing, since it's not the result of the first line art modifier that's cached, since the result is grease pencil data.

It's really the intermediate data from the source meshes that is cached as far as I can tell.

I would suggest calling this "Use Cached Data". It's a bit more vague, but at least it's not misleading.

2937

Similar comment here: What is "Line art data" to the user? Forgetting all of the implementation details. It's probably not what's being cached.

What about "Use cached source object data ..."?

2938

The period for the last sentence is added automatically by the tooltip system.

2938

"when using cached data" is redundant given the previous sentence, and can be removed in my opinion.

This revision now requires changes to proceed.Jun 16 2021, 6:43 AM
YimingWu (NicksBest) marked 17 inline comments as done.Jun 16 2021, 7:46 AM

@Sebastian Parborg (zeddb) Hey would you mind check out some of the wordings here?

And the use_cached_result part may need DNA name changes? I left it as-is, but would like to get your input.

source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
547

I think I'll put it "Geometry Processing", it's more aligned with what those options do.

source/blender/makesrna/intern/rna_gpencil_modifier.c
2936

Or "Use Cache" ? Because the user don't care about what's exactly cached anyway?

2937

Then maybe "Use cached calculation" ?

YimingWu (NicksBest) marked 3 inline comments as done.

Updated to fix stuff in Hans' comment

source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
547

I think the name is ok.

source/blender/makesrna/intern/rna_gpencil_modifier.c
2936

Hmm, I'm also unsure how to name this.
As at a glance all the suggested names doesn't properly convey that the cache is not from the current modifier.

But I can't really come up with something better that is short and to the point.

2937

Maybe we should be more verbose here. What about this:

Only evaluate the scene data once in the first Line Art modifier in the stack. Then reuse that data in this modifier for better performance.

YimingWu (NicksBest) marked an inline comment as done.Jun 16 2021, 1:14 PM
YimingWu (NicksBest) added inline comments.
source/blender/makesrna/intern/rna_gpencil_modifier.c
2937

The problem with this description is that the cache does cache for all modifiers, like when the second modifier selects some line types that the first modifier does not select, both line types will get cached, this description sounds like if you don't select all line types in the first modifier it's not gonna be available later on.

YimingWu (NicksBest) marked 2 inline comments as done.

Updated names and description stuff

With the two inline commends addressed this looks good.


I'm honestly not completely sure that adding the label with the info icon is better than graying out the properties; it's pretty non-standard. But maybe it's a nice way to be more explicit. Anyway, I don't have a strong feeling about that.

source/blender/blenkernel/BKE_gpencil_modifier.h
298

that's gonna -> that will

source/blender/makesrna/intern/rna_gpencil_modifier.c
2938

This can still be simpler IMO:

"Use cached scene data from the first line art modifier in the stack. Certain settings will be unavailable"

This revision is now accepted and ready to land.Jun 16 2021, 3:02 PM

I'm honestly not completely sure that adding the label with the info icon is better than graying out the properties; it's pretty non-standard. But maybe it's a nice way to be more explicit. Anyway, I don't have a strong feeling about that.

It is basically to differentiate from baking.
If we just grayed out when caching, you can't really tell which options are "baked" and used and which are not used when using the cache.

YimingWu (NicksBest) marked an inline comment as done.

Updated to fix wording.