Commit Graph

79 Commits

Author SHA1 Message Date
Sergey Sharybin 7a4b784909 Subsurf: Move away from using scene from modifier data 2018-06-22 15:12:03 +02:00
Sergey Sharybin 498ffef7b0 Subsurf: Use regular mutex instead of RW one
Mutex is now local to particular CCGDM, and guarding edge hash which is only
used by a single function only. There is no need to acquire read lock after
edge hash was created.
2018-01-11 14:38:58 +01:00
Sergey Sharybin df0ecd73af Subsurf: Avoid global lock for loops and orig index layers
This is a bit annoying to have per-DM locking, but it's way better (as in, up to
4 times better) for playback speed when having lots of subsurf objects,
2017-12-22 12:50:57 +01:00
Campbell Barton a151b46627 Fix T53347: Vertex paint crash on undo/exit 2017-11-19 16:45:27 +11:00
Sergey Sharybin a5f4f1e2ce OpenSubdiv: Use pool for delayed OpenGL buffers free when freeing from non-main thread
This is really similar to what GPU module was already doing. There are number of
possible improvements still:

- Re-use allocated VAOs when requesting new ones instead of going to the trouble
  of freeing VAO and then re-creating it again.

- Move VAO handling to GPU module.

Fixes T46589: OpenSubdiv crash with drivers
2015-11-04 21:30:25 +05:00
Sergey Sharybin 11bfeb45ce OpenSubdiv: Completely avoid possible access to non-existing CPU data
Make it so CCGDM reports 0 number of geometry when it uses GPU backend for
drawing. This screws up a bit statistics in info header and requires to have
some special handle of CCGDM in the drawing code, but makes it so non of the
areas will try to access non-existing geometry.
2015-08-05 15:11:50 +02:00
Sergey Sharybin 3d36489672 OpenSubdiv: Commit of OpenSubdiv integration into Blender
This commit contains all the remained parts needed for initial integration of
OpenSubdiv into Blender's subdivision surface code. Includes both GPU and CPU
backends which works in the following way:

- When SubSurf modifier is the last in the modifiers stack then GPU pipeline
  of OpenSubdiv is used, making viewport performance as fast as possible.

  This also requires graphscard with GLSL 1.5 support. If this requirement is
  not met, then no GPU pipeline is used at all.

- If SubSurf is not a last modifier or if DerivesMesh is being evaluated for
  rendering then CPU limit evaluation API from OpenSubdiv is used. This only
  replaces the legacy evaluation code from CCGSubSurf_legacy, but keeps CCG
  structures exactly the same as they used to be for ages now.

This integration is fully covered with ifdef and not enabled by default
because there are several TODOs to be solved first:

- Face varying data interpolation is not really cleanly implemented for GPU
  in OpenSubdiv 3.0. It is also not implemented for limit evaluation API.

  This basically means we'll have really hard time supporting UVs.

- Limit evaluation only works with adaptivly subdivided meshes so far, which
  basically means all the points of CCG are pushed to the limit. This gives
  different result from old code.

- There are some serious optimizations possible on the topology refiner
  creation, which would speed up initial OpenSubdiv mesh creation.

- There are some hardcoded asumptions in the GPU and DerivedMesh areas which
  could be generalized.

  That's something where Antony and Campbell can help, making it so the code
  is structured in a way which is reusable by all planned viewport projects.

- There are also some workarounds in the dependency graph to make sure OpenGL
  buffers are only freed from the main thread.

Those who'll be wanting to make experiments with this code should grab dev
branch (NOT master) from

  https://github.com/Nazg-Gul/OpenSubdiv/tree/dev

There are some patches applied in there which we're working on on getting
into upstream.
2015-07-20 22:29:26 +02:00
Antony Riakiotakis 07def553d2 Fix T44745 non manifold edges of mesh do not work when smoothing in
multires.

Code had special guards for such edges to stop this from happening. I
don't see why this is needed though since code above assigns smoothed
positions for all vertices in the grid.

After removing the guards I saw that this in fact was the only place
where grd adjacency was used, so I completely removed it.
2015-05-27 19:52:12 +02:00
Campbell Barton b1d758ae6b Cleanup: redundant struct declarations 2015-03-29 03:56:39 +11:00
Campbell Barton 2097e621ed Code cleanup: use r_ prefix for return args 2014-03-16 03:26:23 +11:00
Sergey Sharybin 3073a5b1c4 Mark some CCG funcrions as inlined
This seems to be giving speedup up to 10% in own tests.

--
svn merge -r60104:60105 ^/branches/soc-2013-depsgraph_mt
2013-10-01 09:17:35 +00:00
Campbell Barton 25591e958d style cleanup: tabs & whitespace 2012-11-03 15:35:03 +00:00
Campbell Barton 9892736206 code cleanup: header cleanup and remove some duplicate defines. 2012-05-12 20:39:39 +00:00
Campbell Barton ce17c35240 style cleanup: mainly sculpt/whitespace 2012-05-11 08:05:47 +00:00
Nicholas Bishop 0f57b0f1e5 Copy GridPaintMask to vertex paint mask when applying multires.
Adds new subsurf_copy_grid_paint_mask() function similar to
subsurf_copy_grid_hidden().
2012-05-10 20:34:23 +00:00
Nicholas Bishop f4929ad609 Add mask support to CCGSubSurf and multires.
* Add new CCG function ccgSubSurf_setAllocMask(). Similar to to
  ccgSubSurf_setCalcVertexNormals(), it sets whether the CCG elements
  have a mask layer and what that layer's offset is. Unlike normals
  however, it doesn't change any behavior during CCG calculation; it's
  there only to give CCGKey information on the mask.

* Add a new flag to _getSubSurf(), CCG_ALLOC_MASK. If set, space for
  an extra layer is allocated, but the number of CCG layers is not set
  to include it. This is done because GridPaintMasks are absolute,
  rather than being relative to the subdivided output (as MDisp
  displacements are), so we skip subdividing paint masks here.

* Add a new flag to subsurf_make_derived_from_derived(),
  SUBSURF_ALLOC_PAINT_MASK. This controls whether CCG_ALLOC_MASK is
  set for _getSubSurf(). Related, masks are never loaded in during
  ss_sync_from_derivedmesh(). After subdivision is finished, if the
  alloc mask flag is set, the number of CCG layers is increase to 4
  with ccgSubSurf_setNumLayers().

* Add a new flag to multires_make_from_derived(),
  MULTIRES_ALLOC_PAINT_MASK. Not all multires functions need paint
  mask data (e.g. multiresModifier_base_apply.) This flag is always
  set in MOD_multires.c so that subdividing a mesh with a mask updates
  properly even when not in sculpt mode.

* Update multiresModifier_disp_run() to apply, calculate, and add mask
  elements. It's almost the same as the existing operations with xyz
  coordinates, but treats masks as absolute rather than displacements
  relative to subdivided values.

* Update multires_customdata_delete to free CD_GRID_PAINT_MASK in
  addition to CD_MDISPS.

* Update multires_del_higher() to call the new function
  multires_grid_paint_mask_downsample(), which allocates a
  lower-resolution paint mask grid and copies values over from the
  high-resolution grid.
2012-05-10 20:34:08 +00:00
Nicholas Bishop f751d0f6ae Replace hardcoded DMGridData structure with CCGElem/CCGKey.
* Changes to DerivedMesh interface: DMGridData has been removed,
  getGridData() now returns an array of CCGElem pointers. Also added
  getGridKey() to initialize a CCGKey (implemented only by
  CCGDerivedMesh.)

* PBVH: added BLI_pbvh_get_grid_key().

* A lot of code is affected, but mainly is just replacing
  DMGridData.co, DMGridData.no, and sizeof(DMGridData) with the
  CCG_*_elem functions, removing the reliance on grid elements of
  exactly six floats.
2012-05-10 20:33:09 +00:00
Nicholas Bishop 6dbfbabcd6 Code cleanup for parameters of subsurf_make_derived_from_derived.
This is the first commit of the sculpt masking merge. Documentation:
http://wiki.blender.org/index.php/User:Nicholasbishop/PaintMasks

Thanks to Brecht for reviewing!

Replaced four boolean parameters with a single flag and a new enum,
SubsurfFlags.
2012-05-10 20:31:55 +00:00
Campbell Barton 5c89138684 style cleanup: comments 2012-04-22 11:54:53 +00:00
Nicholas Bishop 3d87c23f4f Reduce poly map memory usage (used by sculpt smooth brush.)
Changed the create_vert_poly_map function to return a more compact
structure. Memory saved will vary depending on the mesh, but typically
it should be about one third of the old size.
2012-03-17 04:41:36 +00:00
Nicholas Bishop b37a355c8e Copy hidden flag to vertices when applying multires modifier. 2012-03-14 06:32:13 +00:00
Nicholas Bishop 521e724edd Skip hidden elements in PBVH iterator, raycast, and drawing. 2012-03-14 06:32:03 +00:00
Nicholas Bishop 8717e35db3 Add DerivedMesh.gridHidden and CCGDM implementation. 2012-03-14 06:31:49 +00:00
Nicholas Bishop 0c91821364 Add new CCG accessor functions.
ccg_gridsize() converts a level into gridsize, ccg_factor() is for
converting coordinates between different multires levels.
2012-03-14 06:31:24 +00:00
Nicholas Bishop dfc9a57b3e Code cleanup: replace multires update function pointer with direct call.
Renamed the multiresModifier_update() function to
multires_modifier_update_mdisps() and made it visible to subsurf_ccg.c
so it can be called directly. No functional change, just a bit simpler.
2012-03-12 22:52:20 +00:00
Nicholas Bishop c7ffe7f621 Draw individual face's material and shading correctly in the PBVH.
Previously, the shading and material was set once per PBVHNode when
drawing. This is still the case, but PBVHNodes are now built to
contain only one material and shading mode.

This is done with an extra partitioning step; once the number of
primitives in the node falls below the PBVH leaf limit, it's
primitives are checked for matching materials. If more than one
material or shading mode is present in the node, it is split and
partitioned (partitioned by material rather than 3D location.)

Given a sufficiently 'annoying' input, like a dense mesh with
thousands of materials randomly scattered across it, this could
greatly increase PBVH build time (since nodes might end up containing
a single primitive), but in general this shouldn't come up.

In order to support materials for grids, the CCGDM is building another
grid array (of DMFaceMat structs). This could be used to replace
CCGDM.faceFlag for some small memory savings (TODO).
2012-03-06 02:40:08 +00:00
Nicholas Bishop c729d6a87b Bugfix and code cleanup: use better types for faceFlags in CCGDM.
Previously this was just a character array that stored face/poly flags
and mat_nr. Since mat_nr should be a short, this would have truncated
for higher values.

Replaced with a new DMFaceFlags struct.
2012-03-06 00:17:03 +00:00
Nicholas Bishop e3877a625e Style cleanup: remove underscore prefix from CCG struct names. 2012-02-26 06:50:54 +00:00
Campbell Barton a368e6771a - remove some unused editmesh functions.
- copy & rename EditMesh stricts for use with scanfill (remove unused members)
2012-02-19 22:17:30 +00:00
Campbell Barton 48006292d8 svn merge ^/trunk/blender -r44189:44204 2012-02-17 20:56:25 +00:00
Campbell Barton 2b7ca2304a unify include guard defines, __$FILENAME__
without the underscores these clogged up the namespace for autocompleation which was annoying.
2012-02-17 18:59:41 +00:00
Campbell Barton 776ec0ec61 add function for getting a polygon map: dm->getPolyMap(ob, dm).
polygon version of dm->getFaceMap(ob, dm)

sculpt uses this for checking connectivity.
2012-02-05 06:20:51 +00:00
Campbell Barton 15e6d6cd75 svn merge ^/trunk/blender -r41226:41227 . 2011-10-24 12:43:08 +00:00
Campbell Barton 4a04f72069 remove $Id: tags after discussion on the mailign list: http://markmail.org/message/fp7ozcywxum3ar7n 2011-10-23 17:52:20 +00:00
Campbell Barton 4e118bb22f svn merge ^/trunk/blender -r40890:40950 2011-10-14 01:35:20 +00:00
Campbell Barton bc40f11093 header cleanup (no functional changes) 2011-10-10 09:38:02 +00:00
Campbell Barton 88f4087a57 svn merge -r36725:36801 https://svn.blender.org/svnroot/bf-blender/trunk/blender 2011-05-20 16:52:10 +00:00
Brecht Van Lommel ae0c552bd1 Fix crash when accessing mesh from python while a mesh with a subsurf modifier
is in editmode.
2011-05-19 11:24:56 +00:00
Joseph Eagar f01261d040 merge with/from trunk at r35190 2011-02-27 06:19:40 +00:00
Nathan Letwory 22638e22ea doxygen: blenkernel under core as module. 2011-02-18 13:05:18 +00:00
Sergey Sharybin 329e2d8037 Todo issue: sculpting on deformed mesh
Used a crazyspace approach (like in edit mode), but only modifiers with
deformMatricies are allowed atm (currently shapekeys and armature modifiers only).
All the rest modifiers had an warning message that they aren't applied because
of sculpt mode. Deformation of multires is also unsupported.

With all this restictions users will always see the actual "layer" (or maybe
mesh state would be more correct word) they are sculpting on.

Internal changes:
- All modifiers could have deformMatricies callback (the same as deformMatriciesEM but
  for non-edit mode usage)
- Added function to build crazyspace for sculpting (sculpt_get_deform_matrices), but it
  could be generalized for usage in other painting modes (particle edit mode, i.e)

Todo:
- Implement crazyspace correction to support all kinds of deformation modifiers
- Maybe deformation of multires isn't so difficult?
- And maybe we could avoid extra bad-level-stub for ED_sculpt_modifiers_changed
  without code duplicating?
2011-01-31 20:02:51 +00:00
Joseph Eagar c11c196efa part 1 of merge from trunk at r30358; it compiles, but doesn't link quite yet :) 2010-07-19 04:44:37 +00:00
Brecht Van Lommel 89320c911e Sculpt & modifiers: patch by Sergey Sharybin, with modifications by me.
Fixes various crashes and redraw problems, most noticeable new feature
is that you can now sculpt on a multires mesh with deforming modifiers
preceding it.

I've left out support for sculpting on multires with enabled modifiers
following it, in this case only the base mesh can be sculpted now. The
code changes needed to do this are just too ugly in my opinion, would
need a more torough redesign which I don't think we should try now. In
my opinion this is also not really an important case, since it's going
to be incredibly slow anyway to run a modifier on a high res mesh while
sculpting.


So, to summarize current state:

* Fastest sculpting: base mesh with no modifiers or multires with only
  modifiers preceding it.
* Slower sculpting: base mesh with modifiers, depends on the speed of
  the modifiers.
* Not supported: multires mesh with modifiers following it.
2010-06-02 18:04:31 +00:00
Campbell Barton 8c3ab1c2a4 - use more inline math funcitons where possible
- swapped in less verbose math functons
- modifier include cleanup
2010-04-12 00:36:50 +00:00
Brecht Van Lommel 09b1c681e1 Sculpt Mode Bugfixes:
* #20833: layer brush doesn't work with multires.
* #20946: sculpt mode partially removes parts of the mesh in the viewport.
* #20420: grab brush stops after moving some distance.
* #20906: sculpt grab tool moves in wrong direction.
* #21132 and #21272: undo on object with subdivision surface modifier crashes.
* #21115: subsurf + multires + sculpting + undo causes crash.
* #20683: sculpt + multires apply + undo crash.
* #19094: wrong outline in solid mode.
2010-03-22 11:59:36 +00:00
Campbell Barton 1e9bf0cfdb spaces -> tabs, (4 spaces == 1 tab, only for white space preceding text) 2010-03-22 09:30:00 +00:00
Joseph Eagar 71003b9bcc merge with trunk at r27259 and commit of a patch by anthony jones to fix msvc (though further work may be needed because changes made by the merge 2010-03-09 04:32:40 +00:00
Campbell Barton 081c1205a3 correct fsf address 2010-02-12 13:34:04 +00:00
Joseph Eagar 67ff197cb1 Merge with trunk/2.5 at r25563
Most likely will not compile for others, I'd appreciate any build errors
and missing files reports (I can never seem to get everything committed
and all the build systems working without help).

Porting over the sculpt/multires tools was a breeze,
thanks goes to brecht for a design that didn't exclude
ngons and was easy to port.

Note that I've not tested externally-backed multires
file support yet.  Also, I still need to write version
patch code for some cases.

Some notes:

* Like trunk, topological changes don't update multires right,
  so e.g. subdivide will duplicate multires data on the new faces,
  instead of subdividing it.
* If you set the debug value (ctrl-alt-d) to 1 it'll turn on
  my experiments in speeding up sculpting on higher-res multires
  meshes (but note it makes partial redraw not completely accurate).
* There's a bug where you have to go through editmode to get out
  of sculpt mode, not sure if I inherited or created this myself.
2010-01-05 22:33:41 +00:00
Brecht Van Lommel 010c99deb2 Sculpt Branch:
* Multithread parts of multires and subsurf. Only loops working on
  face grid data and do no memory allocation have been multithreaded,
  others would be more complicated.
* Force some CCGSubsurf functions to be inlined, gives a small overall
  speedup in subsurf code.

* Fix sculpting not working correct with transformed objects.
* Fix a few cases of "spikes" on lower level multires levels. There's
  still cases where it happens, usually on boundary cornders. The
  problem is that in such cases the limit surfaces can be very different
  from the low res surface, so the tangent space is very different too..
* Fix crash deleting multires higher levels with level set to 0.
* Fix crashes that happened sometimes when adding faces in editmode.
2009-12-03 18:35:37 +00:00