Readit News logoReadit News
mlsarecmg commented on Use.GPU Goes Trad   acko.net/blog/use-gpu-goe... · Posted by u/puzzlingcaptcha
SeanAnderson · 3 years ago
The author's entire section on "Real Reactivity" hit quite close to home.

I recently played around with using https://reactpixi.org/ to build a simple ant farm simulation (https://meomix.github.io/antfarm/) and was left disappointed regarding rendering performance, but not surprised. It's a real challenge to get strong numbers when stacking a declarative wrapper on an imperative base. I found myself fighting React's reconciler for performance almost immediately.

I was talking to my coworkers about the issue and one of them suggested trying to use react-three-fiber and just force it to render 2D, but, as the author notes, the problem feels intractable with competing layers of abstraction.

I'm really excited to learn about this library. I feel that I was between a rock and a place with my web-first, declarative graphics tooling. I was pushing myself to learn Rust, to use Bevvy, to have a well-supported, declarative framework, but I felt I would prototype quicker if I stuck with JavaScript. I considered A-Frame, but it's really not about 2D rendering at all with its VR-first approach.

There's really quite a desert of modern, active, declarative, web-first graphics rendering frameworks. Stoked for UseGPU to hit 1.0!

mlsarecmg · 3 years ago
React acknowledges that nothing can ever be purely declarative, it allows you to declare a view while giving you an outlet for imperative computations and side-effects (hooks). There is no contradiction in that.

In Fiber to animate is to use useFrame, which happens to be outside of React and bears no extra cost or overhead, nor does it conflict with reactive prop updates. useFrame allows any individual component to tie its mutations into the render loop.

The reactivity debate is next to irrelevant in WebGL because that is a loop driven system, it is not event-driven like the DOM. If you doubt that observe Svelte/Threlte, which can update the view directly, yet relies on useFrame modeled after Fibers. That is because you need deltas (to be refresh-rate independent), flags (needsUpdate), imperative functions (updateProjectionMatrix etc), it is never just a prop update.

That said, i don't know much about React-Pixi/Konva and so on, and if these do not have a loop outlet then yes i agree. But the whole premise of that article just falls flat.

mlsarecmg commented on Show HN: Collaborative event registration with WebGL and WebSockets   nextjs.org/conf?d=oct2022... · Posted by u/nutlope
hughes · 3 years ago
Whatever this is it brings my 2019 MacBook Pro down to 1fps in Firefox.
mlsarecmg · 3 years ago
sounds like gpu accel is off. or extensions messing with the browser? mbp going to 1fps over a bit of webgl must have a cause.
mlsarecmg commented on React Renderer for Three.js   github.com/pmndrs/react-t... · Posted by u/oleksiitwork
tuckerconnelly · 4 years ago
React is inspired by the DOM and they split it before 1.0 IIRC, but that misses the forest for the trees. The main issue I had is that React, Three.js, and R3F are all hierarchical/tree-like (what you and Three.js are calling a graph). You can technically yes, build 3D scenes, but anything non-trivial will be very awkward.

Let's say you're building a game where you want a sphere to stick to whatever player you throw it at. How would you do that with a scene graph/OOP model? It'd be awkward, removing objects from one parent and adding them to another. Even more awkward if it's a complex object and you only want a part of that complex object to stick to the player. ECS + a constraint or physics system does a decent job (not perfect) of handling this in a relatively elegant and performant way.

I've used Three.js enough--built my portfolio[1] out of it, and then switched to Babylon when I realized how little I liked Three.js. For the record, I also dislike Babylon.

[1] https://tuckerconnelly.com

mlsarecmg · 4 years ago
i have yet to encounter something that shouldn't be expressed as a graph. three, babylon, ogl, blender, gltf, cad, games, they're all scene aligned. that doesn't seem to be a conflict since you still use shaders, physics, ecs and so on.

could you go more into detail what you mean when you say "anything non trivial"? is there a real example of something that would not be possible to create in, say, threejs?

mlsarecmg commented on React Renderer for Three.js   github.com/pmndrs/react-t... · Posted by u/oleksiitwork
dheera · 4 years ago
So just do it with VRML5 like HTML5.

<cube id="myCube" x="0" y="0" z="0" width="10px" height="10px" length="10px" onClick="someFoo()" onMouseOver="someOtherFoo()" onTouchStart="someBar()">

<video src="blah.mp4" rotateX="45deg" rotateY="30deg" autoplay="true" loop="true" onClick="document.querySelector('#myCube').rotateX(45);">

...

No reason the above can't be done. But many people will come up with lame excuses about why we shouldn't have nice things.

mlsarecmg · 4 years ago
i can't say why webgl took over, as well as threejs, but i like how close to the metal they are. i would also much rather have a lower level representation underneath instead of starting outright with a markup language. i think that's why vrml eventually faded. i generally don't see why 3d should be represented in html.

as for react, it merely expresses threejs, and adds something which three doesn't have: self contained components that are now sharable. something like this: https://twitter.com/0xca0a/status/1394697847556149250 just didn't exist in the web previously.

mlsarecmg commented on React Renderer for Three.js   github.com/pmndrs/react-t... · Posted by u/oleksiitwork
dheera · 4 years ago
> updating 2,000 cubes at 60fps

Have we gotten so bloated with framework on top of framework that even this is deemed an impossible load?

If you write straight-up WebGL code 2000 cubes at 60fps should be a walk in the park for any modern PC.

mlsarecmg · 4 years ago
threejs has no problem rendering hundreds of thousands of objects, so react doesn't have a problem either because its baseline is threejs, it does not introduce overhead or a performance penalty. These components render in a regular RAF loop, react is not involved at all unless you are mounting/unmounting objects, and this is where it can actually be faster.
mlsarecmg commented on React Renderer for Three.js   github.com/pmndrs/react-t... · Posted by u/oleksiitwork
arcanon · 4 years ago
The age of WebGPU is almost upon us. Chrome 94 comes out this quarter. I doubt React will be the major player in this next epoch. It will be something new that can pull off an instant load shared world game.
mlsarecmg · 4 years ago
Threejs already has a webgpu renderer.
mlsarecmg commented on React Renderer for Three.js   github.com/pmndrs/react-t... · Posted by u/oleksiitwork
beebeepka · 4 years ago
One of those things that make zero sense but use react, and that makes them cool enough to blog about.
mlsarecmg · 4 years ago
It has similar benefits as react-dom has for the dom. Less code, faster performance, less memory consumption, real interop with a growing eco system.
mlsarecmg commented on React Renderer for Three.js   github.com/pmndrs/react-t... · Posted by u/oleksiitwork
tuckerconnelly · 4 years ago
I really don't think React will be the go-to tool for VR; it's based on the DOM and trees of function calls, which are both hierarchical, which necessarily means you have the gorilla-banana problem.

If you have a coffee cup on a table in VR, is that coffee cup a child of the table? How do you move the coffee cup off the table and put it onto another table? Is it now a child of that other table? What about the coffee in the cup? Is that a child of the cup? How do you change properties of the coffee without necessarily accessing the table and the cup?

Developers working on 3D systems have developed much better paradigms than the DOM for dealing with this problem. An Entity-Component-System architecture with "constraints" is the current best solution. In that architecture, you would create a coffee cup "entity" with a mesh "component" with another "constraint" component, constraining that coffee cup to the table (or better yet, mass component acted on by a physics system). Then you can simply remove the constraint component when removing the cup from one table, and re-add the constraint component when adding it to the other table.

Overall, I think web developers are in for some intense learning and paradigm shifts if 3D becomes the norm.

mlsarecmg · 4 years ago
React is not based on the dom, R3f merely expresses regular threejs which works as an object graph. Three is the usual choice for 3D on the web, if you use it once you'll see that it is also quite natural. There is no conflict between the two and react certainly doesn't change any rules or apis, it just builds a graph, which you would normally form imperatively.
mlsarecmg commented on React Renderer for Three.js   github.com/pmndrs/react-t... · Posted by u/oleksiitwork
webgfxdev · 4 years ago
React is one of the worst choices of doing something like that.

The underlying abstraction model of having a tree of components and re-rendering only the parts that have changed between renders doesn’t map to the hardware at all, meaning you’ll waste most of the HW performance just on maintaining the abstraction.

You’ll also get zero benefits from the third-party libraries - there’s nothing in them that can help you with stuff that matters, like minimizing amount of the GPU state transitions for example or minimizing amount of GPU/CPU syncs.

It will be scenegraphs all over again, and the graphics industry has ditched these long ago in favor of simpler models, for good reasons.

Long story short, the happy path in graphics programming is very narrow and fragile, and you typically want to structure your abstraction around it.

mlsarecmg · 4 years ago
You are arguing against threejs not react. R3f reconciles threejs in the exact way it's getting used, a graph. This ofc is also how blender gltf et al work. If you make a webgl app on the web you most likely use three and all react does is make that a little ordered with some additional benefits when it comes to performance, memory and interop.
mlsarecmg commented on React Renderer for Three.js   github.com/pmndrs/react-t... · Posted by u/oleksiitwork
felipellrocha · 4 years ago
It’s just what you’re rendering is getting nowhere near pushing the limits of what can be done with the gpu.
mlsarecmg · 4 years ago
if you have a threejs app that pushes the limits, the react counterpart will merely do the same, only with less code. threejs renders exclusively.

u/mlsarecmg

KarmaCake day464May 7, 2016View Original