Vertex color changed by distance change from original position

Discussion of Genome, the extensible geometry modifier for 3ds Max
Jim S
Posts: 68
Joined: Fri Sep 04, 2015 3:06 pm

Vertex color changed by distance change from original position

Postby Jim S » Thu Jan 12, 2017 3:00 pm

Hi Bobo,

I'm trying to set up a Genome flow for this and I am stumped. I'm hoping this one will be a breeze for you though.

I attached a sample scene with my non-working setup. I will apply this effect to another scene but a modified Geosphere works just fine for this example in order to get the concept to work.

I have a Geosphere with a morpher modifier that morphs the geosphere's verticies to the position of a cloned geosphere with noise displacement applied. I want to be able to assign vertex colors that change based off of their distance from the original sphere's vertex positions. I'd like for these vertex colors to change over time to correspond with the surface animation.

no morph.jpg
no morph.jpg (264.72 KiB) Viewed 397 times


morphed.jpg
morphed.jpg (285.45 KiB) Viewed 397 times


morph_overlaied_with_no_morph_.jpg
morph_overlaied_with_no_morph_.jpg (257.75 KiB) Viewed 397 times


Any help would be greatly appreciated!!

Jim S
Posts: 68
Joined: Fri Sep 04, 2015 3:06 pm

Re: Vertex color changed by distance change from original position

Postby Jim S » Thu Jan 12, 2017 3:02 pm

I'm not sure why but I couldn't attach my scene file in my last post. It looks like there may be an error here so I'll try emailing it to you too. I also attached a screen grab of my non-working flow. You'll see the logic I'm trying to apply to this setup though - if the vertices positions are equal to the non-deformed sphere they get selected.
Attachments
broken_flow_.jpg
broken_flow_.jpg (630.61 KiB) Viewed 396 times

User avatar
Bobo
Posts: 5939
Joined: Tue Nov 15, 2005 10:26 am
Location: Vancouver, Canada
Contact:

Re: Vertex color changed by distance change from original position

Postby Bobo » Thu Jan 12, 2017 3:44 pm

You need to ZIP the scene, the forum does not allow .MAX files to be uploaded. Got your email, will check it out.

Just looking at your flow, what you need is the Absolute value of the Distance output in the NearestPoint operator. Assuming you want to use that operator at all, if you are using Morphing, the vertex count is identical, so all you need to do is query the vertex position in the other mesh by the same index as the current InputChannel:Index, subtract the two positions, do Vector Mangitude, and divide by the Max. distance to normalize between 0.0 and 1.0. Then you can output as VertexColor or Selection.

Will post some examples as soon as I have them.
Borislav "Bobo" Petrov
Product Specialist
Thinkbox Software Inc.

User avatar
Bobo
Posts: 5939
Joined: Tue Nov 15, 2005 10:26 am
Location: Vancouver, Canada
Contact:

Re: Vertex color changed by distance change from original position

Postby Bobo » Thu Jan 12, 2017 3:58 pm

Here is your flow with my modifications:
GNM_VertexColorByDistance_NearestPointPosition.png
GNM_VertexColorByDistance_NearestPointPosition.png (67.71 KiB) Viewed 392 times

Subtract the two positions, Vector>Magnitude, Divide by half the Displacement Strength to normalize between 0.0 and 1.0, and output as Selection.

You can simplify this as mentioned using the Absolute value of the Distance output socket:
GNM_VertexColorByDistance_NearestPointPositionAbsDistance.png
GNM_VertexColorByDistance_NearestPointPositionAbsDistance.png (52.56 KiB) Viewed 390 times


If you prefer to only color the vertices if they are ABOVE the reference mesh, and stay black when pushed inside (below the surface), you only need to remove the Absolute operator, and add a Clamp after the Divide operator:
GNM_VertexColorByDistance_NearestPointPositionClampDistance.png
GNM_VertexColorByDistance_NearestPointPositionClampDistance.png (48.89 KiB) Viewed 390 times

Any negative values will be clamped to 0.0 and remain black if the vertex is pushed in the negative direction.

In the next version, I removed the top Genome modifier that converted selection to Color, and changed the bottom Genome to Face Corners iteration mode. Here I used VertexQuery to grab the world space position of the reference geosphere's vertex with the same VertexIndex as the current iteration's vertex index. The rest is the same, plus the conversion of the normalized value to a Vector going directly to the Color channel.
GNM_VertexColorByDistance_VertexQueryByIndex.png
GNM_VertexColorByDistance_VertexQueryByIndex.png (60.01 KiB) Viewed 391 times

I expect this to be a lot faster with very dense meshes, because it does not have to stuff the mesh into a kd-tree acceleration structure to perform any nearest point queries, it simply reads by index the respective vertex from the mesh. However, it performs a few more queries (3x the face count instead of the vertex count). So with your Geosphere instead of 10242 NearestPoint calls, it will perform 3x20480 = 61440 vertex reads. Chances are it will still be faster, esp. since we avoid the second Genome on top of the stack...
Borislav "Bobo" Petrov
Product Specialist
Thinkbox Software Inc.

Jim S
Posts: 68
Joined: Fri Sep 04, 2015 3:06 pm

Re: Vertex color changed by distance change from original position

Postby Jim S » Thu Jan 12, 2017 4:58 pm

Bobo, thank you so much!!! I tried each of your flows and they work exactly how I need them to. I am going to use this same setup in another scene with more complex meshes so I'll try using your last example that iterates over face corners. This should work great but I'll let you know if I have any other questions.

Thanks again!!

User avatar
Bobo
Posts: 5939
Joined: Tue Nov 15, 2005 10:26 am
Location: Vancouver, Canada
Contact:

Re: Vertex color changed by distance change from original position

Postby Bobo » Thu Jan 12, 2017 5:13 pm

Ooops! In the first modified flow, the NearestPoint Position should NOT pass through a ToWorld operator, because it is already in World Space.
If the Geosphere is at the origin, it won't matter, but if it is not, you would get double-transform by the world transform matrix, and it would skew your results. Sorry about that, but it was you who added it :mrgreen:
Borislav "Bobo" Petrov
Product Specialist
Thinkbox Software Inc.

Jim S
Posts: 68
Joined: Fri Sep 04, 2015 3:06 pm

Re: Vertex color changed by distance change from original position

Postby Jim S » Thu Jan 12, 2017 6:15 pm

Haha, no worries Bobo! I actually showed this to my coworker Tyler (he has a programming background so he's better at this stuff then I am) and he helped create an alternate flow that adjusts colors differently depending on whether the vertices are displaced inward or outward, which actually should work better for what we're looking to do. Here's a screen grab of the flow and a render. I attached my updated scene file if you want to take a look.

Color_by_distance_change_.jpg
Color_by_distance_change_.jpg (1.58 MiB) Viewed 384 times


Thanks again!
Attachments
Genome_color_by_height_change_new.zip
(487.93 KiB) Downloaded 21 times

User avatar
Bobo
Posts: 5939
Joined: Tue Nov 15, 2005 10:26 am
Location: Vancouver, Canada
Contact:

Re: Vertex color changed by distance change from original position

Postby Bobo » Thu Jan 12, 2017 10:45 pm

InVolume is rather expensive - it still has to perform the kd-tree initialization, and then it has to perform several surface tests to ensure the point is inside or outside. And because we are doing the Face Corners test, it is actually doing a lot more lookups than if you were using a vertex iteration mode (6x more as we saw previously!)

So if you are going to use a mesh lookup, then the alternative approach with a NearestPoint and Distance would give you the same result, but might be faster since it would perform only one lookup for each vertex, and the Distance will return a negative value if inside, and a positive value if outside. Write that into the Selection without clamping it.
Your logical Switch will go into another Genome on top and would just need a Greater operator to check if Distance is greater or less than 0, and then the absolute value of Distance can go into the respective blend operator! To make things even cleaner, the green color input can be reused for both blends, so if you expose it and change it, it would affect both sides...

Of course, if you feel your current solution is fast enough for your actual production scene, then having a single Genome modifier might be a good thing...
Borislav "Bobo" Petrov
Product Specialist
Thinkbox Software Inc.

Jim S
Posts: 68
Joined: Fri Sep 04, 2015 3:06 pm

Re: Vertex color changed by distance change from original position

Postby Jim S » Fri Jan 13, 2017 11:54 am

Thanks Bobo! That's good to know, I'll give your suggested approach a shot and see how that works. In any case it's good for me to try different approaches to get more practice creating flows. Cheers!!


Return to “Thinkbox Software - Genome”

Who is online

Users browsing this forum: No registered users and 1 guest