Sketchfab Forum

Normal/bump maps at runtime

(Madalin Berechet) #1

Sketchfab no longer accept toDataURL() maps at runtime?! I mean only bump/normal maps. There are changes on channel definitions?


Sorry, I'm not sure what you're talking about. Can you elaborate?

(Madalin Berechet) #3

var texB = canvasBump.toDataURL()
texB, //the new map are transfered to Sketchfab API
function (err, textureDUid) {
api.setMaterial(materialToUpdate, function () {
console.log("Bump material updated");


Hmm, thanks. I when was this working before?

(Madalin Berechet) #5

Yes, It worked 3, 4 hours ago.
Now are working just for diffuse channel (the both workflows), but not for normal/bump channels.

(Shaderbytes) #6

I presume in the "..." aspect of your code you are updating the channel texture UID..?

Did the material originally have a texture and you are uploading a different one ? I ask because if not and you are creating your own texture object the "texCoordUnit" variable is not easy to set. I used to have it set to 1 previously and then one day it stopped working so I changed it to 0. Sadly I have seen even other values for this variable. I really wish there was a concise means to know what this variable should be set to.. @stephomi do you know much about this variable..?

If you are just updating a material that had an existing texture previously then I cant say what the issue is. Then it might be something that changed in the manner the support uploads. Did you check the value of the err argument being passed in , if not null then there is some error , log it and see

(Madalin Berechet) #7

Yes, the material originally have a texture. Please see here:
Add some text. The diffuse are transferred, but the bump/normal, no.

(Madalin Berechet) #8

No log errors. Also I have some callbacks that said "texture updated"

(Shaderbytes) #9

ok your code is minified so it doesnt help much , are you setting all the properties of the texture object again or only updating the uid?

(Madalin Berechet) #10

var texB = canvasBump.toDataURL({ // the diffuse working canvas transformed into a jpg code
format: 'jpeg',
quality: 1
texB, //the new map are transfered to Sketchfab API
function (err, textureBUid) {
materialToUpdate = materialHash["upperMap"]; //always, inside tis function, we are update the upperMap, as combination of textures
//console.log("Material to update: ", materialToUpdate);
var texobB = {};
texobB.internalFormat = "RGB";
texobB.magFilter = "LINEAR";
texobB.minFilter = "LINEAR_MIPMAP_LINEAR";
texobB.texCoordUnit = 0;
texobB.textureTarget = "TEXTURE_2D";
texobB.uid = textureBUid;
texobB.wrapS = "REPEAT";
texobB.wrapT = "REPEAT";
materialToUpdate.channels.BumpMap.texture = texobB; //this is the channel we are changing in order to affect the diffuse map
api.setMaterial(materialToUpdate, function () {
console.log("Bump material updated"); // the diffuse colour of the material upperMap was updated

(Shaderbytes) #11

In my utility if the channel originally had a texture in that slot then I only update the UID and dont touch the other variables.. this is because I mentioned the texCoordUnit is not easy to guess

(Shaderbytes) #12

im quite sure this is the problem , try cache the current texture object and only update the uid after uploading a new texture.

(Madalin Berechet) #13

I saw your utilities, thanks for your great contribution. I will try to update only the uid

(Shaderbytes) #14

cool lets hope it works , I actually cache the original via doing a deepcopy , or create a new object using some defaults but additionally I support injecting an object with alternate parameters to make sure it is as flexible as possible :slight_smile:

(Madalin Berechet) #15

Thanks for the tips!

(Stephomi) #16

We probably broke something with today's release, it should be fixed very soon (hoping today/tomorrow).
Until then, you can try adding "material_packing=0" in the url option of the sketchfab embed, it should fix the issue.

TexCoordUnit is used for multi-UV models, but for the huge majority of models, there's only 1 uv set per material, so texCoordUnit should be 0.
As for your code, it should be correct, except for the "internalFormat" which can only be "LUMINANCE" for a BumpMap (but it shouldn't cause any issues I think).

(Madalin Berechet) #17

I have noticed that the normal/bump texture has changed the internal format

was: tex.internalFormat = "RGB";

now it's: tex.internalFormat = "LUMINANCE";

(Madalin Berechet) #18

Thank you for clarification, I saw it after I posted.

I am using now "LUMINANCE" and all works fine.
A few hours ago worked with "RGB".

I've got "RGB" from materials

api.getMaterialList(function (err, materials)

There normal/bump was "RGB". Only roughness was "LUMINANCE"

(Shaderbytes) #19

@MadalinBerechet you seem to quote normal/bump as if the are the same except that the are not. A bump map would be greyscale and does not encode direction and I presume sketchfab simply reads from the first color channel here the "r" or red channel , this is suitable for luminance. A normal map encodes direction in the bump and so uses more than one color channel and so luminance would not be a correct fit for this , it should be RGB.

I presume as stephomi mentioned they must have created a bug in the last release.

(Madalin Berechet) #20

Yes, you are right.
The confusion comes from the fact that they are on the same button in the editor :slight_smile:
But in materials array are completely different.