Comments (5)
Most 3D libraries offer functions like calculateFaceNormals
and calculateVertexNormals
etc.
I actually have a half-finished implementation of these, I will look for it and put up a PR. I was doing this in math.gl since these calculations are completely webgl independent, though we can always discuss where it should go.
We should also consider @tsherif's proposal of using shader derivatives to automatically calculate normals in the shaders.
The "derivatives extension" seems to have 100% support, although those stats don't include headless-gl: https://webglstats.com/webgl/extension/OES_standard_derivatives. We should then decide if we use such calculation as a fallback in case normals are not provided etc.
In general, my instinct would be to resist adding normal calculations directly to loaders.gl, as it seems slightly outside the scope of this library. As an alternative, if we don't go the shader path, we could have the Geometry
or Model
classes autogenerate these if needed using functions e.g. from math.gl.
from loaders.gl.
I think Luma would be a good place for the normal calculations. Mesh processing seems outside the scope of math.gl. The Geometry class seems like a good place to me.
A couple of limitations to keep in mind:
- The derivatives version will only give you the normal of the actual face, so things will have a faceted, flat-shaded look.
- Vertex normal calculations can't do hard edges unless there's a separate vertex for each face, so you might end up rounding hard edges.
from loaders.gl.
I think Luma would be a good place for the normal calculations. Mesh processing seems outside the scope of math.gl. The Geometry class seems like a good place to me.
Yes, it would only make sense as part of a bigger initiative. I have what I think is a good plan here, but will add a PR on math.gl to explain my thinking before pushing ahead with this, we can implement this in luma in the mean-time.
The derivatives version will only give you the normal of the actual face, so things will have a faceted, flat-shaded look.
Yes. Ideally we would support both flat shading and smooth shading as an option (MeshLayer.flatShading: true/false
).
- Flat Shading - Supplying a
normal = filterNormal(normal)
module in a newgeometry
shader module would seems like a great way to support flat shading. It would return the passed in normal unless a flatShading uniform was set, in which case it would use derivatives to calculate a normal.
Vertex normal calculations can't do hard edges unless there's a separate vertex for each face, so you might end up rounding hard edges.
(For indexed geometries, we could do calculate flat shaded normals by first expanding indexed geometries. But if we use shaders for flat shading, this is moot.)
- Smooth shading - We now only need to generate normals for the smooth shading case. Any geometry that uses indices does have the ability to encode that vertices are shared, and by adding face normals for each face using that vertex and then normalizing we get an average which can generate good results.
Obviously it is hard to generate normals in a predictable way for generic geometries. The results will depend on how vertices are shared in geometry which can depend on e.g. the exporter used to generate that geometry. But it will probably be reasonably good in many cases.
The smooth shading is harder to support in the general case. For non-indexed geometries it would require identifying shared vertices which is computationally more complex and expensive, so we may just generate flat normals for that case.
Does this sound like a plan or do you have other solutions in mind?
from loaders.gl.
If the only issue is a fallback for the SimpleMeshLayer when normals aren't provided, I can just add shader-generated normals to the SimpleMeshLayer fragment shader. For now, it could just be auto-enabled if the normals are missing.
from loaders.gl.
@loaders.gl/math has the initial algorithms for this. We can revive these if the need comes up again.
from loaders.gl.
Related Issues (20)
- [Bug] GLTF: Handle URI shader HOT 1
- [Bug] GLTF: Scenegraph json not iterable HOT 2
- [Bug] GLTF: TypedArray for BufferView
- 3D Tiles Implicit Tilesets with multiple subtrees not loading HOT 4
- Failed to open this OBJ file, wrong positions from loader.
- chore: Use SPDX license headers HOT 2
- Getting context._parse error when try to upload Shape File HOT 6
- Loading 3D tiles is very slow, skipLevelOfDetail implementation?
- Cannot find module '.../node_modules/@loaders.gl/flatgeobuf/node_modules/flatgeobuf/lib/mjs/generic/feature' HOT 2
- Fails to load MIME type "image/PNG" due to case-sensitive parsing
- getTypedArrayForImageData failed to return data
- Implement a COPC tiled loader HOT 2
- [Feature] support loading layer data from S3 HOT 5
- @loaders.gl/tile-converter Failed to execute yarn bootstrap HOT 2
- Missing dependencies in package.json HOT 4
- [Feature] glTF: Support per-texture transforms in KHR_texture_transform HOT 2
- [Enhancement]: Support more data types in Draco decoder HOT 1
- Tracker: Parquet
- Basis File Examples HOT 7
- error in loading laz file using LASLoader HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from loaders.gl.