4
$\begingroup$

I am starting to learn WebGL. Can a scene graph be stored in the GPU? Or is that type of thing more for the main thread (or webworker)?

For example, I want to calculate some layout, and apply it as a transform matrix. Can I keep track of a scene graph node in the GPU over time, and modify it's properties over time?

I'm just wondering because I know the GPU architecture is different. Do people normally do scene graph stuff outside the GPU? Can it be done in the GPU?

$\endgroup$
3
  • $\begingroup$ Better question would be, should you have scene graph in rendering engine at all ;) $\endgroup$
    – JarkkoL
    Commented Feb 22, 2017 at 4:04
  • $\begingroup$ @JarkkoL why wouldn't you? how could you otherwise impose relative movements in the scripting of a game engine for instance? $\endgroup$
    – Matthias
    Commented Feb 23, 2017 at 13:53
  • $\begingroup$ @Matthias just explicitly update transformation of such objects. relative movement is extremely rare in practice and should be dealt as an exception, not as part of common engine data structure. $\endgroup$
    – JarkkoL
    Commented Feb 23, 2017 at 14:03

2 Answers 2

1
$\begingroup$

A gpu only cares about the full transform used for a particular object. It's much better that the CPU (webworker) collates the transformation hierarchy into a single matrix.

What you can do is use UBO and create a block where the final transform is stored and as you traverse the scenegraph update the data on the gpu. In the vertex shader you then index into it to get the data that applies to the vertexes. But you shouldn't store graph data in there only the final data needed for rendering.

$\endgroup$
1
  • $\begingroup$ Thanks! For now, I have the scene graph on the main thread, but it would be nice to have it in a web worker then. I would also like to do things like node.rotation.x = 30 from the main thread, and have that update the scene graph node in the worker (effectively the main thread API is just an interface that updates the actual node in the worker). Does that seem like a good approach? I'm going to try it here: github.com/trusktr/infamous $\endgroup$
    – trusktr
    Commented Feb 28, 2017 at 20:37
7
$\begingroup$

Short answer: Yes, It can be done. But no one does so.

Long answer: Scene graphs can be stored and processed on a GPU using OpenCL/WebCL. But it is not practical to do so. Updating scene graphs (a tree not in flat memory) on a GPU is slow, and processing it on a GPU is also slow (again, the tree is not in flat memory), while computing transformation matrices is cheap on a CPU. Thus no one is doing this.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.