Gamestudio Links
Zorro Links
Newest Posts
Calculating with price series
by AndrewAMD. 10/21/19 14:31
Instrument Price Zorro Chart
by felixfx. 10/21/19 12:51
Error E355: Startup failure
by Dooley. 10/21/19 06:47
Today real live account blown - my experience
by Clifford_B. 10/19/19 17:09
Building Diversified Portfolios - New Paper
by SnoopySniff. 10/18/19 16:23
Indices & metals easier to trade than FX???
by SnoopySniff. 10/18/19 10:08
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
7 registered members (AndrewAMD, MatPed, Dico, Grat, Zheka, Dalla, 1 invisible), 642 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
VillageTalkies, line7, Shutch, Clifford_B, Paulius
18310 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Vector Displacement, realtime Blendshapes #473770
08/13/18 04:57
08/13/18 04:57
Joined: Apr 2002
Posts: 1,225
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,225
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.


A8 Pro 8.47
Re: Vector Displacement, realtime Blendshapes [Re: jumpman] #473771
08/13/18 08:21
08/13/18 08:21
Joined: Sep 2003
Posts: 6,848
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,848
Kiel (Germany)
You can just store the data in the vertices itself, then you don't have to sample textures.

Code:
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:

Code:
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] #473776
08/13/18 18:04
08/13/18 18:04
Joined: Apr 2002
Posts: 1,225
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,225
ny
wow thats really interesting Superku, thank you!

How would you force information into those floats? Would it depend on the modelling program you use? And wouldnt this information be discarded once you save it as an MDL file?

Also wouldnt this also mean the bytes could only store a single set of floats? Which means if we could force information in there, that it would only support one blendshape?


A8 Pro 8.47
Re: Vector Displacement, realtime Blendshapes [Re: jumpman] #473779
08/14/18 04:51
08/14/18 04:51
Joined: Sep 2003
Posts: 6,848
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,848
Kiel (Germany)
You'd have to do that via code (for example ent_buffers, see previous post), yes.
That's true, the available data is very limited (for my cases it's enough most of the time).

To help with your original question: Just use 128 as your "0" in your texture channels, then everything below 128 is negative, above is positive. In the vertex shader:
float4 texData = tex2Dlod(...);
float3 displacement = (texData-0.5)*someScalingFactor;


"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,225
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,225
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.

Code:
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?


A8 Pro 8.47
Re: Vector Displacement, realtime Blendshapes [Re: jumpman] #474027
09/09/18 07:17
09/09/18 07:17
Joined: Dec 2003
Posts: 1,097
Maryland, USA
Steempipe Offline
Serious User
Steempipe  Offline
Serious User

Joined: Dec 2003
Posts: 1,097
Maryland, USA
Helpful info, SuperKu.


Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1