Comments (14)
Thanks for the patience; I've published v 0.28.1 which should fix your frame rate issue. Please reopen if that's not the case. :)
from troika.
(Sorry for the very long error log)
from troika.
I found out that this only happens when using the postprocessing library, when enabling the instancing workaround.
from troika.
The reason this is happening is because of this part:
// Handler for automatically wrapping the base material with our upgrades. We do the wrapping
// lazily on _read_ rather than write to avoid unnecessary wrapping on transient values.
get material() {
let derivedMaterial = this._derivedMaterial
const baseMaterial = this._baseMaterial || defaultMaterial
if (!derivedMaterial || derivedMaterial.baseMaterial !== baseMaterial) {
if (derivedMaterial) {
derivedMaterial.dispose()
}
derivedMaterial = this._derivedMaterial = createTextDerivedMaterial(baseMaterial)
// dispose the derived material when its base material is disposed:
baseMaterial.addEventListener('dispose', function onDispose() {
baseMaterial.removeEventListener('dispose', onDispose)
derivedMaterial.dispose()
})
}
return derivedMaterial
}
The postprocessing workaround changes the materials of all the meshes every render two times: https://github.com/vanruesc/postprocessing/blob/master/src/core/OverrideMaterialManager.js
from troika.
Ah I see, so it essentially ends up doing...
let mtl = textMesh.material
...
textMesh.material = mtl
I can see how that would end up double-deriving the material. Should be a simple fix, I just have to check whether the incoming material is already a derived text material.
@giulioz Do you happen to have an online example using your particular postprocessing setup that I could test this with - a Codesandbox or something?
from troika.
I tried to replicate a similar situation with react-three-fiber and I got even another kind of error: https://codesandbox.io/s/troika-text-pp-bug-ymsv1?file=/src/index.js
from troika.
That codesandbox is using an old version, that shadowSide bug was fixed already.
I've just published version 0.28.0 which I think should fix your postprocessing error, give that a try and reopen this ticket if there's still an issue.
from troika.
My fault, I forked from another sandbox and forgot to update...
I updated the sandbox and now it exhibit the bug: https://codesandbox.io/s/troika-text-pp-bug-ymsv1?file=/src/index.js
I'll let you know if 0.28.0 fixes the bug, thank you very much in advance.
from troika.
The fix works but it slows down everything. The profiler shows that a lot of time is spent in shader program compilation (getProgramInfoLog).
The debugger shows that createDerivedMaterial gets called every frame, is this right?
In the material getter it enters this branch when rendering the normals for postprocessing:
from troika.
Hmm, yeah I suppose that makes sense if postprocessing is assigning a different MeshNormalMaterial instance every frame. The createDerivedMaterial utility will cache by base material instance, not by material class, so if it's not using the same material instance each time it will re-derive.
Still, though, ThreeJS's program management should reuse a webgl program if the shader content isn't changing, so there must be something I'm doing that causes slightly different shader content each time. I'll look into that.
from troika.
Ah yes, the rewritten shaders use an id
to disambiguate certain things. That id
is different per base material, hence the resulting shaders are different.
This could be a tricky one to fix without breaking other things. If you could still provide a testcase for me that would be very helpful.
from troika.
I've updated the Codesandbox (https://codesandbox.io/s/troika-text-pp-bug-ymsv1).
If you put a breakpoint in createTextDerivedMaterial (textmesh-standalone.umd.js:5944) you can see it's called every frame.
from troika.
@giulioz Thank you for that CSB example, that's perfect. I've been able to reproduce it locally using that and I have a tentative fix that seems to be working. But this derived material logic is pretty finnicky/fragile so I'm going to put it through its paces during my day job work for the rest of the week, before pushing it out. Hope that doesn't hold you up too badly.
from troika.
No problem! Thanks for the assistance and your hard work on this amazing library :)
from troika.
Related Issues (20)
- Util function getCaretAtPoint can't get the uniform text caret vertical position for number/character and Chinese text. HOT 5
- Runtime error: 'webgl-sdf-generator' does not contain a default export (imported as 'createSDFGenerator'). HOT 3
- Emoji and Unicode support HOT 3
- Memory Issue with troika-three-text HOT 5
- troika-three-text: Indic shaping
- getCaretAtPoint(...) taking surrogate pairs into consideration HOT 2
- Support ligature caret positioning provided in font
- anchorY="bottom-baseline" not working since v0.48.0 HOT 2
- Glitches when used with Montserrat HOT 2
- Cloning a synced text still requires sync();
- [ Angular 17 ] - TS2307: Cannot find module 'troika-three-text' or its corresponding type declaratio HOT 1
- troika-three-text uncaught exception HOT 8
- Apply GLSL shader to only some letters
- Fix netlify links in documentation
- Cannot set property customDepthMaterial of #<InstancedUniformsMesh> which has only a getter
- LinearEncoding was not found in 'three'
- troika-three-text: mesh.textRenderInfo missing lineHeight and other font metrics HOT 3
- troika-three-text: First line of text is missing "top" spacing HOT 10
- How to draw many instance of plan with same texture but with different uvs.
- troika-three-text: possible to use in a webworker? HOT 6
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 troika.