Material renders unnaturally (glossy)












1















I'm trying to render an object with materials using Three.js, but it looks differently than in other online viewers like https://3dviewer.net (also uses Three.js under the hood)



I tried to rise level of details (LOD) and also used NearestFilter / LinearFilter but without any effect.



This is how it should look (screenshot of rendered by 3dviewer object) .



And this is how it looks in my app



In 3dviewer version it looks more natural, and in my it is too shiny and glossy



Should I apply some specific filter (though did not find it in 3dviewer sources) or may be lighting?



My current code is:



let scene = new THREE.Scene();
scene.background = new THREE.Color( '#edeff2' );

let camera = new THREE.PerspectiveCamera( 100, window.innerWidth/window.innerHeight, 1, 1000 );
camera.position.z = 100;

let renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );

let controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.25;
controls.enableZoom = true;

let keyLight = new THREE.DirectionalLight(new THREE.Color('hsl(30, 100%, 75%)'), 1.0);
keyLight.position.set(-100, 0, 100);

let fillLight = new THREE.DirectionalLight(new THREE.Color('hsl(240, 100%, 75%)'), 0.75);
fillLight.position.set(100, 0, 100);

let backLight = new THREE.DirectionalLight(0xffffff, 1.0);
backLight.position.set(100, 0, -100).normalize();

scene.add(keyLight);
scene.add(fillLight);
scene.add(backLight);

let mtlLoader = new THREE.MTLLoader();
mtlLoader.setTexturePath('/examples/3d-obj-loader/assets/');
mtlLoader.setPath('/examples/3d-obj-loader/assets/');
mtlLoader.load('b.mtl', function (materials) {

materials.preload();

let objLoader = new THREE.OBJLoader();
objLoader.setMaterials(materials);
objLoader.setPath('/examples/3d-obj-loader/assets/');
objLoader.load('b.obj', function (object) {

scene.add(object);
object.position.y -= 100;

object.scale.x = 0.01;
object.scale.y = 0.01;
object.scale.z = 0.01;

let boundingBox = new THREE.Box3().setFromObject(object)
let size = boundingBox.getSize()
});
});

var animate = function () {
requestAnimationFrame( animate );
controls.update();
renderer.render(scene, camera);
};

animate();


Link to object, materials + textures - dropbox










share|improve this question

























  • please add some code so that it becomes clear what is the problem

    – Towkir Ahmed
    Nov 14 '18 at 12:42











  • @TowkirAhmed sure, just updated the question

    – Pavel
    Nov 14 '18 at 12:53











  • also need to see the mtl file

    – gaitat
    Nov 14 '18 at 13:35











  • @gaitat sure, attached to the question - dropbox.com/s/wtyqtqz2eopp9ld/three.zip?dl=0 it is a zip with obj, mtl and textures

    – Pavel
    Nov 14 '18 at 13:53






  • 1





    Try: stackoverflow.com/a/45990102/1980846

    – gaitat
    Nov 14 '18 at 17:02
















1















I'm trying to render an object with materials using Three.js, but it looks differently than in other online viewers like https://3dviewer.net (also uses Three.js under the hood)



I tried to rise level of details (LOD) and also used NearestFilter / LinearFilter but without any effect.



This is how it should look (screenshot of rendered by 3dviewer object) .



And this is how it looks in my app



In 3dviewer version it looks more natural, and in my it is too shiny and glossy



Should I apply some specific filter (though did not find it in 3dviewer sources) or may be lighting?



My current code is:



let scene = new THREE.Scene();
scene.background = new THREE.Color( '#edeff2' );

let camera = new THREE.PerspectiveCamera( 100, window.innerWidth/window.innerHeight, 1, 1000 );
camera.position.z = 100;

let renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );

let controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.25;
controls.enableZoom = true;

let keyLight = new THREE.DirectionalLight(new THREE.Color('hsl(30, 100%, 75%)'), 1.0);
keyLight.position.set(-100, 0, 100);

let fillLight = new THREE.DirectionalLight(new THREE.Color('hsl(240, 100%, 75%)'), 0.75);
fillLight.position.set(100, 0, 100);

let backLight = new THREE.DirectionalLight(0xffffff, 1.0);
backLight.position.set(100, 0, -100).normalize();

scene.add(keyLight);
scene.add(fillLight);
scene.add(backLight);

let mtlLoader = new THREE.MTLLoader();
mtlLoader.setTexturePath('/examples/3d-obj-loader/assets/');
mtlLoader.setPath('/examples/3d-obj-loader/assets/');
mtlLoader.load('b.mtl', function (materials) {

materials.preload();

let objLoader = new THREE.OBJLoader();
objLoader.setMaterials(materials);
objLoader.setPath('/examples/3d-obj-loader/assets/');
objLoader.load('b.obj', function (object) {

scene.add(object);
object.position.y -= 100;

object.scale.x = 0.01;
object.scale.y = 0.01;
object.scale.z = 0.01;

let boundingBox = new THREE.Box3().setFromObject(object)
let size = boundingBox.getSize()
});
});

var animate = function () {
requestAnimationFrame( animate );
controls.update();
renderer.render(scene, camera);
};

animate();


Link to object, materials + textures - dropbox










share|improve this question

























  • please add some code so that it becomes clear what is the problem

    – Towkir Ahmed
    Nov 14 '18 at 12:42











  • @TowkirAhmed sure, just updated the question

    – Pavel
    Nov 14 '18 at 12:53











  • also need to see the mtl file

    – gaitat
    Nov 14 '18 at 13:35











  • @gaitat sure, attached to the question - dropbox.com/s/wtyqtqz2eopp9ld/three.zip?dl=0 it is a zip with obj, mtl and textures

    – Pavel
    Nov 14 '18 at 13:53






  • 1





    Try: stackoverflow.com/a/45990102/1980846

    – gaitat
    Nov 14 '18 at 17:02














1












1








1








I'm trying to render an object with materials using Three.js, but it looks differently than in other online viewers like https://3dviewer.net (also uses Three.js under the hood)



I tried to rise level of details (LOD) and also used NearestFilter / LinearFilter but without any effect.



This is how it should look (screenshot of rendered by 3dviewer object) .



And this is how it looks in my app



In 3dviewer version it looks more natural, and in my it is too shiny and glossy



Should I apply some specific filter (though did not find it in 3dviewer sources) or may be lighting?



My current code is:



let scene = new THREE.Scene();
scene.background = new THREE.Color( '#edeff2' );

let camera = new THREE.PerspectiveCamera( 100, window.innerWidth/window.innerHeight, 1, 1000 );
camera.position.z = 100;

let renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );

let controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.25;
controls.enableZoom = true;

let keyLight = new THREE.DirectionalLight(new THREE.Color('hsl(30, 100%, 75%)'), 1.0);
keyLight.position.set(-100, 0, 100);

let fillLight = new THREE.DirectionalLight(new THREE.Color('hsl(240, 100%, 75%)'), 0.75);
fillLight.position.set(100, 0, 100);

let backLight = new THREE.DirectionalLight(0xffffff, 1.0);
backLight.position.set(100, 0, -100).normalize();

scene.add(keyLight);
scene.add(fillLight);
scene.add(backLight);

let mtlLoader = new THREE.MTLLoader();
mtlLoader.setTexturePath('/examples/3d-obj-loader/assets/');
mtlLoader.setPath('/examples/3d-obj-loader/assets/');
mtlLoader.load('b.mtl', function (materials) {

materials.preload();

let objLoader = new THREE.OBJLoader();
objLoader.setMaterials(materials);
objLoader.setPath('/examples/3d-obj-loader/assets/');
objLoader.load('b.obj', function (object) {

scene.add(object);
object.position.y -= 100;

object.scale.x = 0.01;
object.scale.y = 0.01;
object.scale.z = 0.01;

let boundingBox = new THREE.Box3().setFromObject(object)
let size = boundingBox.getSize()
});
});

var animate = function () {
requestAnimationFrame( animate );
controls.update();
renderer.render(scene, camera);
};

animate();


Link to object, materials + textures - dropbox










share|improve this question
















I'm trying to render an object with materials using Three.js, but it looks differently than in other online viewers like https://3dviewer.net (also uses Three.js under the hood)



I tried to rise level of details (LOD) and also used NearestFilter / LinearFilter but without any effect.



This is how it should look (screenshot of rendered by 3dviewer object) .



And this is how it looks in my app



In 3dviewer version it looks more natural, and in my it is too shiny and glossy



Should I apply some specific filter (though did not find it in 3dviewer sources) or may be lighting?



My current code is:



let scene = new THREE.Scene();
scene.background = new THREE.Color( '#edeff2' );

let camera = new THREE.PerspectiveCamera( 100, window.innerWidth/window.innerHeight, 1, 1000 );
camera.position.z = 100;

let renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );

let controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.25;
controls.enableZoom = true;

let keyLight = new THREE.DirectionalLight(new THREE.Color('hsl(30, 100%, 75%)'), 1.0);
keyLight.position.set(-100, 0, 100);

let fillLight = new THREE.DirectionalLight(new THREE.Color('hsl(240, 100%, 75%)'), 0.75);
fillLight.position.set(100, 0, 100);

let backLight = new THREE.DirectionalLight(0xffffff, 1.0);
backLight.position.set(100, 0, -100).normalize();

scene.add(keyLight);
scene.add(fillLight);
scene.add(backLight);

let mtlLoader = new THREE.MTLLoader();
mtlLoader.setTexturePath('/examples/3d-obj-loader/assets/');
mtlLoader.setPath('/examples/3d-obj-loader/assets/');
mtlLoader.load('b.mtl', function (materials) {

materials.preload();

let objLoader = new THREE.OBJLoader();
objLoader.setMaterials(materials);
objLoader.setPath('/examples/3d-obj-loader/assets/');
objLoader.load('b.obj', function (object) {

scene.add(object);
object.position.y -= 100;

object.scale.x = 0.01;
object.scale.y = 0.01;
object.scale.z = 0.01;

let boundingBox = new THREE.Box3().setFromObject(object)
let size = boundingBox.getSize()
});
});

var animate = function () {
requestAnimationFrame( animate );
controls.update();
renderer.render(scene, camera);
};

animate();


Link to object, materials + textures - dropbox







javascript three.js






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 15:30









gman

47k17113203




47k17113203










asked Nov 14 '18 at 12:39









PavelPavel

63




63













  • please add some code so that it becomes clear what is the problem

    – Towkir Ahmed
    Nov 14 '18 at 12:42











  • @TowkirAhmed sure, just updated the question

    – Pavel
    Nov 14 '18 at 12:53











  • also need to see the mtl file

    – gaitat
    Nov 14 '18 at 13:35











  • @gaitat sure, attached to the question - dropbox.com/s/wtyqtqz2eopp9ld/three.zip?dl=0 it is a zip with obj, mtl and textures

    – Pavel
    Nov 14 '18 at 13:53






  • 1





    Try: stackoverflow.com/a/45990102/1980846

    – gaitat
    Nov 14 '18 at 17:02



















  • please add some code so that it becomes clear what is the problem

    – Towkir Ahmed
    Nov 14 '18 at 12:42











  • @TowkirAhmed sure, just updated the question

    – Pavel
    Nov 14 '18 at 12:53











  • also need to see the mtl file

    – gaitat
    Nov 14 '18 at 13:35











  • @gaitat sure, attached to the question - dropbox.com/s/wtyqtqz2eopp9ld/three.zip?dl=0 it is a zip with obj, mtl and textures

    – Pavel
    Nov 14 '18 at 13:53






  • 1





    Try: stackoverflow.com/a/45990102/1980846

    – gaitat
    Nov 14 '18 at 17:02

















please add some code so that it becomes clear what is the problem

– Towkir Ahmed
Nov 14 '18 at 12:42





please add some code so that it becomes clear what is the problem

– Towkir Ahmed
Nov 14 '18 at 12:42













@TowkirAhmed sure, just updated the question

– Pavel
Nov 14 '18 at 12:53





@TowkirAhmed sure, just updated the question

– Pavel
Nov 14 '18 at 12:53













also need to see the mtl file

– gaitat
Nov 14 '18 at 13:35





also need to see the mtl file

– gaitat
Nov 14 '18 at 13:35













@gaitat sure, attached to the question - dropbox.com/s/wtyqtqz2eopp9ld/three.zip?dl=0 it is a zip with obj, mtl and textures

– Pavel
Nov 14 '18 at 13:53





@gaitat sure, attached to the question - dropbox.com/s/wtyqtqz2eopp9ld/three.zip?dl=0 it is a zip with obj, mtl and textures

– Pavel
Nov 14 '18 at 13:53




1




1





Try: stackoverflow.com/a/45990102/1980846

– gaitat
Nov 14 '18 at 17:02





Try: stackoverflow.com/a/45990102/1980846

– gaitat
Nov 14 '18 at 17:02












2 Answers
2






active

oldest

votes


















0














You can easily access the materials of your object.



objLoader.load('b.obj', function (object) {
// Access material
var mat = object.material;

// Make material less shiny
mat.metalness = 0;
mat.roughness = 1;

scene.add(object);
object.position.y -= 100;

object.scale.x = 0.01;
object.scale.y = 0.01;
object.scale.z = 0.01;

let boundingBox = new THREE.Box3().setFromObject(object)
let size = boundingBox.getSize()
});


How you access the material depends on the structure of your object. It could be object.children[0].material, or object.children[0].children[0].material, depending on how it's nested.






share|improve this answer































    0














    I came across the same issue and I had to apply a filter to all of my materials:



    function getAllMaterials( object ) {
    var out = ;
    object.traverse( function( node ) {
    if ( node instanceof THREE.Mesh ) { out.push( node.material ) }
    } );
    return out;
    }

    getAllMaterials( <your-3D-Object-Here> ).forEach( function ( mat ) {
    if ( Array.isArray( mat ) ) {
    mat.forEach( function( cmat ) { cmat.shininess /= 19; } )
    }
    else { mat.shininess /= 19 }
    } );


    You might need to change that static 19 in the code to whatever fits your needs. If you have any questions, I'll set up live example for you.






    share|improve this answer

























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300456%2fmaterial-renders-unnaturally-glossy%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      You can easily access the materials of your object.



      objLoader.load('b.obj', function (object) {
      // Access material
      var mat = object.material;

      // Make material less shiny
      mat.metalness = 0;
      mat.roughness = 1;

      scene.add(object);
      object.position.y -= 100;

      object.scale.x = 0.01;
      object.scale.y = 0.01;
      object.scale.z = 0.01;

      let boundingBox = new THREE.Box3().setFromObject(object)
      let size = boundingBox.getSize()
      });


      How you access the material depends on the structure of your object. It could be object.children[0].material, or object.children[0].children[0].material, depending on how it's nested.






      share|improve this answer




























        0














        You can easily access the materials of your object.



        objLoader.load('b.obj', function (object) {
        // Access material
        var mat = object.material;

        // Make material less shiny
        mat.metalness = 0;
        mat.roughness = 1;

        scene.add(object);
        object.position.y -= 100;

        object.scale.x = 0.01;
        object.scale.y = 0.01;
        object.scale.z = 0.01;

        let boundingBox = new THREE.Box3().setFromObject(object)
        let size = boundingBox.getSize()
        });


        How you access the material depends on the structure of your object. It could be object.children[0].material, or object.children[0].children[0].material, depending on how it's nested.






        share|improve this answer


























          0












          0








          0







          You can easily access the materials of your object.



          objLoader.load('b.obj', function (object) {
          // Access material
          var mat = object.material;

          // Make material less shiny
          mat.metalness = 0;
          mat.roughness = 1;

          scene.add(object);
          object.position.y -= 100;

          object.scale.x = 0.01;
          object.scale.y = 0.01;
          object.scale.z = 0.01;

          let boundingBox = new THREE.Box3().setFromObject(object)
          let size = boundingBox.getSize()
          });


          How you access the material depends on the structure of your object. It could be object.children[0].material, or object.children[0].children[0].material, depending on how it's nested.






          share|improve this answer













          You can easily access the materials of your object.



          objLoader.load('b.obj', function (object) {
          // Access material
          var mat = object.material;

          // Make material less shiny
          mat.metalness = 0;
          mat.roughness = 1;

          scene.add(object);
          object.position.y -= 100;

          object.scale.x = 0.01;
          object.scale.y = 0.01;
          object.scale.z = 0.01;

          let boundingBox = new THREE.Box3().setFromObject(object)
          let size = boundingBox.getSize()
          });


          How you access the material depends on the structure of your object. It could be object.children[0].material, or object.children[0].children[0].material, depending on how it's nested.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 21:55









          MarquizzoMarquizzo

          5,94832043




          5,94832043

























              0














              I came across the same issue and I had to apply a filter to all of my materials:



              function getAllMaterials( object ) {
              var out = ;
              object.traverse( function( node ) {
              if ( node instanceof THREE.Mesh ) { out.push( node.material ) }
              } );
              return out;
              }

              getAllMaterials( <your-3D-Object-Here> ).forEach( function ( mat ) {
              if ( Array.isArray( mat ) ) {
              mat.forEach( function( cmat ) { cmat.shininess /= 19; } )
              }
              else { mat.shininess /= 19 }
              } );


              You might need to change that static 19 in the code to whatever fits your needs. If you have any questions, I'll set up live example for you.






              share|improve this answer






























                0














                I came across the same issue and I had to apply a filter to all of my materials:



                function getAllMaterials( object ) {
                var out = ;
                object.traverse( function( node ) {
                if ( node instanceof THREE.Mesh ) { out.push( node.material ) }
                } );
                return out;
                }

                getAllMaterials( <your-3D-Object-Here> ).forEach( function ( mat ) {
                if ( Array.isArray( mat ) ) {
                mat.forEach( function( cmat ) { cmat.shininess /= 19; } )
                }
                else { mat.shininess /= 19 }
                } );


                You might need to change that static 19 in the code to whatever fits your needs. If you have any questions, I'll set up live example for you.






                share|improve this answer




























                  0












                  0








                  0







                  I came across the same issue and I had to apply a filter to all of my materials:



                  function getAllMaterials( object ) {
                  var out = ;
                  object.traverse( function( node ) {
                  if ( node instanceof THREE.Mesh ) { out.push( node.material ) }
                  } );
                  return out;
                  }

                  getAllMaterials( <your-3D-Object-Here> ).forEach( function ( mat ) {
                  if ( Array.isArray( mat ) ) {
                  mat.forEach( function( cmat ) { cmat.shininess /= 19; } )
                  }
                  else { mat.shininess /= 19 }
                  } );


                  You might need to change that static 19 in the code to whatever fits your needs. If you have any questions, I'll set up live example for you.






                  share|improve this answer















                  I came across the same issue and I had to apply a filter to all of my materials:



                  function getAllMaterials( object ) {
                  var out = ;
                  object.traverse( function( node ) {
                  if ( node instanceof THREE.Mesh ) { out.push( node.material ) }
                  } );
                  return out;
                  }

                  getAllMaterials( <your-3D-Object-Here> ).forEach( function ( mat ) {
                  if ( Array.isArray( mat ) ) {
                  mat.forEach( function( cmat ) { cmat.shininess /= 19; } )
                  }
                  else { mat.shininess /= 19 }
                  } );


                  You might need to change that static 19 in the code to whatever fits your needs. If you have any questions, I'll set up live example for you.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 15 '18 at 20:10

























                  answered Nov 15 '18 at 19:49









                  XedretXedret

                  890817




                  890817






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300456%2fmaterial-renders-unnaturally-glossy%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Xamarin.iOS Cant Deploy on Iphone

                      Glorious Revolution

                      Dulmage-Mendelsohn matrix decomposition in Python