|
How to offset a vertex in world space instead of object space
#473095
06/13/18 01:11
06/13/18 01:11
|
Joined: Apr 2002
Posts: 1,246 ny
jumpman
OP
Serious User
|
OP
Serious User
Joined: Apr 2002
Posts: 1,246
ny
|
Hello shader friends
How would I, in a vertex shader(DX9, ps.vs.3), move a vertex in an axis in world space instead of object space? So I would be able to shove a vertex 4 units in the X axis within the model, but if I rotate the model/scale it move it, the moved vertex would be still moved in the X axis of the world, instead of the X axis of the object space?
So for example, I moved a vertex forward on a model's forehead towards NORTH pole. Then I rotate the model, or animate it, or move it, the vertex would still be pointing NORTH?
|
|
|
Re: How to offset a vertex in world space instead of object space
[Re: jumpman]
#473098
06/13/18 09:04
06/13/18 09:04
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
Hi, 'matWorld' matrix transforms coordinates from object space to world space, and 'matViewProj' tranforms from world space to projected space.
float3 outWorld = mul(inPos, matWorld).xyz;
outWorld.x += _offset;
outPos = mul(float4(outWorld, 1.0f), matViewProj);
Salud!
|
|
|
Re: How to offset a vertex in world space instead of object space
[Re: txesmi]
#473107
06/13/18 23:16
06/13/18 23:16
|
Joined: Apr 2002
Posts: 1,246 ny
jumpman
OP
Serious User
|
OP
Serious User
Joined: Apr 2002
Posts: 1,246
ny
|
Thank you Txesmi The following seems to work as well, is there a reason?
float4 texShove = tex2Dlod(waveSampler,float4(inTex.x,inTex.y,0,0));
float3 offset = float3(600,0,0);
inPos += mul(offset,matWorldInv ); // matWorldInv
matWorldInv is the inverse.
|
|
|
|