Normal mapping implementation

Discussion related to the implementation of new features & algorithms to the Core Engine.

Moderators: jromang, tomb, zcott, coordinators

Re: Normal mapping implementation

Postby Lord Crc » Sun Jul 17, 2011 12:11 pm

Thanks SATtva!

Here's a small sample of how to use it:

Code: Select all
Texture "Tex.002_float" "float" "normalmap"
   "string filename" ["normal_mapping\\Scene\\00001\\xnormals_normals.PNG"]
   "float gamma" [1.00000000000000]  # <-- VERY IMPORTANT
   "string mapping" ["uv"]
   "float udelta" [0.000000000000000]
   "float uscale" [1.000000000000000]
   "float vscale" [-1.000000000000000]
   "float vdelta" [0.000000000000000]


MakeNamedMaterial "Material.001"
   "texture bumpmap" ["Tex.002_float"]   # Use as regular bump map
   "color Kr" [0.69999999 0.69999999 0.69999999]
   "string type" ["mirror"]


edit: Pushed my initial implementation. Let's see if I managed to miss something :lol:
May contain traces of nuts.
User avatar
Lord Crc
Developer
 
Posts: 4517
Joined: Sat Nov 17, 2007 2:10 pm

Re: Normal mapping implementation

Postby moure » Mon Jul 18, 2011 3:45 am

Thanks a lot Lordcrc :D

Here is my first test , absolutely successful, Carved with alpha map some details in a 6 million polys plane and extracted the map. Applied it in a ....one (or maybe 4) poly plane and here is the result after 5 minutes of rendering. Notice the shadows and the reflections :)

Also i include the normal map in case anyone wants to make a test. Had to 7zip it cause it was 12 mb.

EDIT: I guess the bump amount when you use a normal map works as a percentage, i had to put it to 1 to get the correct amount of it in contrast to when using regular height maps that white is 1 meter and you have to scale it to 0,005 for example to get correct results.
Attachments
Plane_Perforated_metal.7z
Normal Map
(5.59 MiB) Downloaded 46 times
test_normal_map_plane.png
Normal map on a plane
User avatar
moure
Developer
 
Posts: 411
Joined: Sun Sep 26, 2010 4:32 am
Location: Greece

Re: Normal mapping implementation

Postby moure » Mon Jul 18, 2011 5:41 am

Another test, this time i uvmapped a cube (with some subdivisions) and made an normal map with the help of nvidias normal map plugin for photoshop http://developer.nvidia.com/nvidia-texture-tools-adobe-photoshop
Again the results are great even on edges there seems to be no issue at all.
Attachments
Cube_000000.jpg
Normal Map on cube
User avatar
moure
Developer
 
Posts: 411
Joined: Sun Sep 26, 2010 4:32 am
Location: Greece

Re: Normal mapping implementation

Postby jensverwiebe » Mon Jul 18, 2011 12:12 pm

Jup, seems fine. Here a little test with normalmap created with NMG ( normal map generator freeware ):


normal_map_investigation1.png



Jens
User avatar
jensverwiebe
Developer
 
Posts: 2130
Joined: Wed Apr 02, 2008 4:34 pm

Re: Normal mapping implementation

Postby Lord Crc » Mon Jul 18, 2011 12:24 pm

Thanks for testing guys! And thanks for the scene Moure, it'll come in handy when nailing down those last issues.

moure wrote:EDIT: I guess the bump amount when you use a normal map works as a percentage, i had to put it to 1 to get the correct amount of it in contrast to when using regular height maps that white is 1 meter and you have to scale it to 0,005 for example to get correct results.


Yes, this is because the scale is "baked" into the normal map to begin with. You can think of normal maps as "relative bumps" while height maps as "absolute bumps". As such the scale for normal maps is relative, while absolute for height maps.
May contain traces of nuts.
User avatar
Lord Crc
Developer
 
Posts: 4517
Joined: Sat Nov 17, 2007 2:10 pm

Re: Normal mapping implementation

Postby J the Ninja » Mon Jul 18, 2011 1:38 pm

And yes, combining normal and bump maps definitely works. Multimix is quite handy for stacking them, and you can scale down your bump map from right within the texture:
Screen shot 2011-07-18 at 11.23.49 AM.png
Screen shot 2011-07-18 at 11.23.49 AM.png (17.56 KiB) Viewed 1466 times


The torus with its normal map and a blender_clouds (voronoi crackle) bump map:
combo.jpg
-Jason

Material DB Admin
User avatar
J the Ninja
Developer
 
Posts: 2249
Joined: Wed May 19, 2010 9:54 pm
Location: Portland, USA

Re: Normal mapping implementation

Postby Lord Crc » Tue Jul 19, 2011 11:39 am

Good news everyone!

mfoxdogg managed to put me in contact with Morten Mikkelsen, which has written a thesis on bump mapping, with weight on sampled normal maps. He assured me that my current method will be fine for "plain" normal maps (like the ones Moure has used here), but will fail for sampled normal maps (as in the torus I posted).

To render the sampled normal maps correctly it's absolutely essential that the tangent space used during reconstruction matches the tangent space used during sampling ("baking"). In order to make this easier, Morten has created some open source code to consistently create "proper" tangents for meshes, even if vertex order is changed etc. Blender and xNormal now uses his code, and thus I think we should do as well.

In order to support his code, we'll also need a vertex welder (he has one available for that too), as his tangent space code returns an unindexed mesh back.

In addition we'll need to add two new vectors to the RayDifferential class: "tangent" and "bitangent". I propose we add another constructor which accepts these, the old ones just normalize dpdu and dpdv. These new fields will then be used when transforming the normalmap normal back into object space, instead of the current dpdu, dpdv.
edit: Hmm can we just reuse dpdu,dpdv directly for this in GetShadingGeometry? I forgot that the shading geometry's dpdu,dpdv doesn't actually follow u or v.

Since this will require the storage of an additional vector per vertex (the bitangent can be recovered on the fly), I think we should make a parameter to control this behavior. It should then be enabled for "baked" meshes only.
May contain traces of nuts.
User avatar
Lord Crc
Developer
 
Posts: 4517
Joined: Sat Nov 17, 2007 2:10 pm

Re: Normal mapping implementation

Postby jeanphi » Wed Jul 20, 2011 2:37 am

Hi,

In GetShadingGeometry dpdu and dpdv are only used to have a coordinate system to compute the shading normal, we could use any coordinate system there (in case there are no UV coordinates we already fall back to a random system), so there's no problem using the tangent bitangent space for that, quite the contrary.
Actually this might be the occasion to rearchitect the UV stuff so that the raydifferential doesn't depend that much on the UV map and we compute UV stuff when needed with support for more than 1 UV set per mesh.

Jeanphi
jeanphi
Developer
 
Posts: 6624
Joined: Mon Jan 14, 2008 7:21 am

Re: Normal mapping implementation

Postby syndaryl » Wed Jul 20, 2011 8:06 pm

jeanphi wrote:Actually this might be the occasion to rearchitect the UV stuff so that the raydifferential doesn't depend that much on the UV map and we compute UV stuff when needed with support for more than 1 UV set per mesh.


Hurray!
Roter Sand und weisse Tauben \ Laben sich an meinem Blut
Am Ende gibt es doch ein Ende \ Bin ich doch zu etwas gut
User avatar
syndaryl
 
Posts: 154
Joined: Sun Sep 05, 2010 11:28 pm

Re: Normal mapping implementation

Postby Lord Crc » Thu Jul 21, 2011 2:59 am

Mind if I commit the added fields to RayDifferential I needed? It now works, and I'd rather have the working code in the repo, we can then refactor it afterwards. It adds two vectors and a float.

I'm adding my current results. First Blender's results, just for comparison. Next up is the Lux results. Compared to BI I think it's quite good indeed.

I still have to clean up the code a wee bit (debug code ftw!).

A BIG thanks to Morten Mikkelsen for his assistance!
Attachments
normal_mapping_bi_ref.png
Blender - Hires mesh
normal_mapping_bi_mapped.png
Blender - Lowres mesh + baked normal map
normal_mapping_ref2.png
LuxRender - Hires mesh
normal_mapping_mapped6.png
LuxRender - Lowres mesh + baked normal map
May contain traces of nuts.
User avatar
Lord Crc
Developer
 
Posts: 4517
Joined: Sat Nov 17, 2007 2:10 pm

PreviousNext

Return to Architecture & Design

Who is online

Users browsing this forum: No registered users and 0 guests