Gamestudio Links
Zorro Links
Newest Posts
Access string content through another string
by ChrstphFr
47 minutes 19 seconds ago
How to return a vector from a function
by jumpman
Today at 01:24
Vector Displacement, realtime Blendshapes
by jumpman
Yesterday at 23:46
Code Repository
by OptimusPrime
Yesterday at 13:25
Votes for future features
by OptimusPrime
Yesterday at 07:18
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14
08/13/18 22:44
Getting Maximum and Minimun Values from Array
by Tavasy
08/13/18 20:38
AUM Magazine
Latest Screens
AckCon'18 - Lotter vs the World 2 - Preview Release
Evonet Beta v1.0 : Online Project Development Template
Lake scene
Forgotten Tales - Demo version
Who's Online
11 registered (Ulenspegel, jyd, ChrstphFr, OptimusPrime, HamSelv, jumpman, AndrewAMD, wdlmaster, 3 invisible), 489 Guests and 7 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
toto, FloMi, behr065, OptimusPrime, bailemad
18026 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 Online
Serious User

Registered: 04/17/02
Posts: 1190
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: 1159
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 Online
Serious User

Registered: 04/17/02
Posts: 1190
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: 4600
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: 1159
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