janaka 122 Report post Posted November 13, 2004 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 ideac Thanks 0 Share this post Link to post Share on other sites
Nik02 4352 Report post Posted November 13, 2004 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. 0 Share this post Link to post Share on other sites
janaka 122 Report post Posted November 13, 2004 thanks Nik02 Thank you very much for your idea I am new for 3D world.... any body have visible example or tutorial thanks 0 Share this post Link to post Share on other sites
janaka 122 Report post Posted November 13, 2004 any body have visible example or tutorial 0 Share this post Link to post Share on other sites
neneboricua19 634 Report post Posted November 13, 2004 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 0 Share this post Link to post Share on other sites
Nik02 4352 Report post Posted November 13, 2004 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 0 Share this post Link to post Share on other sites
Geoffrey 612 Report post Posted November 13, 2004 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. -NikI 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) 0 Share this post Link to post Share on other sites
Geoffrey 612 Report post Posted November 13, 2004 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. 0 Share this post Link to post Share on other sites
janaka 122 Report post Posted November 13, 2004 Thanks Geoffrey I am interested your method please explain your old code thank you very much for helping me. 0 Share this post Link to post Share on other sites
Nik02 4352 Report post Posted November 13, 2004 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] 0 Share this post Link to post Share on other sites
Geoffrey 612 Report post Posted November 13, 2004 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. 0 Share this post Link to post Share on other sites
Nik02 4352 Report post Posted November 13, 2004 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 0 Share this post Link to post Share on other sites
hplus0603 11362 Report post Posted November 13, 2004 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. 0 Share this post Link to post Share on other sites
Nik02 4352 Report post Posted November 13, 2004 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... 0 Share this post Link to post Share on other sites
janaka 122 Report post Posted November 14, 2004 Hi hplus0603please give me little example code....................it's easy to understand.. 0 Share this post Link to post Share on other sites
janaka 122 Report post Posted November 14, 2004 I found method for estimating curvature following paper give good methodologyc. Is it possible to implement using HLSL shader languagec..please give your valuable commentsc http://www.cs.princeton.edu/gfx/pubs/_2004_ECA/index.php 0 Share this post Link to post Share on other sites
Nik02 4352 Report post Posted November 14, 2004 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. 0 Share this post Link to post Share on other sites
Guest Anonymous Poster Report post Posted November 14, 2004 Hi Nik02 how about .FX file????????????? can we implement as FX effect file 0 Share this post Link to post Share on other sites
Nik02 4352 Report post Posted November 14, 2004 Quote:Original post by Anonymous PosterHi Nik02 how about .FX file????????????? can we implement as FX effect fileThe 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, 0 Share this post Link to post Share on other sites