1 registered members (AndrewAMD),
1,306
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Vector Displacement, realtime Blendshapes
#473770
08/13/18 04:57
08/13/18 04:57
|
Joined: Apr 2002
Posts: 1,246 ny
jumpman
OP
Serious User
|
OP
Serious User
Joined: Apr 2002
Posts: 1,246
ny
|
Hi friends, I might be biting off more than I can chew, but I was wondering if this is possible.
With tex2dlod, and pixel shader 3, you are able to sample a texture within the vertex shader, and move vertices around based on reading textures. This is how they make oceans move, terrain deformation and etc. However, as a character artist, im really interested in seeing if I can implement blend shapes/morph targets. A big reason is to add facial expressions.
Right now, I can do very simple stuff with texture fetch within the vertex shader. I could do something like, move the vertex up X amount of units based on the red channel of the texture. Move this vertex down X amount of units based on the blue channel of the texture.
But as you can see, you cant store negative values in a texture, especially any formats that gamestudio can accept.
How can I offset a vertex, in the XYZ axis, but also displace them in the negative direction?
Ive looked up vector displacement formulas in google, and I dont know where to start.
|
|
|
Re: Vector Displacement, realtime Blendshapes
[Re: jumpman]
#473771
08/13/18 08:21
08/13/18 08:21
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
You can just store the data in the vertices itself, then you don't have to sample textures.
typedef struct {
float x,y,z; // position in DirectX coordinates
float nx,ny,nz; // normal
float u1,v1; // first coordinate set, for textures
float u2,v2; // second coordinate set, for shadow maps
float x3,y3,z3,w3; // third coordinate set, for tangent vector and handedness
float tu4,tv4; // 4th coordinate set, for additional data
} D3DVERTEX;
That's the D3DVERTEX vertex declaration from atypes.h - it's wrong though, you cannot really access and use tu4,tv4 like that. A8 is using the following instead:
const D3DVERTEXELEMENT9 VertexA8[] = {
{ 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 },
{ 0, 32, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 },
{ 0, 40, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 2 },
{ 0, 56, D3DDECLTYPE_UBYTE4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0 },
{ 0, 60, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDINDICES, 0 },
D3DDECL_END()
};
Might look confusing at first but what it tells you is how the last 8 byte ("float tu4,tv4") are actually used. I'd recommend using ent_buffers over ent_getvertex to get D3DVERTEX pointers. You could for example use the 2nd UV set to store data.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: Vector Displacement, realtime Blendshapes
[Re: Superku]
#473782
08/14/18 21:46
08/14/18 21:46
|
Joined: Apr 2002
Posts: 1,246 ny
jumpman
OP
Serious User
|
OP
Serious User
Joined: Apr 2002
Posts: 1,246
ny
|
Thanks for helping with that snippet Superku. Im having trouble wrapping my head around how to not only generate the correct vector displacement map within mudbox, but also write the vertex displacement snippet in my vertex shader. This may be over my head. I might give it a few more shots.
float4 bloatShape1 = tex2Dlod(clothSampler6, float4(InTex.x,InTex.y,0,0) );
float3 bloatMove1 = (bloatShape1-0.5)*20;
I cant just InPos.xyz += bloatmove1 , this will offset everything in one direction. I dont know the correct map to generate within mudbox (16bit), and I dont know how to offset a vertex position based on the RGB components. Im not finding formulas online either. Do you think you have pseudo code to manipulate a vertex on RGB? What would be a good sample texture in mind that you think would work?
|
|
|
|