Jump to content
DASD

How do you get UV density and UV distortion as attributes?

Recommended Posts

1.
How do you get UV density and UV distortion as a vertex attributes?

2.
How would you get UV overlap as a vertex attribute?

3.
How would you get UV direction (flipped UVs) as a vertex attribute?

 

(I can think of ways to build this stuff, but I am looking for solutions that already exist. Packages like Maya give you this kind of information by default. I would imagine Houdini does too. )

Share this post


Link to post
Share on other sites

I can't think of anything out of the box that will provide these attributes...

but it's a pretty good RFE

:)

Share this post


Link to post
Share on other sites

What is UV density use for? I thought they were just coordinates for mapping.

Share this post


Link to post
Share on other sites

The UV density would be the ratio of UV space to object space I suppose, which is also related to how you would compute the distortion.

The larger the difference is between the shape (not size) of the UV polygon compared polygon shape, the more distortion you have, which is always >0 for organic models,

unless you cut out every uv polygon separately (which is a lot worse for texturing purposes)

Share this post


Link to post
Share on other sites

With distortion I mean how far the UV triangle shapes deviate from their 3D polygon shape. And with density I mean how small or large UV triangles are relative to each other (compensated for the original 3D polygon size).

For an optimal unwrap distortion would be low and density variation would be low too.

Edited by DASD

Share this post


Link to post
Share on other sites

Sometimes when you are searching for something and you find a topic you visited a long time ago, but no new posts were made in the meantime..
I guess that is a call to action :P

The following code outputs 2 vertex attributes related to distortion;
one is the angle difference between uv and world, vertex corners
the other gives the edgeLength ratio difference between the in and outgoing edge of every vertex.

Afterwards you can of course use an attribute promote to get the average primitive or point distortions of course
or you can merge the distortion into a single attribute by taking the maximum value for example
 

//run over vertices:

//get neighbouring verts
int locVert = vertexprimindex(0, @vtxnum);
int prNumVerts = primvertexcount(0, @primnum);
int vtx0 = primvertex(0, @primnum, (locVert - 1) % prNumVerts);
int vtx1 = primvertex(0, @primnum, (locVert + 1) % prNumVerts);

//printf("%d - %d - %d\n", vtx0, @vtxnum, vtx1);

//get world posData
vector p0 = vertex(0, "P", vtx0);
vector p1 = vertex(0, "P", vtx1);

p0 = v@P - p0; //get position edges
p1 = p1 - v@P;

float posEdgeL0 = length(p0); //get position edge lens
float posEdgeL1 = length(p1);

p0 /= posEdgeL0; //normalize pos edges
p1 /= posEdgeL1;

//get uv posData
vector uv0 = vertex(0, "uv", vtx0);
vector uv1 = vertex(0, "uv", vtx1);

uv0 = v@uv - uv0; //get uv edges
uv1 = uv1 - v@uv;

float uvEdgeL0 = length(uv0); //get uv edge lens
float uvEdgeL1 = length(uv1);

uv0 /= uvEdgeL0; //normalize uv edges
uv1 /= uvEdgeL1;

//get edgeRatios
posEdgeL0 /= posEdgeL1;
uvEdgeL0 /= uvEdgeL1;

//compare world and uv data
float worldDot = dot(p0, p1);
float uvDot = dot(uv0, uv1);
f@uvDistortAng = abs(worldDot - uvDot); //this value should be between 0 and 2
f@uvDistortLen = abs(posEdgeL0 - uvEdgeL0); //you may want to normalize this value in a different node later


Edited by acey195

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×