<p>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.</p>

<p>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.</p>

CC BY-SA 3.0
2017-02-28T20:37:15.440Z
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: https://github.com/trusktr/infamous
trusktr
CC BY-SA 3.0
2017-02-22T00:06:54.373Z
2017-02-22T00:06:54.373Z
ratchet freak
<p>Short answer: Yes, It can be done. But no one does so.</p>

<p>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.</p>

CC BY-SA 3.0
2017-02-22T02:08:18.270Z
2017-02-22T08:13:08.287Z
2017-02-22T08:13:08.287Z
Mary Chang
<p>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)?</p>

<p>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?</p>

<p>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?</p>

CC BY-SA 3.0
2017-02-22T04:04:18.427Z
Better question would be, should you have scene graph in rendering engine at all ;)
JarkkoL
CC BY-SA 3.0
2017-02-23T13:53:58.917Z
@JarkkoL why wouldn't you? how could you otherwise impose relative movements in the scripting of a game engine for instance?
Matthias
CC BY-SA 3.0
2017-02-23T14:03:19.187Z
@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.
JarkkoL
<transformations><gpu><webgl><javascript><scene-graph>
Can a scene graph be stored in the GPU?
trusktr
# Can a scene graph be stored in the GPU?

(Asked by: username_0 on 2017-02-21)

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?

**Tags:** transformations, gpu, webgl, javascript, scene-graph

> **Comments:**
> **username_1**: Better question would be, should you have scene graph in rendering engine at all ;)  
> **username_2**: @username_1 why wouldn't you? how could you otherwise impose relative movements in the scripting of a game engine for instance?  
> **username_1**: @username_2 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.  

---

## 2 answers

### Answer by username_3 on 2017-02-22. Score: 1 | Accepted answer

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.

> **Comments:**
> **username_0**: 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: https://github.com/username_0/infamous  

---

### Answer by username_4 on 2017-02-22. Score: 7

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.


---

