obtaining screen position?

5dd66e0225657f6ea919eb133ced3e68
0
Phlex 101 Jul 26, 2009 at 02:54

Hey, I’m trying to render a deferred point light in DirectX9 C++ based on the XNA C# code here (http://www.catalinzima.com/?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;

screenshot3wkf.png

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

screenshot3z.png

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

struct VertexShaderInput
{
    float3 Position : POSITION0;
};

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

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;
    
    //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;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
    //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:

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.

9 Replies

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Jul 26, 2009 at 05:34

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.

5dd66e0225657f6ea919eb133ced3e68
0
Phlex 101 Jul 26, 2009 at 06:17

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

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.

Fe8a5d0ee91f9db7f5b82b8fd4a4e1e6
0
JarkkoL 102 Jul 26, 2009 at 06:52

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

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Jul 26, 2009 at 16:55

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.

6aa952514ff4e5439df1e9e6d337b864
0
roel 101 Jul 27, 2009 at 17:54

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;

struct VertexShaderInput
{
    float3 Position : POSITION0;
};

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

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;
    
    //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;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
    //obtain screen position
    input.ScreenPosition.xy /= input.ScreenPosition.w;

    // calculate light, snip
    return 0;
}

technique StandardFW
{
    pass P0
    {
        VertexShader = compile vs_2_0 VertexShaderFunction( );
        PixelShader  = compile ps_2_0 PixelShaderFunction( ); 
    }
}

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

5dd66e0225657f6ea919eb133ced3e68
0
Phlex 101 Jul 27, 2009 at 19:59

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.

6aa952514ff4e5439df1e9e6d337b864
0
roel 101 Jul 27, 2009 at 21:11

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
6aa952514ff4e5439df1e9e6d337b864
0
roel 101 Jul 27, 2009 at 21:21

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

6aa952514ff4e5439df1e9e6d337b864
0
roel 101 Jul 30, 2009 at 06:48

Was that right?