Jump to content

[Blender Exporter] Question about normal material


xaero59
 Share

Recommended Posts

I noticed that the normal material doesn't behave like other materials in blender ( see : self.textures.append(Texture('bumpTexture', 1.0 / mtex.normal_factor, mtex, mesh, exporter)) )

The normal level is = to 1/lvl , is it a bug or is it required by bjs or blender ?

Link to comment
Share on other sites

Hi @xaero59.  No replies yet, huh?  Sorry.  May I try to clarify?

You are talking about this: https://github.com/BabylonJS/Babylon.js/blob/master/Exporters/Blender/io_export_babylon.py#L2069  ... yes?

You are asking why line 2069 is different... than lines 2065 and 2073, yes?  Why the extra mathematical division for bump map level?  *nod*

I also see it happening at https://github.com/BabylonJS/Babylon.js/blob/master/src/Materials/babylon.standardMaterial.ts#L819

Let's request an audience with @JCPalmer, who has been known to be an export in experting.  Errr... I mean... an expert in exporting.  :)

But, all forum users... if you have info on this unique decimal-point-shifting for level... on normal/bump maps... we would love to hear it.  Thanks!

Link to comment
Share on other sites

@xaero59, @Wingnut: @JCPalmer. Well I'm not the best person to understand the whys and wherefores of coding but I do notice that one of Wingy's links goes to "io_export_babylon.py" - version 4.6 of the exporter. However, as Jeff points out the problem line was " in exporter before I started ". So why?

All I can do is to comment on normal maps in general and how they are created. Baking normal maps with red, green and blue channels can get complicated. Different software can have different definitions about what each channel represents.

See from about 45 secs of this video that compares what the channels represent in Maya and UDK. Blender is different again.

I'm not sure whether this is connected to your issue, but always be careful with normal maps.

cheers, gryff :)

Link to comment
Share on other sites

Found when the modification happened : https://github.com/BabylonJS/Babylon.js/commit/71539bb29371fca67a6ab3329265b6a07e1050cc


Since the bump level is set directly in the babylon file, that doesn't seem very relevant to me.

@gryff You are right on this, personally I'm working with collada files imported into blender , the original meshes use a greyscale bump map , so I'm converting them into normal map , it's not perfect but it works, the only thing is that I need to adjust the bump level very often.

Link to comment
Share on other sites

Yeah, Jack Caron worded that git PR...

"use the inverse of the normal factor to match the inverse level in the loader"

match ==  compensate-for?  I'd say yes.

I wonder if we should scour the change/version logs for Blender, and see if/when a change happened to that value(s). 

But as Gryff kindly pointed-out... it is a bit of a moving target... in various software.

All in all, I think Jack's PR was to compensate-for (counter-act) an unusual calculation... seen in the exporter.  Jack could not access the exporter code, so he compensated by modding the framework. (in theory).  But still... somebody put that code in the exporter... long ago, and there was probably a reason. 

Perhaps we should examine the code of other Blender exporters, and see if others did the same?

Let's look at "them".  https://github.com/mrdoob/three.js/blob/master/utils/exporters/blender/addons/io_three/exporter/material.py#L82

Hmm... bump_scale and normal_scale.   Lets go deeper... like here and here.  Hmm, is there more to this story, my dear Watson?  :)   Perhaps Blender only provides these little "scalar?" values (fractions), and perhaps BJS needs a big fat integer to use for .level?  I'm just speculating... but... I smell something.  heh

Link to comment
Share on other sites

 

6 hours ago, V!nc3r said:

So can we patch this line by deleting "1.0/" ? I vote yes :)

(just a little tip in case someone don't know : you can do maths directly in number input in Blender, very useful in this case xrAdD7G.png)

I vote yes too , and thanks for the blender tip !! Very useful indeed.

My theory with the exporter modification is that maybe in the past when BJS was loading imported mesh the bump material was processed using 1.0/lvl as well ( so let's say one put 0.5 as the bump level in blender, it would give : 1.0/0.5 = 2 , 1.0/2 = 0.5 ) but it's not the case anymore and the bump level is just directly processed without any additional maths.

Link to comment
Share on other sites

To add to this topic about the issue I mentioned above - an example. See images below.

First image - a high poly sphere that I sculpted in Blender so that it has some protruding ridges. I then baked a normal map which I then applied to a low poly sphere (used to create the high poly sphere by subdivision)

Second Image - I exported that low poly sphere at two geometry settings for the normal factor 5 and its inverse 0.2 and viewed them in the Sandbox. Note the ridges do not protrude out but are cutting into the sphere.

I gather this is caused by the red and green channels being "inverted" compared to Maya.

cheers, gryff :)

 

blender1.png

babylon3.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...