Shader failing on imported mesh

My custom shader appears to not be working on the mesh I just imported. To illustrate what it is suppose to be looking like I rendered a sphere right above it, upon which the shader does seem to act normally. My suspicion is the normals on the mesh are wrong. Image below:

The code I use to import (for testing only):

BABYLON.SceneLoader.ImportMesh('', "../Meshes/", "scene.gltf", scene, function(newMeshes){ = newMeshes[0];
    var amigaMaterial = new BABYLON.ShaderMaterial("amiga", scene, "../HighContrast",
        attributes: ["position", "normal", "uv"],
        uniforms: ["world", "worldViewProjection", "lightSource", "threshold"]
    amigaMaterial.setVector3("lightSource", new BABYLON.Vector3(10, 10., 40.));
    amigaMaterial.setFloat("threshold", 0.7);
    scene.clearColor = new BABYLON.Color3(255., 255., 255.);
    newMeshes[0].material = amigaMaterial;
    var sphere = BABYLON.Mesh.CreateSphere("Sphere", 16, 1, scene);
    sphere.material = amigaMaterial;
    sphere.position.y += 2
    newMeshes[0].position = BABYLON.Vector3.Zero();

Anyone got any idea what I’m doing wrong here?

i don’t know how to use materials the way you use it but i will try to help :slightly_smiling_face:
i think babylon will accept only .babylon file format try to convert it in blender .
or try to declare a variable to hold the imported mesh in it cause the function in the arguments causes a problem to me once
make sure that the mesh has a uv map by open it in 3d app or search for the word uv in the mesh file in your IDE
and for more try to verify with this :

im a begineer too :slightly_smiling_face: so that what i can provide

Appreciate the reply. The UV map is irrelevant for my use case as the shader I use does not incorporate one. As far as the .babylon file goes I’m not following you. Why would the rendering of the shader fail due to the object being in glft format? As you can see it’s already loaded properly.

yeah i see , i thought the file format may has an impact

It turned out the mesh was loaded at the second index of the array. I’m a little confused as of why, but iterating over them and applying the material to each individual one did the trick.

That’s because when loading a gltf file a root node is created to handle the conversion from right to left handedness.

1 Like