View Full Version : Direction of normals associated to new vertices

devdept

11-22-2009, 05:39 AM

Hi All,

Here is the problem definition:

Suppose you have a Quad face with a different normal for each vertex. Now we cut it because of a boolean operation. How shall we compute the new vertices normals? We are already using the face normal but the result is very unpleasant.

Is there a way to compute the contribuition of each original normal at the new vertex position and get a good guess?

The data available is of course the vertices position in 3D, the 4 original normal vectors and the face normal.

http://www.devdept.com/normals.gif

Thanks in advance,

Alberto

Ilian Dinev

11-22-2009, 05:59 AM

You'll later need code that does the same for texcoords and vtx-varyings, so a more general solution might be nicer from the beginning. Barycentric coordinates? Some helping Maths can be found in the nVidia presentation of correct gl_quad interpolation via geometry-shaders.

Also, I vaguely remember some Gradients maths from university, that handles this.

devdept

11-22-2009, 06:18 AM

Hi Ilian,

No, no need for texCoords yet, they are applied automatically later.

Isn't is the same problem of finding the pixel color of the following -famous- OpenGL triangle?

http://ondrew.googlepages.com/lua_triangle.png

If I knew how to compute the pixel color here I could also guess the normal everywhere in the surface above.

Thanks,

Alberto

Ilian Dinev

11-22-2009, 07:04 AM

Interpolating a value across a triangle is really simple:

1) transform the verts so that z=0 on each (move "camera" to look head-on onto the triangle). Now you have have 2D triangle that isn't degenerate (unless the input was degenerate).

2) split the triangle into 2 triangles, the division is a horizontal line that starts from the middle-Y vertex.

3) for each of the 2 triangles (one pointing up, another pointing down):

3.1) interpolate values linearly across edges, for "Y scanline". Interpolate linearly the two scanline-results by X value. => output result.

But as nVidia's paper shows, we can't just split quads and N-gons into triangles and expect nice interpolations.

devdept

11-23-2009, 05:00 AM

Ilian,

Unfortuantely we need to work in 3D not on screen space.

Is it not like drawing the color picker surface as in the picture below:

http://www.photoshopessentials.com/images/photo-editing/photo-filter/color-picker.jpg

In this case only three colors are involved but maybe it can be done also with four...

Thanks,

Alberto

Ilian Dinev

11-23-2009, 06:26 AM

The method I gave for triangle-interp is rather 3D :) . The use of 'scanline' terms was just to help cross-reference with rasterizers :) .

Lord crc

11-23-2009, 06:34 AM

The normal approach would be to use Phong normal interpolation. It's essentially using linear interpolation of the vertex normals, which is then normalized. You can read up on it here: http://local.wasp.uwa.edu.au/~pbourke/texture_colour/interpolation/

devdept

11-23-2009, 07:43 AM

Wow Lord, at the first sight it looks exactly what we were looking for.

Leave me the time to read it carefully.

Thanks,

Alberto

devdept

11-23-2009, 01:08 PM

Hi Lord,

Yes, it is exactly what we were looking for.

One point is by the way not clear to me in the suggested doc ( http://local.wasp.uwa.edu.au/~pbourke/texture_colour/interpolation/):

"One way is to choose a major axis by specifying a normal. The plane with this normal that passes though the point in question cuts two of the polygon edges, this is used as the extended line"

If I understand well we need to chose a plane to split two opposite Quad edges and get two new normals in these points.

How shall we chose this plane?

Thanks,

Alberto

Lord crc

11-23-2009, 01:49 PM

I must admit I've only used the barycentric version of this method. The way I interpret that passage is that you pick one of the normals consistently for all points P within the quad. Which normal you pick is arbitrary, but it should be the same for all points within the quad. Then you construct a plane with that normal, going through the point in question P. This plane then intersects two edges, and these edges should be used for the initial interpolation.

Please note the final remark, ie you should normalize after interpolating between the initial edges, then again after you interpolate between those two "edge-point normals". I incorrectly stated only to do the latter step.

devdept

11-23-2009, 02:16 PM

Lord,

is that you pick one of the normals consistently for all points P within the quad

I really can't understand this. Suppose you have a face laying on XY plane and you chose the same plane for splitting. You will not find any intersection point on edges. It is not so easy to select the right plane, what do you think?

Am I missing something?

Thanks,

Alberto

Lord crc

11-23-2009, 05:44 PM

Well, if all normals point in the Z direction (I'm going to assume the same Z direction, since the mesh should be "nice"), then there's nothing to interpolate. If one of the normals does not point directly in the Z direction, pick it, and it will (should :) split the edges.

I'm not certain what would be a good criteria for picking the "splitting normal". Perhaps pick the one with the greatest angle to the face normal? From what I can gather, this should work in all cases except when all normals equal the face normal, in which case there interpolated normal is the face normal as well.

devdept

11-24-2009, 12:48 AM

You are right, it should work.

What about getting a normal on the edge. Can the following equation work?

normalOnEdge = d1 * N1 + d2 * N2 / 2

Where d1 is 0.2 and d2 is 0.8 (the relative distances from the vertices)

Thanks,

Alberto

Lord crc

11-24-2009, 02:03 AM

Regular linear interpolation should be used, so if you drop the division by two there it should work :)

devdept

11-24-2009, 02:13 AM

Thanks Lord,

The n1+n2/2 is not working too. It does not take in account the distances from original vertices. Far better to check the relative distance on the edge and split the line connecting normals endpoint at the same percentage.

Thanks so much again for your help.

Now hopefully we can implement the whole algorithm.

Alberto

EDIT: You are right, we are saying the same thing.

Lord crc

11-24-2009, 07:38 AM

You're welcome. Hope it works out alright :)

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.