Skip to main content
GameDev.net gamedev.net
🔒 Locked

w component of SV_Position/gl_fragcoord

Started by grunt123 Sep 12, 2018 at 3:01 PM 5 replies 8.3k views
Original Post
grunt123
grunt123

Hi, guys

i read from the internet that w component of gl_fragcoord (opengl) used in pixel shader is actually 1/w. But is it same for dx11 SV_Position?

i did some pixel debugging, and it looks like it's actually just w, not 1/w.

Can anyone confirm this? thanks

xxxkxxx
xxxkxxx

Hello.
In DirectX 11, w component of SV_Position in pixel shader is view space depth.

grunt123
grunt123

hmm, ok. that means if i want to convert dx11 shader that uses w (viewspace depth) to vulkan shader (gl_fragcord), i need to do 1/w to get correct result?

xxxkxxx
xxxkxxx

Fortunately, 1/w is already stored in z component of SV_Position in pixel shader.

DiligentDev
DiligentDev

Not sure what exactly you mean by "doing 1/w", but in both HLSL and GLSL, you do not need do divide your vertex shader output by w. In all APIs your shader output is in homogeneous 4D space, the projection to w=1 plane is done by the rasterizer after culling, clipping and other steps.

Be aware though that while D3D and Vulkan use normalized device Z coordinate range [0, 1], OpenGL by default uses [-1, +1] (unless you use extensions to fix this). This affects how z from NDC is transformed to depth and defines how you should set up your projection matrix.


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.