Simplify shape

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

Simplify shape

Post by Dade » Wed Oct 30, 2019 3:16 pm

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: 168
Joined: Thu Jul 05, 2018 11:38 pm
Location: Rio de Janeiro

Re: Simplify shape

Post by alpistinho » Wed Oct 30, 2019 5:19 pm

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: 1528
Joined: Mon Dec 04, 2017 10:11 pm
Location: Ivory Coast

Re: Simplify shape

Post by Sharlybg » Wed Oct 30, 2019 5:58 pm

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: 198
Joined: Tue Mar 13, 2018 10:34 am

Re: Simplify shape

Post by Egert_Kanep » Thu Oct 31, 2019 4:49 pm

Can't wait to get my hands on it

User avatar
Dade
Developer
Developer
Posts: 3270
Joined: Mon Dec 04, 2017 8:36 pm
Location: Italy

Re: Simplify shape

Post by Dade » Sat Nov 02, 2019 11:11 am

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: 331
Joined: Wed Jan 10, 2018 8:04 am

Re: Simplify shape

Post by marcatore » Sat Nov 02, 2019 1:02 pm

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

Great!

Post Reply