Jump to content

Babylon Texture Normal Map Tiling


MackeyK24
 Share

Recommended Posts

@dsman wrote:

Once again thanks for creating Unity Toolkit, it is so much helpful for our startup. 

There are few issues. If you can point out where to fix probably we can contribute to toolkit as well. 

When we apply a PBRMetalicRoughness Babylon material (Material drop-down -> BabylonJS -> PBRMetalicRoughness)  to any surface and then export the scene, the uv tiling is different for both basic albedo texture and Bump Map (Normal map in Unity). If we have 10x 10 tiling for main albedo texture, the bump map is applied at 1x1. Surprisingly it didn't happen in on another mesh with tiled albedo. 

Link to comment
Share on other sites

Yo @dsman I fixed this in 3.1 beta ... but for now in SceneBuilder.Materials for both standard and pbr after setting the normal texture:

DumpStandardMaterial()

AFTER

// Normal map
bMat.bumpTexture = DumpTextureFromMaterial(material, "_BumpMap");
if (bMat.bumpTexture != null && material.HasProperty("_BumpScale"))
{
    bMat.bumpTexture.level = material.GetFloat("_BumpScale");
}

ADD THIS

if (bMat.diffuseTexture != null && bMat.bumpTexture != null) {
    bMat.bumpTexture.uScale = bMat.diffuseTexture.uScale;
    bMat.bumpTexture.vScale = bMat.diffuseTexture.vScale;
    bMat.bumpTexture.uOffset = bMat.diffuseTexture.uOffset;
    bMat.bumpTexture.vOffset = bMat.diffuseTexture.vOffset;
}

 

DumpPBRMaterial()

AFTER

// Normal
babylonPbrMaterial.bumpTexture = DumpTextureFromMaterial(material, "_BumpMap");
if (babylonPbrMaterial.bumpTexture != null && material.HasProperty("_BumpScale"))
{
   babylonPbrMaterial.bumpTexture.level = material.GetFloat("_BumpScale");
}

ADD THIS

if (babylonPbrMaterial.albedoTexture != null && babylonPbrMaterial.bumpTexture != null) {
    babylonPbrMaterial.bumpTexture.uScale = babylonPbrMaterial.albedoTexture.uScale;
    babylonPbrMaterial.bumpTexture.vScale = babylonPbrMaterial.albedoTexture.vScale;
    babylonPbrMaterial.bumpTexture.uOffset = babylonPbrMaterial.albedoTexture.uOffset;
    babylonPbrMaterial.bumpTexture.vOffset = babylonPbrMaterial.albedoTexture.vOffset;
}

 

 

Link to comment
Share on other sites

Should be... the scene file has proper values for BOTH textures now :)

I am still having issues with the latest 3.1 beta REALLY slowing my scenes down that are using cannon... I cannot figure out what changed and why this is happening...

All I know is that using the Alpha version which is in toolkit... I made the space shooter demo... if I simply replace the babylon.js with the current 3.1 beta EVERYTHING having to do physics SLOWS DOWN... All the asteroids and laser shots and every I move around with setLinearVelocity is just DOG SLOW... I can pin point what the issue is BUT IS REALLY SLOW... I know that pretty generic... I cant repo in playground because it was a whole game already ... All I can do is make available the FINISHED BUILD project folder with all scene assets an script code... So I just been waiting to hope it just GETS FIXED :)

But when ever it does, I have plenty more fixes for Terrains and a a few project build fixes for faster export/builds the the toolkit 3.1 Beta Release :)

Yeah look at all those smiley faces :)

 

Link to comment
Share on other sites

  • 2 weeks later...
On 12/5/2017 at 12:06 PM, RaananW said:

@MackeyK24 - about cannon, what is your world scale? there was an issue with the step time we provide to cannon, which was fixed for 3.1 . so if your world scale is very big, it will seem like the scene is slower. in reality, it is physically correct.

Hey @RaananW

Dunno where i would set this... if you are just talking about the scale of the geometry ... i guess that would be the default unity scaling.

Can you please take a look at Space Shooter Demo - 3.2 Alpha 

if you need to see what the one was like using 3.1 alpha... Working 3.1 Alpha Demo

 

Link to comment
Share on other sites

On 12/5/2017 at 12:06 PM, RaananW said:

@MackeyK24 - about cannon, what is your world scale? there was an issue with the step time we provide to cannon, which was fixed for 3.1 . so if your world scale is very big, it will seem like the scene is slower. in reality, it is physically correct.

Yo @RaananW i cant seem to find anything about setting world scale... What is that and where would i set that... In babylon ???

Link to comment
Share on other sites

Yo @dsman

There is something wrong with the way cannon js plugin is working with my Unity Exported content. I think it may have something to do the "World Scale" changes some of the BIG DOGS who maintain the babylon js codebase. Anyways...

There is no working 3.1 Beta or 3.2 xxxx.

My toolkit seems to be stuck on 3.1 Alpha until the physics issues get fixed (or someone tells me how to address the changes they put in BabylonJS codebase)

Sorry :(

 

Link to comment
Share on other sites

@MackeyK24   Ok. I understand. 
But then if you can tell me where can I make code changes you suggested to fix the issue of normal map tiling, at least we can continue using the current Toolkit version. 

I simply need file name of above code changes you suggested and instruction to build/compile the Toolkit. 

Link to comment
Share on other sites

On 12/1/2017 at 4:46 PM, MackeyK24 said:

Yo @dsman I fixed this in 3.1 beta ... but for now in SceneBuilder.Materials for both standard and pbr after setting the normal texture:

DumpStandardMaterial()

AFTER


// Normal map
bMat.bumpTexture = DumpTextureFromMaterial(material, "_BumpMap");
if (bMat.bumpTexture != null && material.HasProperty("_BumpScale"))
{
    bMat.bumpTexture.level = material.GetFloat("_BumpScale");
}

ADD THIS


if (bMat.diffuseTexture != null && bMat.bumpTexture != null) {
    bMat.bumpTexture.uScale = bMat.diffuseTexture.uScale;
    bMat.bumpTexture.vScale = bMat.diffuseTexture.vScale;
    bMat.bumpTexture.uOffset = bMat.diffuseTexture.uOffset;
    bMat.bumpTexture.vOffset = bMat.diffuseTexture.vOffset;
}

 

DumpPBRMaterial()

AFTER


// Normal
babylonPbrMaterial.bumpTexture = DumpTextureFromMaterial(material, "_BumpMap");
if (babylonPbrMaterial.bumpTexture != null && material.HasProperty("_BumpScale"))
{
   babylonPbrMaterial.bumpTexture.level = material.GetFloat("_BumpScale");
}

ADD THIS


if (babylonPbrMaterial.albedoTexture != null && babylonPbrMaterial.bumpTexture != null) {
    babylonPbrMaterial.bumpTexture.uScale = babylonPbrMaterial.albedoTexture.uScale;
    babylonPbrMaterial.bumpTexture.vScale = babylonPbrMaterial.albedoTexture.vScale;
    babylonPbrMaterial.bumpTexture.uOffset = babylonPbrMaterial.albedoTexture.uOffset;
    babylonPbrMaterial.bumpTexture.vOffset = babylonPbrMaterial.albedoTexture.vOffset;
}

 

 

 

Yo @dsman .. I Already posted these instructions :)

And the actual source is automatically compile by unity when you save changes (it actually complies all the source for the project even time you open the project as well)

 

Basically find the DumpPBRMaterial and DumpStandardMaterial functions in the SceneBuilder.Materials.cs file and follow snippets above :)

 

 

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...