Gamestudio Links
Zorro Links
Newest Posts
New Zorro version 1.83
by jcl
Today at 16:24
Unfreed in -diag
by 3run
Today at 10:30
About STRING* and char
by 20BN
Today at 09:40
I need help
by evangelos
Today at 02:37
Draw stuff from other thread
by Superku
Yesterday at 22:00
Optimize Stop with multi Asset strategy
by Dalla
Yesterday at 21:48
cloth ?
by 3run
Yesterday at 20:48
AUM Magazine
Latest Screens
Evonet Beta v1.0 : Online Project Development Template
Lake scene
Forgotten Tales - Demo version
RPG PARTY
Who's Online
16 registered (easyX, 3run, AndrewAMD, alibaba, FirasTaji, jenGs, 5 invisible), 492 Guests and 3 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
FirasTaji, zentrader, Fenry, DJ_Algo, tang
18005 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: 1170
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: 1141
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: 1170
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: 4599
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: 1141
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