Skip to content

WebGLRenderer: Force flat shading for geometries without normals. #32831

Merged
mrdoob merged 3 commits into
devfrom
webgl-normals-fallback
Jan 23, 2026
Merged

WebGLRenderer: Force flat shading for geometries without normals. #32831
mrdoob merged 3 commits into
devfrom
webgl-normals-fallback

Conversation

@mrdoob

@mrdoob mrdoob commented Jan 23, 2026

Copy link
Copy Markdown
Owner

Description

Previously, geometries without normals would render black with materials that require normals for lighting calculations. Users had to manually set material.flatShading = true or call geometry.computeVertexNormals() as a workaround.

The renderer now detects this case and automatically uses flat shading, which computes normals from screen-space derivatives in the fragment shader.

mrdoob and others added 2 commits January 23, 2026 16:06
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@mrdoob mrdoob added this to the r183 milestone Jan 23, 2026
@github-actions

github-actions Bot commented Jan 23, 2026

Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 356.57
84.67
356.71
84.7
+142 B
+34 B
WebGPU 621.78
172.66
621.78
172.66
+0 B
+0 B
WebGPU Nodes 620.38
172.43
620.38
172.43
+0 B
+0 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 489.35
119.68
489.5
119.71
+142 B
+34 B
WebGPU 692.75
187.97
692.75
187.97
+0 B
+0 B
WebGPU Nodes 642.41
175.15
642.41
175.15
+0 B
+0 B

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@mrdoob mrdoob merged commit c57ccd0 into dev Jan 23, 2026
10 checks passed
@mrdoob mrdoob deleted the webgl-normals-fallback branch January 23, 2026 07:42
@mrdoob

mrdoob commented Jan 24, 2026

Copy link
Copy Markdown
Owner Author

@Mugen87 @sunag

I've tried to get Claude to port this change to WebGPURenderer but it can't figured it out. Can you give it a go?

In order to repro:

@supervitas

Copy link
Copy Markdown

@mrdoob It was okay. Now i cant use my custom oct-encoded normals. Because its vec2 attribute, and cant be aligned for vec3 normal.

@mrdoob

mrdoob commented Jun 16, 2026

Copy link
Copy Markdown
Owner Author

Can you create a jsfiddle that shows what you're doing?

@supervitas

Copy link
Copy Markdown

@mrdoob Okay, nevermind, since i can override parameter flatShading which is comming in onBeforeCompile thats still works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants