Gamestudio Links
Zorro Links
Newest Posts
New Zorro v1.99.2
by jcl
46 minutes 0 seconds ago
Strategy Development
by AndrewAMD
59 minutes 37 seconds ago
closing profitable trades (stop)
by MINER
Today at 12:47
Next contest?
by jcl
Yesterday at 15:44
advance decline (ADO) code examples?
by 3dgamelight
12/09/18 19:52
Newbie coding question. HELP Please!
by 3dgamelight
12/09/18 16:28
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14
12/08/18 19:10
AUM Magazine
Latest Screens
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Evonet Beta v1.0 : Online Project Development Template
Lake scene
Who's Online
19 registered (alibaba, ags, Artvin, AndrewAMD, chsmac85, 20BN, CocaCola, Ayumi, 5 invisible), 477 Guests and 12 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
mahomed, bondz, Neil_G, bobby4h, MutilatedDuck
18117 Registered Users
Topic Options
Rate This Topic
#473095 - 06/13/18 03:11 How to offset a vertex in world space instead of object space
jumpman Offline
Serious User

Registered: 04/17/02
Posts: 1212
Loc: 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?
_________________________
A8 Pro 8.47

Top
#473098 - 06/13/18 11:04 Re: How to offset a vertex in world space instead of object space [Re: jumpman]
txesmi Online
Serious User

Registered: 06/13/07
Posts: 1192
Loc: Hiporope and its pain
Hi,
'matWorld' matrix transforms coordinates from object space to world space, and 'matViewProj' tranforms from world space to projected space.

Code:
float3 outWorld = mul(inPos, matWorld).xyz; 
outWorld.x += _offset;
outPos = mul(float4(outWorld, 1.0f), matViewProj);



Salud!

Top
#473107 - 06/14/18 01:16 Re: How to offset a vertex in world space instead of object space [Re: txesmi]
jumpman Offline
Serious User

Registered: 04/17/02
Posts: 1212
Loc: ny
Thank you Txesmi

The following seems to work as well, is there a reason?

Code:
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.
_________________________
A8 Pro 8.47

Top
#473112 - 06/14/18 10:03 Re: How to offset a vertex in world space instead of object space [Re: jumpman]
mk_1 Offline
Expert

Registered: 12/25/00
Posts: 4602
The "reason" is that you take an offset of 600 in world coordinates, and transform this offset into object space. After that I assume you use the usual matWorldViewProj transformation.

This works but I consider txesmi's solution more readable.
_________________________
Follow me on twitter

Top
#473123 - 06/15/18 09:11 Re: How to offset a vertex in world space instead of object space [Re: mk_1]
txesmi Online
Serious User

Registered: 06/13/07
Posts: 1192
Loc: Hiporope and its pain
@jumpman
On your method, it needs one matrix multiplication more in order to pass the world coordinates to the pixel shader for lighting purposes. Another side-effect is that 'matWorldInv' is not used on normal rendering an it has to be specifically computed, while 'matWorld' is always computed as multiplicand of 'matWorldViewProj'.

Salud!

Top


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