question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Smooth shading not working even with explicit flatShading: false

See original GitHub issue

Describe the bug

According to docs, smooth shading is the default. Unfortunately, I cannot set it up.

To Reproduce

I just started with three.js, but to my understanding it should be fairly straightforward. Shade smooth is the default, and also can be explicitly defined by material({ flatShading: false })

I created a non-indexed geometry procedurally using BufferGeometry like below. Note I have called computeVertexNormals(true) (the true comes from some stackoverflow answer, but it doesn’t help so idk)

Is it somehow related to the fact it’s non-indexed?

Live example

https://jsfiddle.net/high_byte/e6chLudk/

Code


geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
geometry.computeVertexNormals(true);

var material = new THREE.MeshLambertMaterial({
  color: 0xdf5000,
  flatShading: true,
  side: THREE.DoubleSide,
});

mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

4reactions
donmccurdycommented, Feb 11, 2021

Is it somehow related to the fact it’s non-indexed?

Yes, in a non-indexed geometry every triangle has unique vertices from every other triangle. This basically ~makes smooth shading impossible~ causes computeVertexNormals() to compute flat normals, not smooth ones. Try using BufferGeometryUtils.mergeVertices( geometry ) first, then computing vertex normals. If you are having trouble with that, please use the forum or stack overflow.

2reactions
WestLangleycommented, Feb 11, 2021

@donmccurdy

Yes, in a non-indexed geometry every triangle has unique vertices from every other triangle. This basically makes smooth shading impossible.

nit. I think that should be rewritten like so:

Yes, in a non-indexed geometry every triangle has unique vertices from every other triangle. In that case, the normals generated by computeVertexNormals() will result in flat shading.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Smooth Shading option not working - Blender Stack Exchange
When you activate smooth shading on disconnected faces, Blender treats each one individually and it looks like flat shading because each ...
Read more >
Smooth shading in THREE.js with varying triangle orientation
I am just using a simple phong material: let material = new THREE.MeshPhongMaterial({ color: new THREE.Color('#FFAA44'), side: THREE.DoubleSide, ...
Read more >
Flatshading not working - Questions - three.js forum
Material.flatShading is always false by default. So setting it explicitly to false make no difference.
Read more >
Standard material has flat shading when loading GLTF at ...
Describe the bug Shading appears flat, no lighting effects, when using the MRTK/Standard material with meshes that have had normals ...
Read more >
Geometry Shader - LearnOpenGL
A geometry shader takes as input a set of vertices that form a single ... Now that you (sort of) know how geometry...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found