A patch to improve normal mapping

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
RyanClark
Posts: 15
Joined: Sun Jul 22, 2007 7:34 am
Location: Chicago / Austin
Contact:

A patch to improve normal mapping

Post by RyanClark »

Hi,

This code preserves the artist's original normals when calculating tangent space. This way, normal-mapped models should look closer to the artist's intent. Smooth surfaces will stay smooth, and flat surfaces will stay flat.

Here's an illustration:

Image



You can grab the code here:
http://ryanclark.net/irrlicht/SeamlessT ... ht1.31.zip


You can grab a precompiled Win32 Visualstudio DLL here:
http://ryanclark.net/irrlicht/Irrlicht1 ... ngents.zip


This can probably use more testing. I've only compiled in Visual Studio and haven't tested with a wide range of models.

cheers,

-Ryan
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

Are there any FPS differences? (Just wondering :P)
RyanClark
Posts: 15
Joined: Sun Jul 22, 2007 7:34 am
Location: Chicago / Austin
Contact:

Post by RyanClark »

I expect faster performance, since models turn out smaller than with the default code. I haven't tested, though.

If you're generating tangent space every frame, such as for a dynamic mesh, then you might find the default Irrlicht code faster.

You can toggle between the methods at compile time with #define USE_SEAMLESS_TANGENTSPACE
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Hey, cool. There had been some efforts in doing such an extension some month ago, but I think they never finished the stuff. I'll have a look at it soon. Is this under zlib-license in case we add it to the core library?
RyanClark
Posts: 15
Joined: Sun Jul 22, 2007 7:34 am
Location: Chicago / Austin
Contact:

Post by RyanClark »

Sure. Feel free to publish the code changes under whatever license you'd like!
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Whoa awesome I was in need of this (For non other than to render bumpmapped planets smoothly :P )

Thank you RyanClark :D
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Virion
Competition winner
Posts: 2149
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

keep it up irrlicht is getting better. :D
My company: https://kloena.com
My profile: https://zhieng.com
My co-working space: https://deskspace.info
My game engine: https://kemena3d.com
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

One question after looking at the code: You're just taking the average of the neighbouring tangents and binormals. Since the normal is left unchanged it won't fit the binormal then. I'd have thought that you need to calculate binormal and tangent based on the current normal (and leaving it unchanged).
RyanClark
Posts: 15
Joined: Sun Jul 22, 2007 7:34 am
Location: Chicago / Austin
Contact:

Post by RyanClark »

You're right - If your normals aren't smooth they won't be perfectly orthogonal to the tangent planes. I don't know how much difference that makes. It seems to look good, but might look better if I add a postpass to rotate the tangent and bitangent into alignment with the pre-existing normal.

My newest code recomputes the normal vectors, so that won't be a problem, at least for this version.

It uses an angle-weighted average to compute a more realistic tangent space. The angle-weight method is used in recalculateNormals as well, so vertex-lighted materials are improved as well as normal-mapped ones.

Here's the new code. You can compare methods by toggling USE_ANGLE_WEIGHTED_NORMALS. Give it a spin!

http://ryanclark.net/irrlicht/CMeshManipulator.cpp

cheers,

-Ryan
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Post by Nadro »

Why new Irrlicht doesn't use this code for improve createMeshWithTangents?
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Probably because the post was buried here on the forums, I've added it to the tracker now though. Someone's bound to add it before 1.5 :)
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I wasn't really sure about the old version, due to the concerns I posted. I think I lost track of this due to some other work, at least I don't know if I ever tried the new version. At least making it the default normals and tangent calculations might require lots of tests, making it just another manipulation method would be ok.
Also, last time I tried patched from ryanclark I had to port lots of stuff, because he did not develop against the latest SVN versions. This is no general problem, but can delay addition ot the library quite a lot.
Post Reply