Pointiness to Vertex Colours Script

Hi there, I have posted this here to Blender Stack Exchange, but thought I’d cross-post it here as well. Hope this is the right part of the forum! :slight_smile:

I am attempting to create some Procedural Weathering Effects on a high-poly model using a similar Pointiness method to that discussed in my previous question and answer here. Whilst Cycles provides great results using this method, for the sake of speed I’m trying to replicate the effect in EEVEE.

As of Blender 2.81a, however, the Geometry->Pointiness node is not currently supported in EEVEE and, as discussed in this thread on the bug tracker, due to the intensive pre-processing step needed to compute the effect it is unlikely to be supported anytime soon.

This has led me down the path of attempting to manually replicate the colours that the Pointiness node generates by first using the Dirty Vertex Colours operator (which is, in-practice, 1-click) to give me a vertex colour map of the mesh edges/cavities, and then essentially colour-correcting them (in a very rough fashion) to be visually similar to the output of the Pointiness attribute in cycles.

This has been somewhat successful when using the high-poly (~430k faces) ‘Standford Buddha’, and the following node setups for EEVEE/Cycles:

Comparison Current Setup

Whilst this works well for the buddha model, attempting to use the same correction parameters on different, lower-poly models yields drastically different results:

Suzanne Comparison

With a significant amount of tweaking, I’m sure the correction parameters could once again be adjusted to visually match the Pointiness output, however, I’m looking for a rapid, procedural approach that doesn’t require a lot of manual changes.

Despite the issues, it does still seem like the ‘Dirty Vertex Colours’ approach could be the most promising. As a result, I’m debating whether a script or mathematical shader approach could be used to either replicate the basic Pointiness values and apply them as vertex colours or, alternatively, accurately remap the ‘Dirty Vertex Colours’ to the ‘correct’ Pointiness values. I’m assuming that a script that simply generates Pointiness colours based on the original algorithm from Sergey’s patch may be simpler and more successful however, considering my initial problems.

Unfortunately, despite it not seeming like the algorithm is particularly complex, my knowledge of python and the code that goes into cycles shaders isn’t sufficient enough to help me convert it. From Shadowphile’s thread here on Blender Artists, it is suggested that Pointiness is generated by searching in a ring around a vertex/edge (one-ring neighbourhood), applying a value of 0.5 to flat surfaces, a value of >0.5 to outside edges and a value of <0.5 to inside edges, before adding an overall blur to approximate a two-ring neighbourhood.

In researching this problem more, I also came across Ambi’s script here for better calculating Mesh Curvature to Vertex Colours (and the associated BA Thread). While this provides some insight into how iterating through the mesh and assigning colours could be achieved, it unfortunately uses different algorithms, and isn’t directly related to my Pointiness problem; or ultimately converted for Blender 2.8x.

Thanks for taking the time to read, any help in shedding some light on this problem would be very much appreciated!


Helpful Links:

Looks like curvature indeed wasn’t middle gray, here’s a new release https://github.com/amb/ambitools/releases/tag/v1.0.2 fresh out of the oven. (3D view > Edit > Mesh Toolbox > Vertex color > Curvature > blur:0, power: 1.0, alt: false)

2 Likes

Thank you so much for the speedy reply and toolbox update @ambi, really wasn’t expecting that! :smiley:

I’ve been playing around with the Curvature vertex colour tool in your addon over the past couple of days but unfortunately I still haven’t quite wrapped my head around how to convert the vertex colours to a value that resembles the Pointiness output.

As it stands this is the difference between the Pointiness output and Curvature vertex colour output as applied to Suzanne with a level 2 Subdivision Modifier:

Out of the box your method does look a lot nicer, but unfortunately in order to work with the rest of my weathering setup I could do with normalising the vertex colour values so that I can run them through the same colour ramp as I do with the Pointiness output. Any ideas? :slight_smile:

You can get closer, but not with a color ramp. You need a lot of math nodes. A color ramp clips values above and below 0-1. It does not rescale them to 0-1. You need a sigmoid to do that.

This is how I’ve gotten close in a few minutes. Maybe a RGB curves or something can do the rest. Forget the color ramp :wink:

sigmoid group:

Thanks @ambi, that’s amazing work.