Wrong texture tiling when feeding texture inside Texture Block via code

Hello there,

I’ve created a simple PBRMetallicRoughness shader using the Node Material tool where I can customize the color of my models, with diffuse, normal and a color map texture reads and I can preview there just fine there and when I load that inside my game as well. However, I need to feed custom textures on them (for different kind of models I have, obviously) and I followed this tutorial

to assign the textures but whenever I do that the tiling bugs out.

Here’s a code snipped

async LoadCustomMaterial () : Promise {
this._nodeMaterial = await BABYLON.NodeMaterial.ParseFromFileAsync(‘MyModelColorSwap’, this._assetManager.getPath(‘shaders/’) + ‘MyModelColorSwap.json’, this._scene!);
}

Later on I do

LoadTextures () : void {
this._albedo = new BABYLON.Texture(this._assetManager.getPath(‘textureMaps/’) + ‘My_Albedo.png’, this._scene);
this._colorMask = new BABYLON.Texture(this._assetManager.getPath(‘textureMaps/’) + ‘My_ColorMap.png’, this._scene);
this._normal = new BABYLON.Texture(this._assetManager.getPath(‘textureMaps/’) + ‘My_Normal.png’, this._scene);
}

and then

   const diffuseBlock = this._nodeMaterial!.getBlockByName('DiffuseMap');
    const colorMapBlock = this._nodeMaterial!.getBlockByName('ColorMap');
    const normalBlock =  this._nodeMaterial!.getBlockByName('NormalMap');

    const txtDiffBlock = diffuseBlock as TextureBlock;
    const txtColorMapBlock = colorMapBlock as TextureBlock;
    const txtNormalBlock = normalBlock as TextureBlock;

    txtDiffBlock.texture = this._albedo;
    txtColorMapBlock.texture = this._colorMask; 
    txtNormalBlock.texture = this._normal;

I print all the values and everything seem ready.
I also tried matching every single parameter that I have inside Node Material (Texture Node) via code to see if that was the issue, but with no luck.
Ex:
txtDiffBlock.texture.wrapU = 1;
txtDiffBlock.texture.wrapV = 1;
txtDiffBlock.texture.uAng = 0;
txtDiffBlock.texture.vAng = 0;
txtDiffBlock.texture.wAng = 0;
txtDiffBlock.texture.uOffset = 0;
txtDiffBlock.texture.vOffset = 0;
txtDiffBlock.texture.uScale = 1;
txtDiffBlock.texture.vScale = 1;

etc.
I also tried BABYLON.NodeMaterial.IgnoreTexturesAtLoadTime = true;

Any ideas on what’s going on in my case?

Cheers!

Welcome aboard!

It seems it should work.

Would you be able to setup a repro in the Playground? If you need to access external resources, this page will explain you how to do it.

2 Likes

Hey Evgeni,

Here’s a link to a Playground I did with the same issue https://playground.babylonjs.com/#H2C9FE#1

I even simplified my Node Material to have just a diffuse map and a normal map

Cheers!

NME Texture blocks take non Y-inverted textures as inputs, so you should pass false as the 4th parameter of the Texture constructor:

1 Like

Hey Evgeni,

Thank you for the help!

Passing in the constructor solved the issue, but I’m wondering why when I set afterwards it doesn’t work

albedo.uOffset = 0;
albedo.vOffset = 0;
albedo.uScale = 1;
albedo.vScale = 1;
albedo.uAng = 0;
albedo.vAng = 0;
albedo.wAng = 0;
albedo.uRotationCenter = 0;
albedo.vRotationCenter = 0;
albedo.wRotationCenter = 0;
albedo.isBlocking = true;
albedo._invertY = false;
albedo.homogeneousRotationInUVTransform = false;
albedo.isBlocking = true;
albedo.hasAlpha = false;
albedo.getAlphaFromRGB = false;
albedo.level = 1;
albedo.coordinatesIndex = 0;
albedo.optimizeUVAllocation = true;
albedo.coordinatesMode = 7;
albedo.wrapU = 1;
albedo.wrapV = 1;
albedo.wrapR = 1;
albedo.anisotropicFilteringLevel = 4;
albedo.isCube = false;
albedo.is3D = false;
albedo.is2DArray = false;
albedo.gammaSpace = true;
albedo.invertZ = false;
albedo.lodLevelInAlpha = false;
albedo.lodGenerationOffset = 0;
albedo.lodGenerationScale = 0;
albedo.linearSpecularLOD = false;
albedo.isRenderTarget = false;

the albedo._invertY in this particular case

invertY (or _invertY) is read-only, it’s a setting that is passed and taken into account at build time only.

1 Like