Page MenuHome

Curves: Draw legacy hair particle system as curves object. (WIP)
Needs ReviewPublic

Authored by Jacques Lucke (JacquesLucke) on May 13 2022, 12:10 PM.

Details

Summary

The goal is to convert the legacy hair system to the new curves object at run-time for drawing. This allows us to get rid of all drawing code that was specific to hair particle systems. Then we can focus on improving the rendering of the curves object without too much code duplication.

Previously, render engines had to iterate over all particle systems in an object to find the hair systems that had to be rendered. Now, in the particle system modifier, the final hair strands are converted into a Curves data-block that is then passed to render engines as a separate object.

Notes:

  • For Eevee this depends on D14916 for attribute rendering.
  • The cycles_hair_cpu test still fails, because the hair basemesh intercept and hair length info tests fail. However, Brecht mentioned that this is actually fixing a bug.

Todos:

  • Might be necessary to support reading from float2 attribute in the Texture Coordinate node in eevee as well (at least for curves).
  • Eevee/workbench need working intercept, length and uv attributes.
  • Eevee curve shapes seem a bit different than before. Needs to be investigated.

Diff Detail

Repository
rB Blender
Branch
render-hair-as-curves (branched from master)
Build Status
Buildable 22119
Build 22119: arc lint + arc unit

Event Timeline

Jacques Lucke (JacquesLucke) requested review of this revision.May 13 2022, 12:10 PM
Jacques Lucke (JacquesLucke) created this revision.
Jacques Lucke (JacquesLucke) retitled this revision from Curves: Draw legagy hair particle system as curves object. to Curves: Draw legagy hair particle system as curves object. (WIP).May 13 2022, 12:11 PM
Jacques Lucke (JacquesLucke) edited the summary of this revision. (Show Details)
  • make radius of last point 0 when close tip is enabled

It's great that we can remove all this code, just needs to be feature complete before it can be merged.

Dalai Felinto (dfelinto) retitled this revision from Curves: Draw legagy hair particle system as curves object. (WIP) to Curves: Draw legacy hair particle system as curves object. (WIP).May 13 2022, 4:27 PM
  • propagate uv and color attributes

Patch with Cycles fixes: P2952

  • Only the hair length test is still failing, however it's actually fixing a bug. where Cycles ignored the Render > Extra > Parent Particle setting.
  • The first float2 attribute is assumed to be the default UV map. There doesn't seem to be anything to determine which attribute is a UV map or not, and which is the active one.

Thanks Brecht, that helps a lot!

  • Merge master.
  • Add patch from Brecht to fix cycles tests.
  • move some functions to bke
  • remove more dead drawing code
Jacques Lucke (JacquesLucke) edited the summary of this revision. (Show Details)
Jacques Lucke (JacquesLucke) retitled this revision from Curves: Draw legacy hair particle system as curves object. (WIP) to Curves: Draw legacy hair particle system as curves object..May 17 2022, 9:07 AM

Unless you'd like me too, I think I'll skip testing this and trust the work you and Brecht have done. Great to remove this much code. Hopefully it's just the start!

Just a couple small comments, so I'll accept this now.

intern/cycles/blender/curves.cpp
451

I guess this ifdef should be removed now, since the old particle system depends on this code path.
Same in other places probably.

source/blender/blenkernel/intern/curves.cc
394–581 ↗(On Diff #51554)

I think it would be better to keep the particle system conversions to be in a separate fie, since they will probably be relatively permanent, for versioning.

Same with particle_hair_to_curves defined in the BKE_curves.hh header.

There's still some work to be done.

  • The inability to detect the active UV map will cause some files to be rendered differently.
  • Eevee/workbench don't seem to have working intercept, length or UV attributes.
  • Eevee curve shapes seems a bit different than before. Not sure if this is a result of Cycles and Eevee being different before and matching now, but for example render/motion_blur/curve_motion_blur.blend has more subdivision than before.

I compared the Eevee/Workbench render tests before and after. But I needed to apply D14969 to make the tests work, and also had to update the reference images before since they are outdated.

Yeah fair enough, will add that to the description.

For the Eevee/workbench changes it seems reasonable to wait for D14916. Both patches would probably conflict quite a bit otherwise. Also, this patch has to wait for D14916 anyway.
I had some trouble running the eevee/workbench tests earlier today, thanks for looking into that.

The inability to detect the active UV map will cause some files to be rendered differently.

You mean in cases where it would not detect any active uv map before and now uses a float2 attribute, or what case do you have in mind?

Brecht Van Lommel (brecht) requested changes to this revision.May 17 2022, 3:59 PM
This revision now requires changes to proceed.May 17 2022, 3:59 PM
Jacques Lucke (JacquesLucke) retitled this revision from Curves: Draw legacy hair particle system as curves object. to Curves: Draw legacy hair particle system as curves object. (WIP).May 17 2022, 4:02 PM
Jacques Lucke (JacquesLucke) edited the summary of this revision. (Show Details)

You mean in cases where it would not detect any active uv map before and now uses a float2 attribute, or what case do you have in mind?

When there are multiple UV maps, you can set which UV map is active for viewport/render. That's the one that is used in the UV Map node when not specifying a name, and the default texture coordinate for the Image Texture node.

This is a general design issue when switching from dedicated UV map attributes to generic float2 attributes, not sure if a solution was considered for that.

I see that there is a CD_PROP_UV in D14365, that would help figure out which is a UV, but could not find a doc explaining the intended design.

This is a general design issue when switching from dedicated UV map attributes to generic float2 attributes, not sure if a solution was considered for that.

At some point we were considering adding "usage hints" to attributes. Some "active" status could be part of that.
Another possibility would be to pass the name of the "active uv map" to the shader using some property on the geometry (e.g. char *Mesh.active_uv_map or using custom properties). The UI for choosing the active uv map could still stay the same, we might just need some way to also set the name from geometry nodes.

[EDIT] Actually, these are not necessarily alternatives, both (attribute usage hints and Mesh.active_uv_map) can exist at the same time.
[EDIT2] Haven't seen CD_PROP_UV before, currently I don't agree with that design.

The CD_PROP_UV in D14365 is not 'real' though. It's just a #define to CD_PROP_FLOAT2. The only reason I used this define is to ease the search&replace if we decide to distinguish between UVs and general purpose FLOAT2 layers after all. Afaik the current plan is to not make a distinction and just use replace CD_RPOP_UV with CD_PROP_FLOAT2 before eventually merging D14365 . When starting out I didn't yet know that CD_PROP_FLOAT2 was basically unused in the codebase and I wanted an easy way to distinguish between the new (UV) layer accesses and the existing FLOAT2 stuff.

  • Merge branch 'master' into render-hair-as-curves

I created T98366: Active Attributes to discuss how we want to handle the problem with active uv maps.

  • Merge branch 'master' into render-hair-as-curves