I'm trying to work with transformed quads, that is to say, quads that have there vertices defined in screen coordinates. Basically im trying to shift those quads to different points on the screen. The trouble is, those points are defined in world coordinates.

I'm attempting to write a shader that will accept transformed vertices (from a 2D quad), and shift those vertices to a point on the screen (lets call the point 'p') which is defined in world coordinates. Point 'p' is passed to the shader along with the quad vertex.

So basically, i need to convert my point 'p' to screen coordinates using the shader, and then translate my quad coordinates (defined in screen space) to 'p'.

I have a base quad that has the vertex coordinates: (0,1,0,1), (0,-1,0,1), (1,-1,0,1), (1,1,0,1). I then scale and shift the quad in the shader as appropriate. For this example, i scaled the x component of the vertices by 100, and the y component by 2. So you basically end up with a 4pixel high quad x 100pixels wide. The quad is built around the screen origin (top-left corner) so all i have to do is shift all the vertices is the quad by 'p' to place the quad in the right spot.

I can get my quads to move around to roughly the right relative positions from each other, but not the correct positions on the screen. It seems the magnitude of the translations is not right (only guessing).

Main shader code is posted below. Any help would be much appreciated.

struct VSOutput { float4 Pos_ws; float4 Pos_ps; float4 Color; }; VSOutput ComputeVSOutput2DShift(float4 position, float4 col, float4 p) { VSOutput vout; // convert point to clip coordinates float4 pCLIP = mul(p, WVP); // convert point to screen space float3 pNDC = pCLIP.xyz / pCLIP.w; // adjust height position.y *= 2; // adjust width position.x *= 100; // convert vertex to screen space position.xy /= ViewportSize; position.xy *= float2(2, -2); position.xy -= float2(1, -1); // translate vertex position.x += pNDC.x; position.y += pNDC.y; // set output data vout.Pos_ps = position; vout.Color = col; return vout; }

**Edited by porters, 04 December 2012 - 05:26 PM.**