Simplify shape

Discussion related to the LuxCore functionality, implementations and API.
Post Reply
User avatar
Dade
Developer
Developer
Posts: 5672
Joined: Mon Dec 04, 2017 8:36 pm
Location: Italy

Simplify shape

Post by Dade »

I'm out of the white rabbit's hole ... it was a long journey. I added the support for a new Simplify shape (check viewtopic.php?f=5&t=1483 for some more information about shapes in LuxCore).

Simplify Shape

Simplify is a shape intended for decimating the number of triangles in a mesh with the smaller possible error. It is based on paper "Surface Simplification Using Quadric Error Metrics" by Michael Garland Paul S. Heckbert. My code is based on code from Sven Forstmann's https://github.com/sp4cerat/Fast-Quadri ... lification.

The following properties can be used to define a simplification step in geometry transformation pipeline:

Code: Select all

scene.shapes.obj_whitesimplify.type = simplify
# Original mesh name
scene.shapes.obj_whitesimplify.source = obj_whitedisp
# Decimate the triangles up to a 25% of the original mesh
scene.shapes.obj_whitesimplify.target = 0.25
# Scale the  error according the size of the triangle edges on film plane (disabled by default)
scene.shapes.obj_whitesimplify.edgescreensize = 0.01
# A flag to avoid touch mesh borders (in order to avoids cracks, etc.)
scene.shapes.obj_whitesimplify.preserveborder = 0
It is an iterative process the will decimate triangles up to the required target:

Code: Select all

[SDL][0.095] Simplify shape obj_whitedisp with target 0.25
[SDL][0.388] Simplify iteration 0 (13107 edge candidates, deleted 7598/7598 of 131072 triangles)
[SDL][0.574] Simplify iteration 1 (13107 edge candidates, deleted 5169/12767 of 131072 triangles)
[SDL][0.752] Simplify iteration 2 (13107 edge candidates, deleted 4730/17497 of 131072 triangles)
[SDL][0.927] Simplify iteration 3 (13107 edge candidates, deleted 5259/22756 of 131072 triangles)
[SDL][1.095] Simplify iteration 4 (13107 edge candidates, deleted 5674/28430 of 131072 triangles)
[SDL][1.256] Simplify iteration 5 (13107 edge candidates, deleted 5434/33864 of 131072 triangles)
[SDL][1.408] Simplify iteration 6 (13107 edge candidates, deleted 5654/39518 of 131072 triangles)
[SDL][1.554] Simplify iteration 7 (13107 edge candidates, deleted 5824/45342 of 131072 triangles)
[SDL][1.691] Simplify iteration 8 (13107 edge candidates, deleted 5896/51238 of 131072 triangles)
[SDL][1.821] Simplify iteration 9 (13107 edge candidates, deleted 5879/57117 of 131072 triangles)
[SDL][1.942] Simplify iteration 10 (13107 edge candidates, deleted 5711/62828 of 131072 triangles)
[SDL][2.039] Simplify iteration 11 (13107 edge candidates, deleted 5571/68399 of 131072 triangles)
[SDL][2.130] Simplify iteration 12 (13107 edge candidates, deleted 6013/74412 of 131072 triangles)
[SDL][2.216] Simplify iteration 13 (13107 edge candidates, deleted 6900/81312 of 131072 triangles)
[SDL][2.295] Simplify iteration 14 (13107 edge candidates, deleted 7454/88766 of 131072 triangles)
[SDL][2.365] Simplify iteration 15 (13107 edge candidates, deleted 7440/96206 of 131072 triangles)
[SDL][2.425] Simplify iteration 16 (13107 edge candidates, deleted 6898/103104 of 131072 triangles)
[SDL][2.427] Subdivided shape from 131072 to 27968 faces
This is an example with of a Suzanne decimate from 3936 to 1874 and 323 faces:

simplify.jpg

This is an example of the main reason I implemented this new shape: for the Mesh => Subdivide => Displace => Simplify chain of geometric transformations.

sphere.jpg
vect.jpg

.edgescreensize property

".edgescreensize" can be used to scale the geometric error by the size of the triangle on the screen. This is an example:

viewscale.jpg

It should be easy to understand where the camera was positioned at the time of the decimation: out of view and far triangles are more decimated than the near one.

Normal, UV, Color and Alpha vertex information

To correctly evaluated the decimation error accounting for Vertex position and Normal would require to work on a 6-D space, for Position+Normal+UV would require a 8-D space, etc.
It is clearly not easily manageable so I'm working only with position and interpolating other vertex attributes.
This can introduce some slight error. This is an example of the UV error, the original mesh:

uv-not-reduced.jpg

the simplified one:

uv-reduced.jpg

This isn't usually a problem for natural patterns like rocks, etc. it is more visible with regular geometric pattern like the one above.

LuxCore geometry pipeline

As you may have noticed, the LuxCore geometry pipeline is becoming a quite powerful tool. For instance, this image

vect.jpg

is the result of:

1) load a sphere low poly mesh;
2) subdivide the mesh to have a regular high poly count;
3) apply vector displacement;
4) apply harlequin pattern to the mesh;
4bis) simplify the result;
5bis) apply harlequin pattern to the mesh;

(i.e. you can build a tree, not just a pipeline).
Support LuxCoreRender project with salts and bounties
User avatar
alpistinho
Developer
Developer
Posts: 198
Joined: Thu Jul 05, 2018 11:38 pm
Location: Rio de Janeiro

Re: Simplify shape

Post by alpistinho »

Great work!

I was keeping up with the commits and it was a big rabbit hole indeed :lol:
Support LuxCoreRender project with salts and bounties
User avatar
Sharlybg
Donor
Donor
Posts: 3101
Joined: Mon Dec 04, 2017 10:11 pm
Location: Ivory Coast

Re: Simplify shape

Post by Sharlybg »

A lot of work done even if it look very technical for me i can understand that adaptive subdivision per mesh is now possible. there is a lot of topic to cover in comming month :

__Light tracing

__ SDS caustics / Pool holy grail

__ adaptive subdivision displacement

__ Also have to talk about improvement done in Auto portals when it is ready

Bravo thanks.
Support LuxCoreRender project with salts and bounties

Portfolio : https://www.behance.net/DRAVIA
User avatar
Egert_Kanep
Posts: 237
Joined: Tue Mar 13, 2018 10:34 am

Re: Simplify shape

Post by Egert_Kanep »

Can't wait to get my hands on it
User avatar
Dade
Developer
Developer
Posts: 5672
Joined: Mon Dec 04, 2017 8:36 pm
Location: Italy

Re: Simplify shape

Post by Dade »

I have added an option to preserve mesh borders in order to avoids cracks between contiguous meshes, etc.

Code: Select all

# A flag to avoid touch mesh borders (in order to avoids cracks, etc.)
scene.shapes.obj_whitesimplify.preserveborder = 0
If enabled it will never touch mesh borders, no matter how much you want to decimate the mesh:

preserve.jpg
Support LuxCoreRender project with salts and bounties
marcatore
Donor
Donor
Posts: 463
Joined: Wed Jan 10, 2018 8:04 am

Re: Simplify shape

Post by marcatore »

fantastic! it's turning out really well and powerful.

Great!
User avatar
lacilaci
Donor
Donor
Posts: 1969
Joined: Fri May 04, 2018 5:16 am

Re: Simplify shape

Post by lacilaci »

I have few questions

is this correct order of nodes to have mesh subdivided->displaced->simplified?
Annotation 2020-01-01 095607.jpg
How does the edge screen size value work? Default is at 0.00 so does that mean that by default is the feature disabled? Or is it disabled when it's at 1?
User avatar
Dade
Developer
Developer
Posts: 5672
Joined: Mon Dec 04, 2017 8:36 pm
Location: Italy

Re: Simplify shape

Post by Dade »

lacilaci wrote: Wed Jan 01, 2020 8:56 am is this correct order of nodes to have mesh subdivided->displaced->simplified?
Yes.
lacilaci wrote: Wed Jan 01, 2020 8:56 am How does the edge screen size value work? Default is at 0.00 so does that mean that by default is the feature disabled? Or is it disabled when it's at 1?
Yes, 0.0 means disabled and it is the target maximum percentage of edge screen size: 0.1 => 10% screen size.
Support LuxCoreRender project with salts and bounties
Post Reply