Gamestudio Links
Zorro Links
Newest Posts
MT4/5 - wrong M1 time
by Grat. 06/02/20 12:10
Comment MT4 "Trade Test"
by Grat. 06/01/20 20:51
Login info through strategy script?
by AndrewAMD. 06/01/20 13:29
Windows 10 file_write error
by Spirit. 06/01/20 11:04
Out of Sample
by AndrewAMD. 06/01/20 01:30
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
11 registered members (AndrewAMD, alibaba, jbhunter, Dalla, ESR, 3run, Dooley, FLD, jenGs, 1 invisible), 545 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Frank_Shieh, PBSeven, Hardi01, Giuseppe, AdamWu
18461 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
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,227
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,227
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,322
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,322
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!

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

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

Re: How to offset a vertex in world space instead of object space [Re: jumpman] #473112
06/14/18 08:03
06/14/18 08:03
Joined: Dec 2000
Posts: 4,607
mk_1 Offline

Expert
mk_1  Offline

Expert

Joined: Dec 2000
Posts: 4,607
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
Re: How to offset a vertex in world space instead of object space [Re: mk_1] #473123
06/15/18 07:11
06/15/18 07:11
Joined: Jun 2007
Posts: 1,322
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,322
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!


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