Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Imhotep), 567 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 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,246
ny
jumpman Offline OP
Serious User
jumpman  Offline 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 Offline
Serious User
txesmi  Offline
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.

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

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

Expert
mk_1  Offline

Expert

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

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