<p>With modern hardware, morph targets probably should not be VS inputs. They should be SSBOs or the D3D equivalent. The vertex shader should fetch from these arrays of positions and act on them appropriately. You can pass the number of targets as a uniform or something.</p>

CC BY-SA 4.0
2018-05-09T17:37:54.177Z
2018-05-09T17:37:54.177Z
Nicol Bolas
<p>So with the idea that I want to load in an object with morph targets and for simplicity sake I know it will have between 1-8 position morph targets. Ultimately I want to do</p>

<pre><code>renderedPrimitive.POSITION = primitive.POSITION + 
   weights[0] * primitive.targets[0].POSITION +
   ....
   weights[N] * primitive.targets[N].POSITION;
</code></pre>

<p>But being open to load in any model how do you go about knowing the number of vertex input attributes to allocate. Getting the CPU side dynamically is not an issue, but am I wrong that the ONLY way around this is building your shader with some <code>#define</code> and compiling during runtime?</p>

<shader>
Dynamically allocating morph targets in shaders
FrickeFresh
# Dynamically allocating morph targets in shaders

(Asked by: username_0 on 2018-05-09)

So with the idea that I want to load in an object with morph targets and for simplicity sake I know it will have between 1-8 position morph targets. Ultimately I want to do

```
renderedPrimitive.POSITION = primitive.POSITION + 
   weights[0] * primitive.targets[0].POSITION +
   ....
   weights[N] * primitive.targets[N].POSITION;

```

But being open to load in any model how do you go about knowing the number of vertex input attributes to allocate. Getting the CPU side dynamically is not an issue, but am I wrong that the ONLY way around this is building your shader with some `#define` and compiling during runtime?

**Tags:** shader


---

## 1 answers

### Answer by username_1 on 2018-05-09. Score: 1 | Accepted answer

With modern hardware, morph targets probably should not be VS inputs. They should be SSBOs or the D3D equivalent. The vertex shader should fetch from these arrays of positions and act on them appropriately. You can pass the number of targets as a uniform or something.


---

