So I want to create one of these in my directX11 project.

The little axis there that shows you the direction.

I have a nice 3d shader for my world geometry that I tweaked from Frank D. Luna (He writes books on directX.) and another for my 2D UI so I thought I'd look at those and see what I could conjure up since I didn't know all that much about shaders to begin with. But this is what I came up with.

float4x4 gWorldViewProj;

struct VertexIn
{
float3 PosL    : POSITION;
float3 NormalL : NORMAL;
float2 Tex     : TEXCOORD;
};

struct VertexOut
{
float4 PosH       : SV_POSITION;
float2 Tex        : TEXCOORD;
};

VertexOut VS(VertexIn vin)
{
VertexOut vout;

// Transform to homogeneous clip space.
vout.PosH = mul(float4(vin.PosL, 1.0f), gWorldViewProj);

// There are no transformations for texture coordinates.
vout.Tex = vin.Tex;

return vout;
}


This code works if I pass in a quad and render a texture too it. Then for gWorldViewProj I give it just the world matrix of the UI. Renders fine.

But when I tried it with 3D objects (anything that wasn't a quad.) nothing would render. The only way I could get it to render is by passing in world * view * proj but then it rotates around the scene when you look around because of the view matrix.

So the obvious work around was to create a view matrix with no transformations and that worked.

I thought I could just give it a world matrix since that's what I did with the 2D UI. I also tried world * proj but no prevail. Why does this shader render quads without a view matrix but can't render other more complex sets of geometry without the view matrix. Here is how I generated the quad.

• I don't exactly follow you... Please remove all of the code except the actual VS. Please, then, add the code you use to generate the quad. – Jon Apr 22 '15 at 4:03

Please also expand on this: "world matrix of the UI" and show how it's constructed.

If you do not explicitly supply a World, View, or Projection, Identity is used. This has the effect of multiplying everything by 1 (no change). Using a world matrix without a view matrix is the same as using a view matrix without a world matrix; (X*1)==(1*X)==(X). I might be misunderstanding, but I suspect your confusion is stemming from that.

If World, View, and Projection are all Identity, then world-space, view-space, projection-space, and screen-space all have the same origin and units. If any matrix is not Identity, coordinates from the previous coordinate system are being moved/scaled into the next. When all objects have been located in world-space by their individual world-matrices, the entire world is moved/rotated/scaled at once by the view matrix. If the view matrix happens to be Identity, the objects are, now, already in projection space.

This is what you are doing, but its not clear, to me, exactly how yet; will update as necessary.

Keep in mind that:

translating coordinates (away from (0,0)), Then rotating them (around (0,0))


is not the same as:

rotating coordinates (around (0,0)), Then translating them (away from (0,0))


So the obvious work around was to create a view matrix with no transformations and that worked.

Your intuition is spot-on; it is very common to keep the rotation component of the view matrix separate.