Sign in to follow this  
janaka

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

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Nik02
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.
-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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by hplus0603
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.


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 this post


Link to post
Share on other sites
I found method for estimating curvature following paper give good methodologyc.
Is it possible to implement using HLSL shader languagec..please give your valuable commentsc
http://www.cs.princeton.edu/gfx/pubs/_2004_ECA/index.php

Share this post


Link to post
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
Hi Nik02

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

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Hi 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 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

Sign in to follow this