Multiple vertex streams

Hi,

is it possible to have one shader receive two vertex position channels?

Basically:

// vertex input: position, position
struct appdata {
    float4 position1;
    float4 position2;
};

How would i send those positions from mesh to the shader?

I need this because I’d like to try to implement morphing animation on the shader. I have very little experience with Unitys shaders so please help :wink:

Thanks

you can send two float4 thats no problem.
But there is no future vertex position only the current one as provided by the animation shader

Your main work will be providing the target position etc to the shader towards which it interpolates in the near future

That is my main concern yes.

The position1 would be from the source mesh, and position2 would be the target mesh.

In DirectX I could just set up a vertex declaration like this:

D3DVERTEXELEMENT9 MorphMeshDecl[] =
{
// 1st stream is for source mesh
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
{ 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
// 2nd stream is for target mesh
{ 1, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 1 },
{ 1, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 1 },
{ 1, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 },
D3DDECL_END()
};

and then just do SetStreamSource(0, &VBSource, …), SetStreamSource(1, &VBTarget, …).

And render the scene, and the shader would get both the source and target position and then I could easily interpolate between the two.

What i’m asking. Is there a way to duplicate this functionality in Unity?

You have no access to the engine source code unless you source license unity.

Also, I’m unsure this would help that much even if it worked.
The vertex interpolation of the target frame would have to be done first if you don’t provide multiple static meshes (which most users likely would like to avoid), so your morph animation would actually be a multi pass vertex shader to first generate the target frame transformations (regular skin animation) and then do the morphing.
Not sure if just using CPU won’t be faster for quite some users and the cpu solution is already present as far as I’m aware.

The easiest solution would be if the animation shader were changeable but I don’t think its source is available

The entire point would be to provide multiple static meshes. No skeletal animation would be used AT ALL. Sorry for not being clear on this.

CPU solutions are extremely slow because I need to send the interpolated mesh to the video memory every frame. The vertex shader way would be many times faster, and that’s why I need it.

I fear you either have to source license unity or wait until UT implements morphing then. No way for you to alter it.