# how to estimate curvature on 3D mesh by using HLSL shaders?

This topic is 4775 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all I want to know how to implement curvature shader , in other words how to estimate principle curvature on 3D triangular mesh. I shall be very grateful to you if could you give ideac Thanks

##### Share on other sites
If you want to calculate local vertex curvature, you need to take into account it's neigbours' relative positions. This cannot be done in purely shader logic, since a vertex shader has only the current vertex available as input data. However, once you have calculated the curvatures in your program, you can save them as per-vertex data and feed them to the shader that way.

##### Share on other sites
thanks Nik02

Thank you very much for your idea I am new for 3D world.... any body have visible example or tutorial

thanks

##### Share on other sites
any body have visible example or tutorial

##### Share on other sites
You haven't really provided enough information for anyone to give you a sample because we don't know what you're trying to do.

I know that if you want to compute smooth normals for a mesh (i.e. not just use the normal of the triangle the vertex is part of) you need to take into account the "curvature" of the area around the vertex.

The algorithm would go something like this:
for every vertex in the mesh{  for each triangle that uses this vertex  {    compute the normal of this triangle (use a cross product)  }  Normal of this vertex is the average of the normals of all the triangles that use the vertex.}

This will give your mesh a more "curved" look when it is illuminated because the normals are not just from the triangle faces; they are smoothed out over the surface of the mesh.

If this isn't what you're looking for, can you give more detail?

neneboricua

##### Share on other sites
Incidentally, curvature (AKA derivative of radius) can be calculated in a similar way that neneboricua explains the generation of smooth normals.

For each triangle sharing a vertex, compute the cross products to establish triangle normals. Then take the sum of [each triangles normal]/[triangle size] dot [original vertex normal] and divide the sum by the number of triangles. The resulting number, as far as I can tell, should represent the absolute weighted curvature at the vertex point.

To determine whether the curvature is convex or concave (the sign of curvature), you should analyze the directions of each neighbor triangle normals in relation to the normal of the vertex you are calculating the curvature for, and take the dominant side as the result.

This theory was formed during writing this post - take it as an untested concept :)

-Nik

##### Share on other sites
Quote:
 Original post by Nik02For each triangle sharing a vertex, compute the cross products to establish triangle normals. Then take the sum of [each triangles normal]/[triangle size] dot [original vertex normal] and divide the sum by the number of triangles. The resulting number, as far as I can tell, should represent the absolute weighted curvature at the vertex point. -Nik

I did something similar once, and I think something like this will work well. I don't see the logic behind dividing by the triangle size though - I'd weight according to the angle made by the triangle at that point, instead.

On a practical note, make sure you're normals are normalized! (i.e. have length one)

##### Share on other sites
I've had a look at my old code, and what I actually did is slightly different. It's still based on cross and dot products, and a weighted average, but the vectors involved are different. I'll try to explain it if you're interested.

##### Share on other sites
Thanks Geoffrey I am interested your method please explain your old code thank you very much for helping me.

##### Share on other sites
I must've thought about the triangle area contribution when I said "triangle size". However, the further the other vertices are from the current vertex, the less effect they should have towards the curvature.

Geoffrey, I'd also like very much to read about how you implemented a solution to this problem [smile]

##### Share on other sites
OK, my algorithm was for a subtly different situation which I don't really want to explain, so no code - sorry. The idea though is to dot product the normal at the point with various normalized vectors to surrounding points on the surface.

If the surface is flat, these dot products will clearly be zero.

If the surface is concave (curving in the direction of the normal as you move away from the point), the surface vectors will actually have a small positive component in the direction of the normal - the dot products will be positive.

If the surface is convex (curving in the opposite direction to the normal as you move away from the point), the surface vectors will have a small negative component in the direction of the normal - the dot products will be negative.

I hope you can visualize this.

The problem is then:

1) to choose which surrounding surface points to sample. If you're calculating curvature at a vertex, you could use the vertices that are connected to it by triangle edges.

2) after performing the calculations, to decide how to weight the combination. I'm becoming increasingly unsure what to suggest - when I did this myself the situation was a bit special. I guess an average would be acceptable, but it's certainly not the best approach possible.

Well that's about it. Let me know if you can't make sense of it.

##### Share on other sites
This is clearly a problem worth pondering - but not for today :) I'm going to sleep now!
I'll get back to the topic as soon as possible...

-Nik

##### Share on other sites
Curvature is just ddx and ddy of the normal over a fixed world-space distance. Note that you typically only get per-fragment derivatives in the current shader models, so you have to divide by the world-space size of the fragment to get the actual curvature if you use these functions.

##### Share on other sites
Quote:
 Original post by hplus0603Curvature is just ddx and ddy of the normal over a fixed world-space distance. Note that you typically only get per-fragment derivatives in the current shader models, so you have to divide by the world-space size of the fragment to get the actual curvature if you use these functions.

Yes, and for per-vertex calculation, divide by the triangle size (as I mentioned), the "fragment" size at vertex level.

EDIT: You guys can't take away my sleep [smile] Going now, for real...

##### Share on other sites
Hi hplus0603

please give me little example code....................it's easy to understand..

##### Share on other sites
I found method for estimating curvature following paper give good methodologyc.
http://www.cs.princeton.edu/gfx/pubs/_2004_ECA/index.php

##### Share on other sites
Since the core algorithm of actually generating the curvature value fundamentally needs access to the vertices that any given vertex shares it's triangles with, you can't calculate it in the vertex shader - you only have access to one vertex at any time. Vertex shader is good in visualizing the pre-calculated data, however; it is trivial to color a vertex based on the curvature value stored in that vertex.

Interesting paper, though! It reinforces my understanding of the concept, and I see that my idea of the curvature calculation is very close to their theory and implementation. Their method of weighting the neighbor contribution is very good compared to pure triangle size consideration.

##### Share on other sites
Hi Nik02

how about .FX file????????????? can we implement as FX effect file

##### Share on other sites
Quote:
 Original post by Anonymous PosterHi Nik02 how about .FX file????????????? can we implement as FX effect file

The same architectural limitations still apply, so I have to answer "no" to this as well. Shaders included in .fx files get to be compiled and/or assembled to ordinary shaders that get passed to the d3d device, just like you'd do manually with SetVertexShader or SetPixelShader.

Even if you could implement the algorithm in a .fx file or a standalone shader, you'd still have the same amount of work that your host implementation would require. Therefore, I suggest just using the language of your choice for this task, the same one that you use to write the host program. You are not going to find a vertex shader compatible with current consumer 3d architectures that could do the whole calculation of mesh curvature for you,

##### Share on other sites

This topic is 4775 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628641
• Total Posts
2983981

• 10
• 18
• 20
• 13
• 9