Material renders unnaturally (glossy)
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
|
show 2 more comments
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
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
|
show 2 more comments
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
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
javascript three.js
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
|
show 2 more comments
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
|
show 2 more comments
2 Answers
2
active
oldest
votes
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.
add a comment |
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 14 '18 at 21:55
MarquizzoMarquizzo
5,94832043
5,94832043
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Nov 15 '18 at 20:10
answered Nov 15 '18 at 19:49
XedretXedret
890817
890817
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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