Triangle mesh texture filtering

117 views
Skip to first unread message

Lucas MALLEUS

unread,
Aug 28, 2013, 11:35:56 AM8/28/13
to pt...@googlegroups.com

Hi,

I am trying to filter a texture applied on a triangle mesh using PtexTriangleFilter available in Ptex (using Gaussian one). However, I got some artifacts on the edges of faces. The example here is atlas reconstructed from Ptex filtered texture. Basically, it is a texture with fully white triangles and fully black ones. I use a fixed filter width: 0.5 in both direction with a texture aligned grid (vw1 = 0 and uw2 = 0), a scale of 1 and no additional blur.
Is this kind of result expected, or am I doing anything wrong?

Brent Burley

unread,
Aug 28, 2013, 12:44:36 PM8/28/13
to pt...@googlegroups.com
On Wednesday, August 28, 2013 8:35:56 AM UTC-7, Lucas MALLEUS wrote:
I am trying to filter a texture applied on a triangle mesh using PtexTriangleFilter available in Ptex (using Gaussian one). However, I got some artifacts on the edges of faces. The example here is atlas reconstructed from Ptex filtered texture. Basically, it is a texture with fully white triangles and fully black ones. I use a fixed filter width: 0.5 in both direction with a texture aligned grid (vw1 = 0 and uw2 = 0), a scale of 1 and no additional blur.
Is this kind of result expected, or am I doing anything wrong?

Your filter footprint is not circular as you imagine and thus not continuous across faces.  Note that u and v are two of the three barycentric coordinates and their basis vectors are not orthogonal; on a characteristic (equilateral) triangle the three basis vectors are 120 degrees apart.  The filter footprint is specified with respect to these u and v basis vectors (w is redundant).  A footprint of {(.5,0), (0,.5)} forms a parallelogram whose sides are all length .5 with angles 120 and 60 and thus foreshortened in the w direction.  To get a circular footprint, you need a footprint vectors with right angles in the triangle basis.  If you imagine a cartesian frame where the triangle basis vectors are U = (1,0) and V = (-1/2, sqrt(3)/2)) then your cartesian footprint projected to the triangle basis is {( (.5,0).U, (.5,0).V), ((0,.5).U, (0,.5).V)} = {(.5,-.25), (0, sqrt(3)/4)}.  Note this is only one of many possible circular footprints; any cartesian frame would work.  If you plug those numbers into your test (and if my math and your ptex adjacency data are correct) then you should get continuous filtering.  It might be helpful to first try a regular triangle mesh such as the simple ptex triangle example.

[Btw, this may seem unnecessarily complicated but it's consistent with the rectangular filter if you are computing the filter extent by projecting the pixel (or ray) footprint.  In both cases you need to project the filter footprint into the texture basis by dotting it with dP/du and dP/dv.]

Lucas MALLEUS

unread,
Aug 30, 2013, 9:32:24 AM8/30/13
to pt...@googlegroups.com

 

Indeed, I didn't took into consideration the fact that my footprint wasn't circular. I built one using your comments and it works fine. Thank you very much for your help!
However, I am facing another problem I don't manage to identify the source. I tried to filter a really basic tri-mesh, made of 4 equilateral triangles that shape a large equilateral triangle.
The filtering does only work when adjacent edges ids across edges match. Edges id is either 0, 1 or 2, and if edge 1 is facing edge 2 on the adjacent face, then the filter does it wrong.
First picture represents the bad filtered texture, the second the good filtered one. What is actually surprising is that filter is not totally wrong, but only in the middle and the end of edges.
I have checked my adjacency data about a hundred times, and I can tell you it's right (compared to the triangle sample).
I have seen in the code that a rotation is called when edges ids don't match, but I am unable to know where is my mistake. Can you help me please?

Lucas MALLEUS

unread,
Aug 30, 2013, 10:18:19 AM8/30/13
to pt...@googlegroups.com
I investigated more about the differences between the two results posted, and it appeared that only the filtered values from the middle triangle are wrong. The filtered values from the 3 external triangles are correct...

Brent Burley

unread,
Aug 30, 2013, 10:42:17 AM8/30/13
to pt...@googlegroups.com
Can you attach the ptx file and corresponding obj file?  Then I can quickly check it using our tools.


On Fri, Aug 30, 2013 at 7:18 AM, Lucas MALLEUS <lucasm...@gmail.com> wrote:
I investigated more about the differences between the two results posted, and it appeared that only the filtered values from the middle triangle are wrong. The filtered values from the 3 external triangles are correct...

--
 
---
You received this message because you are subscribed to the Google Groups "ptex" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ptex+uns...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Lucas MALLEUS

unread,
Aug 30, 2013, 10:54:03 AM8/30/13
to pt...@googlegroups.com
Sure, here it is. Do you have any software that allows to directly display a triangle mesh under ptx format? I tried Opensubdiv and Mudbox, but it seems that none supported triangle texture properly.


--
 
---
You received this message because you are subscribed to a topic in the Google Groups "ptex" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ptex/j_PTOpa0MmA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ptex+uns...@googlegroups.com.
ptex_filtering.zip

Lucas MALLEUS

unread,
Aug 30, 2013, 10:58:39 AM8/30/13
to pt...@googlegroups.com
Sorry, joining the filtered texture ptex file.
test_filter_0.ptx

Brent Burley

unread,
Aug 30, 2013, 11:05:15 AM8/30/13
to pt...@googlegroups.com
We have a ptxview app that can display triangle ptex files.  We've been meaning to release it as open source but it is provided with prman in the mean time.

Brent Burley

unread,
Aug 30, 2013, 12:38:39 PM8/30/13
to pt...@googlegroups.com
Saving a ptx file out of our paint system using your obj file produces this adjdata (ptxinfo -f):
face 0:  res: 7 7 (128 x 128)  adjface: 3 -1 -1 -1  adjedge: 2 0 0 0  flags: (none)
face 1:  res: 7 7 (128 x 128)  adjface: -1 3 -1 -1  adjedge: 0 0 0 0  flags: (none)
face 2:  res: 7 7 (128 x 128)  adjface: -1 -1 3 -1  adjedge: 0 0 1 0  flags: (none)
face 3:  res: 7 7 (128 x 128)  adjface: 1 2 0 -1  adjedge: 1 2 0 0  flags: (none)

whereas your ptx files have:
face 0:  res: 7 7 (128 x 128)  adjface: 3 -1 -1 -1  adjedge: 2 3 3 0  flags: (none)
face 1:  res: 7 7 (128 x 128)  adjface: -1 3 -1 -1  adjedge: 3 0 3 0  flags: (none)
face 2:  res: 7 7 (128 x 128)  adjface: -1 -1 3 -1  adjedge: 3 3 1 0  flags: (none)
face 3:  res: 7 7 (128 x 128)  adjface: 1 2 0 -1  adjedge: 1 2 0 0  flags: (none)

The adjedge values differ but only for boundary edges where adjedge is ignored, so it should be OK.

I'm able to render with your textures.  Here's an example using "not_filtered.ptx" at a couple blur sizes.  Note: this is using loop subd.

Inline image 1Inline image 2

I noticed the texture data isn't perfectly clean and the triangles in the texture don't perfectly line up with faces; however this isn't affecting the filtered result.  Also I'm not sure why the textures don't seem to match the images you posted.
image.png
image.png

Lucas MALLEUS

unread,
Sep 2, 2013, 6:13:26 AM9/2/13
to pt...@googlegroups.com
I guess I did something wrong somewhere.
May I ask you if the following process is correct?


Ptex::String error_read;
PtexPtr<PtexCache> c(PtexCache::create());
c->setSearchPath(".");

//Creation of the filter from the PTEX texture to be filtered
PtexPtr<PtexTexture> input(c->get("input_file_to_be_filtered.ptx", error_read));
PtexTriangleFilter::Options opts(PtexTriangleFilter::f_gaussian, 0, 1.0);
PtexPtr<PtexTriangleFilter> filter ( (PtexTriangleFilter*) PtexTriangleFilter::getFilter(input, opts) );

//Evaluation of the filtered value at the point (uv[0],uv[1])
//The values in ww are the filter footprint vectors I filled the way you told me
filter->eval(result,0,3,i,uv[0],uv[1],ww[0],ww[1],ww[2],ww[3],1.0,0.0);

uv contains the coordinates of the center of the texel of the new texture to be written.

Lucas MALLEUS

unread,
Sep 3, 2013, 4:36:53 AM9/3/13
to pt...@googlegroups.com
After some tests, I managed to find a way to obtain the same filter on all the mesh. I consider a fixed circular filter [a,0,0,a] in the atlas space. I then write a change of basis from atlas space to UV ptex space to get the coordinates of the two vectors of the footprint, and I filter using these two ones. And the result is correct, whatever the orientation of the triangles is.
Thanks a lot for your advice, it helped me to find out a correct solution for the filtering!


--

Lucas MALLEUS

unread,
Sep 3, 2013, 12:12:45 PM9/3/13
to pt...@googlegroups.com
Reading the PtexFilter API once more, I noticed that:


uw1 U filter width 1, normalized [0..1]

vw1 V filter width 1, normalized [0..1]

uw2 U filter width 2, normalized [0..1]

vw2 V filter width 2, normalized [0..1]

which means that those values can't be negative? If it is the case, how could you have a circular footprint in an equilateral triangle?

Brent Burley

unread,
Sep 3, 2013, 3:49:37 PM9/3/13
to pt...@googlegroups.com
The API docs are out-of-date.  There was a time when the footprint was always rectangular, but now the footprint is an arbitrary parallelogram.  I'll fix the docs.


--
 
---
You received this message because you are subscribed to the Google Groups "ptex" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ptex+uns...@googlegroups.com.

Brent Burley

unread,
Sep 4, 2013, 11:23:38 AM9/4/13
to pt...@googlegroups.com
On Wed, Sep 4, 2013 at 8:01 AM, Lucas MALLEUS <lucasm...@gmail.com> wrote:
I actually didn't notice that filtering was only crossing one edge towards each direction at max (I just read this on a previous topic on this forum: https://groups.google.com/forum/#!topic/ptex/Q5ZgVsmIvM8). This explains the fact that thin triangles are badly filtered if the filter footprint is too large. Iterating a filter with smaller footprint allows dodging the problem, doesn't it ?
 
Perhaps, but I'm not clear on the use case.

If you want a filter that is much larger than the triangles, thin or not, then you will need some way to walk the neighborhood of faces.  At some point this will become prohibitive.  Personally, I've felt that it's dangerous to filter too far away from the local face because you may get data from a part of the model that is facing quite a different direction.  Also, the faces are not likely the same size so assumptions about appropriate filter width may not be valid for a large neighborhood.  It has also been my experience that when the filter reaches the size of the control faces, you are now at a sampling rate similar to the geometry and whatever anti-aliasing is being used for the geometry should likely be suitable for the textures.

Keep in mind that Ptex was intended and best used for subdivision surfaces, triangle textures being meant for Loop subd.  With Loop subd, it's my impression that thin triangles are generally avoided.  In our case at least, we use Loop only for cloth and only for the reason that triangle meshes are better suited for simulation and as-regular-as-possible triangles are preferred.

Lucas MALLEUS

unread,
Sep 4, 2013, 11:01:36 AM9/4/13
to pt...@googlegroups.com
I actually didn't notice that filtering was only crossing one edge towards each direction at max (I just read this on a previous topic on this forum: https://groups.google.com/forum/#!topic/ptex/Q5ZgVsmIvM8). This explains the fact that thin triangles are badly filtered if the filter footprint is too large. Iterating a filter with smaller footprint allows dodging the problem, doesn't it ?

--
 
---
You received this message because you are subscribed to a topic in the Google Groups "ptex" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ptex/j_PTOpa0MmA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ptex+uns...@googlegroups.com.

Lucas MALLEUS

unread,
Sep 6, 2013, 8:41:00 AM9/6/13
to pt...@googlegroups.com
Thank you for these details, I will consider them in my future work.
I actually made 2 mistakes in my code for the footprint calculation, and everything works fine now, by iterating the filter. The filtered texture reprojected in the atlas is quite amazing, as well as the result on mesh.


--
Reply all
Reply to author
Forward
0 new messages