Vertex normals weighted by face area

Announcements and discussion regarding any projects related to Cyan Worlds' Plasma Engine including (but not limited to) CyanWorlds.com Engine, Drizzle, OfflineKI, PyPRP, and libHSPlasma.

Vertex normals weighted by face area

Postby Christian Walther » Sat Aug 09, 2008 7:53 am

I had planned to do some modeling today, and ended up coding again... :lol:

I was trying to make shapes with flat faces and smoothly rounded edges, and noticed that they looked really crappy in Uru (top right cube in the following picture).

renormal.jpeg
renormal.jpeg (40.98 KiB) Viewed 5673 times

This is because to compute the vertex normals (that are exported by PyPRP), Blender averages the face normals of all adjacent faces of a vertex, which means that even the normals of the cube faces that are supposed to be flat are bent outward and the face is shaded as if it was curved (bottom right in the picture). What I want is the look at the top left, which is achieved by vertex normals as shown at the bottom left.

So I searched the web for a while and came to the conclusion that Blender just can't do that. It does not have the capability to let the user arbitrarily modify vertex normals. The normals can be modified from Python (which is how I got the screenshot), but they are reset to the default averaged normals again as soon as edit mode is left.

What to do? Since the normals can be modified at least temporarily, we could do that right before exporting, inside PyPRP. So that's what I did, and the result is available as revision 318 in my experimental branch http://svn.guildofwriters.com/pyprp/contrib/CWalther/experimental/.

With this extension, every object that has property renormal set to areaweighted, either as a Blender property or in AlcScript, has its normals recomputed. All other objects are left alone with their default Blender-computed normals. To compute a vertex normal, it still averages the face normals of the adjacent faces, but it does this weighted by the area of each face. That way, my big cube faces contribute the major part of the resulting normal, while the small bevel faces have little influence. Other algorithms could conceivably be added to this system in the future, such as weighting by some power of the face area or by the angles of the face corners, explicitly specified normals encoded in a vertex color layer, etc.

Perhaps some of you find this useful too. Testing and feedback is welcome!

Edit: For those who don't wan't to deal with Subversion and/or with the unstable trunk version of PyPRP, here is the relevant file from PyPRP 1.5.0 with just this modification applied - unzip and drop into your .blender/scripts folder (after renaming the existing one as a backup):
prp_DrawClasses.py-renormal-1.5.0.zip
(17.32 KiB) Downloaded 537 times
Christian Walther
 
Posts: 443
Joined: Sun Jun 08, 2008 3:10 am
Location: Switzerland

Re: Vertex normals weighted by face area

Postby Nadnerb » Sun Aug 10, 2008 2:47 pm

I like this feature a lot, and after playing with it for a while, I decided (as you did) that it really ought to be a feature of blender. :P Anyway, I've added it to the pyprp trunk.

Note: changed the alcscript property to read from the visual section of the object script.
Image
Live KI: 34914 MOULa KI: 23247 Gehn KI: 11588 Available Ages: TunnelDemo3, BoxAge, Odema
Nadnerb
 
Posts: 1057
Joined: Fri Sep 28, 2007 8:01 pm
Location: US (Eastern Time)

Re: Vertex normals weighted by face area

Postby Christian Walther » Mon Aug 11, 2008 11:18 am

Cool, thanks! 8-)

Modifiable normals seem to be quite an often-requested feature in Blender, particularly from game artists and other low-poly modellers. I have not seen any sign of anyone working to implement it though.

Nadnerb wrote:Note: changed the alcscript property to read from the visual section of the object script.

Good point. It does break the symmetry between AlcScript and Blender property a bit, but as far as I see there isn't a lot of such symmetry in the rest of PyPRP to begin with, so that's probably OK.

:idea: Remind me to write some documentation in the wiki before 1.6 is released.
Christian Walther
 
Posts: 443
Joined: Sun Jun 08, 2008 3:10 am
Location: Switzerland

Re: Vertex normals weighted by face area

Postby Jojon » Tue Aug 12, 2008 5:55 am

Excellent!
Jojon
 
Posts: 1116
Joined: Sun Sep 30, 2007 5:49 am


Return to Plasma Development

Who is online

Users browsing this forum: No registered users and 20 guests