0
\$\begingroup\$

So I'm trying deferred shading in DirectX11.

I am using the following method (used in the FXAA shader and described here: http://www.altdev.co/2011/08/08/interesting-vertex-shader-trick/) to render a fullscreen triangle for my deferred shading pass.

FullscreenTriangleVSOut main(uint VertexID: SV_VertexID)
{
    FullscreenTriangleVSOut output;

    output.mTexcoord = float2((VertexID << 1) & 2, VertexID & 2);
    output.mPosition = float4(output.mTexcoord * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f), 0.0f, 1.0f);

    return output;
}

And then in the pixel shader, I want a proper texture coordinate to sample my diffuse, normal, position textures from the GBuffer.

In GLSL, I simply do:

ivec2 texcoord = ivec2(textureSize(unifDiffuseTexture) * (gl_FragCoord.xy / UnifAmbientPass.mScreenSize));

But for some reason, in HLSL my SV_POSITION is always (0.5, 0.5). I looked in visual studio 2013 and debugged the pixel shader at various pixels, and yes at all places the SV_POSITION is (0.5, 0.5). Why is this?

\$\endgroup\$
0
\$\begingroup\$

You can't use SV_Position for this in hlsl, you should get the position from an other output slot without the SV_Position semantic instead.

output.mPosition = float4(output.mTexcoord * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f), 0.0f, 1.0f);
output.mNewPos = output.mPosition; //use mNewPos in the pixel shader

SV_Position is just for the rasterizer.

\$\endgroup\$
  • \$\begingroup\$ Are you sure? Looking at msdn.microsoft.com/en-us/library/windows/desktop/… for example, it seems perfectly valid to use SV_Position as input to the pixel shader? \$\endgroup\$ – KaiserJohaan Jul 29 '14 at 14:03
  • \$\begingroup\$ I also tried this but couldn't get it to work, so used the above solution. You could wait some more until some directx god shows up and gets you some facts. Until then I suggest you try this. ;) \$\endgroup\$ – János Turánszki Jul 29 '14 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.