# obtaining screen position?

9 replies to this topic

### #1Phlex

Member

• Members
• 53 posts

Posted 26 July 2009 - 02:54 AM

Hey, I'm trying to render a deferred point light in DirectX9 C++ based on the XNA C# code here (http://www.catalinzi...om/?page_id=55). My directional light works fine, however my point light is failing to work correctly, this is what im getting when I render a point light;

It should be the right way up in the very centre of the screen like how my Directional light is:

I think it has something to do with how I get the screen position coordinates in my shader. Originally it was like this:



{

float3 Position : POSITION0;

};

{

float4 Position : POSITION0;

float4 ScreenPosition : TEXCOORD0;

};

{

//processing geometry coordinates

float4 worldPosition = mul(float4(input.Position,1), World);

float4 viewPosition = mul(worldPosition, View);

output.Position = mul(viewPosition, Projection);

output.ScreenPosition = output.Position;

return output;

}

{

//obtain screen position

input.ScreenPosition.xy /= input.ScreenPosition.w;

// calculate light, snip

}



But the compiler would say this whenever I tried to access TEXCOORD0.w outside the vertex shader:

Quote

Direct3D9: VS->PS Linker: X446: (Error) Current pixel shader declares input texture coordinate t0.xyzw. However the current transformed vertex declaration (vertex proc. disabled) only provides texcoord0.xy

So then I moved

input.ScreenPosition.xy /= input.ScreenPosition.w;

into the vertex shader just above the return output line, and it no longer complained about anything, however it looks wrong, I believe the rest of the code is fine, however if anyone wishes to see the code I use to render the point light in C++ or HLSL please ask. I've spent at least a week trying to figure this out, so thank you in advance for any ideas, suggestions or help you may have.

### #2Reedbeta

DevMaster Staff

• 5307 posts
• LocationBellevue, WA

Posted 26 July 2009 - 05:34 AM

Yeah, moving the divide by w into the vertex shader will give wrong results as the interpolation will no longer be perspective correct. However, the code you posted looks fine to me, so I'm not sure why that error is popping up. It's a bit mysterious. I wonder what "vertex proc disabled" means - it sounds like it thinks the vertex program is not being used, or it is throwing it out entirely due to some problem? Unfortunately MSDN doesn't have any listing for that phrase, or for the X446 error code - which is pretty surprising, as they usually have quite thorough documentation. I'm not sure how easy it is to submit a support request / bug request to MS, but you may try seeing if you can do that to get some more info about this error.
reedbeta.com - developer blog, OpenGL demos, and other projects

### #3Phlex

Member

• Members
• 53 posts

Posted 26 July 2009 - 06:17 AM

Hey, thanks for the reply, that was compiled under SM 2.0, if I compile with 3.0 I get this

Quote

Direct3D9: VS->PS Linker: X777: (Error) The current pixel shader expects vertex declaration to provide semantic 'texcoord0' including components(s): 'xyw', however the current transformed vertex declaration (vertex proc. disabled) provides 'texcoord0' with component(s): 'xy'. The vertex declaration's component set needs to be a superset of pixel shader input component set.

I'm not sure if it matters, but it's a new error code number so maybe that will be have documentation on MSDN? Where can you search error codes on MSDN? If nothing comes of this I'll send an error report to Microsoft.

### #4JarkkoL

Senior Member

• Members
• 475 posts

Posted 26 July 2009 - 06:52 AM

If you use SM3.0, you should use VPOS register to get the pixel coordinates in screen space.

### #5Reedbeta

DevMaster Staff

• 5307 posts
• LocationBellevue, WA

Posted 26 July 2009 - 04:55 PM

No results for X777 either. There's no special place to search; I just google with 'site:msdn.microsoft.com', or use the search bar on the MSDN homepage.
reedbeta.com - developer blog, OpenGL demos, and other projects

### #6roel

Senior Member

• Members
• 698 posts

Posted 27 July 2009 - 05:54 PM

I can't reproduce your error. I made an .fx file with this:

uniform extern float4x4 World;
uniform extern float4x4 View;
uniform extern float4x4 Projection;

{
float3 Position : POSITION0;
};

{
float4 Position : POSITION0;
float4 ScreenPosition : TEXCOORD0;
};

{

//processing geometry coordinates
float4 worldPosition = mul(float4(input.Position,1), World);
float4 viewPosition = mul(worldPosition, View);

output.Position = mul(viewPosition, Projection);
output.ScreenPosition = output.Position;
output.ScreenPosition.xy /= output.ScreenPosition.w;

return output;
}

{
//obtain screen position
input.ScreenPosition.xy /= input.ScreenPosition.w;

// calculate light, snip
return 0;
}

technique StandardFW
{
pass P0
{
}
}


So with the homogenization w div stuff in both the vs (wrong) and ps (correct), but I don't get any errors.

### #7Phlex

Member

• Members
• 53 posts

Posted 27 July 2009 - 07:59 PM

Hi,
I am beggining to think it is my hardware, sadly. What are you running?

Thank you

EDIT: ok some strange things are going on, first of all, this code gives me no run time debug info regarding input texture coordinates:

float w = input.ScreenPosition.w;

as does anything else accessing the values individually. However, if I attempt this:

input.ScreenPosition.xy /= w;

or even

input.ScreenPosition.x /= w;

It starts throwing out errors all over the place. I can multiply and all sorts of things, but the moment I try and divide using the values, it dies.

### #8roel

Senior Member

• Members
• 698 posts

Posted 27 July 2009 - 09:11 PM

Sorry, I wasn't clear enough: with "no errors" I meant "no compiler errors". How do you compile that shader? I did:
fxc /T fx_2_0 myfile.fx

### #9roel

Senior Member

• Members
• 698 posts

Posted 27 July 2009 - 09:21 PM

Ah. I believe I know now. There shouldn't be a D3DDECLUSAGE_POSITIONT in your vertex declaration.

### #10roel

Senior Member

• Members
• 698 posts

Posted 30 July 2009 - 06:48 AM

Was that right?

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users