Gamestudio Links
Zorro Links
Newest Posts
Where's the Wiki?
by Quad. 06/25/19 22:16
Published Gamestudio Games?
by Dooley. 06/25/19 16:59
Updating to A8 [SOLVED]
by Dooley. 06/25/19 16:00
Message from IB of open position
by Zheka. 06/25/19 13:58
FXCM: "Can't connect to price server"
by riinvest. 06/25/19 10:35
New Zorro version 2.12
by jcl. 06/25/19 09:42
Aum120 is ready
by Emre. 06/24/19 17:54
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
5 registered members (JeyKey II, wdlmaster, alibaba, jenGs, kvm), 574 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Theaisback, redye, rhe2564, Qw3rty, Dal
18239 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,225
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

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

Joined: Jun 2007
Posts: 1,229
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,225
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

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

Expert
mk_1  Offline

Expert

Joined: Dec 2000
Posts: 4,606
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,229
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

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