best way to recompute normals?

I have a channel sop bringing in a blended cg head. I need to recompute normals after that.
1 - what is the fastest way to do that?
2 - I need NOT to recompute normals around the edge of the model, where it needs to connect with the rest of the body (and so if I don’t recompute normals they’ll match). Is whatever you’re going to suggest allowing me to exclude those vertex from having their normals recomputed - ie a group field)?

thanks!!

Currently there isn’t a way to only compute normals on a subset of the primitives. Also there isn’t really a fast way either. Use a Attribute Create SOP, but it’s slow. If your point count is low enough it may be fast enough though.

As you know there is GPU based solution, but it’ll be a while (i.e many months) until I can add this to Touch as its a very large task.

Sorry

well the facet sop does that, and I assume the group field allows you to do it to a selected subset.

It’s not fast of course, hence my question.

We’ll deal, thanks,
d

As far as I could tell from the code the Facet SOP doesn’t do it either actually.

well we definetly see a huge change in the geo if - after the channel sop - we add a facet and recompute normals - looks a whole lot better, like there’s no comparison.

what’s it doing then?

What I meant is that it does recompute them, but it doesn’t do it based on the selected group. It does every point.

shoot.

Well what we’re thinking is to blend the normals in our blend network, then feed those to the object through the channel sop. Wouldn’t that work?

d

Yup, thats a good idea.

Hey malcolm, what GPU based solution are you talking about?

Geometry Shaders. In a geometry shader you have access to all 3 points of a triangle at a single time. From this you can calculate a normal. However this normal will be a ‘face’ normal (normal is the same for all 3 points in the triangle) and you’ll get a faceted look to your shading.
To aid with this, geometry shaders also have a feature where along with the 3 points that make up a triangle, the 3 points that will describe the 3 adjacent triangles can also be given. Using the adjacent triangles you can blend between adjacent face normals and get a blended normal that will give a smoother look. This look still won’t be perfect yet as you still havn’t blended between enough triangles. Take a look at the attached image.


The center triangle is the one you are currently drawing. The 3 points of this triangle are the normals we want to figure out. The other 3 white triangles are the ones you can calculate using the 3 adjacent vertices the geometry shader will give you.
To get super smooth shading you still need 3 more points (red dots) of information to construct the red triangles. Using the face normals of these red triangles you will now get the correct blended normals that will give you smooth shading. This will match the result our CPU based normal generation would create (Attribute Create, Facet SOP etc.). So to get a correct normal for a single point you need to blend 5 face normals from 5 triangles.

However currently there isn’t a way for Touch to send in the adjacency information into the geometry shader (this is the work I need to do). Also we would need a way to create vertex attributes that contain the positions of the red dots.

It may actually be possible to do this in a vertex shader if you can create vertex attributes for each vertex that contain the position of the 5 vertices that are adjacent to it. If you could do this then in the vertex shader you can calculate all 5 face normals and blend them. I’m not sure if Houdini’s Point SOP has been made powerful enough to create this vertex information. I doubt Touchs can right now. So thats another thing I need to add.

Actually now that I’ve thought through it some more, the vertex shader approach may ever be faster…

1 Like

As a workaround for now. I’ve added Compute Normals and Compute Tangent check boxes to the Channel SOP. This still has a cost, but it’ll be a lot cheaper than using a separate Attribute Create or Facet SOP.

greeat! is this release downloadable now?

No, not yet. Not sure when we’re releasing another build exactly. I’ll check with Greg. The newer builds also have some multithreaded speedups for geometry rendering that I’ve added (some of the cost of SOP cooking as been offloaded to another CPU). This will also speedup the Channel SOP for you, but these changes are new and possibly buggy. I’d suggest you run your app a lot and test things out to see if there are any issues that come up .

I know this thread is 10 years old now, but in case someone comes reading through this from search results: I realised (after the fact) I implemented a technique similar to what malcolm was suggesting was possible in this thread (emulating the CPU vertex normal computation in a shader on the GPU.)

viewtopic.php?f=20&t=12186&p=47430