1
\$\begingroup\$

I'm working with Direct3D 11 and HLSL. I use four different shaders (vertex, hull, domain and pixel).

I always have troubles using the right coordinate space in my shaders. Could somebody identify the appropriate space for the vertex, hull, domain and pixel shader stages?

\$\endgroup\$
  • 1
    \$\begingroup\$ I'm confused what is a hull and domain shader? The fragment shader gets called after the rasterization process and the vertex shader get called before the rasterization process and converts the verts from world space to screen space. I assume hull and domain shaders are geometry shaders? In that case they occure after the vert shader and are used to manipulate geometry (tessellation, ect...). Vertex and Geometric shaders work with the 3d coordinates of the verts and any changes in coordinate systems must be applied manually. \$\endgroup\$ – ClassicThunder Jul 25 '13 at 16:58
  • \$\begingroup\$ hull and domain shader are 2 new stages in directx11, yes geometry shaders. the hull shader comes after vertex shader and bevor tesselator (fixed function) and the domain shader comes after the tesselator and bevor pixel shader. thx \$\endgroup\$ – Jinxi Jul 25 '13 at 17:23
7
\$\begingroup\$
  • The vertex shader takes input data from vertex buffers (which are typically in model space), transforms that input, and produces output data in clip space. After the vertex shader stage, the perspective divide (by the output w coordinate) occurs.

  • The pixel shader deals with fragments, not vertices, but when you do make use of coordinates (via SV_Position for example), those coordinates are in screen space (offset by 0.5). This means they range from zero to one.

  • The hull and domain shaders operate on input data and produce output data within the same space. Because the input data is generally in model space, the output data is also in model space.

That said, these are just canonical defaults. Since you are controlling the input data and the interpretation of that input data, you can place that data in any coordinate frame that is useful to you. For example, when faking 2D graphics in a 3D API it can be useful to simply place pixel coordinate input data into vertex buffers and have a very simple, almost no-op vertex shader.

There are some aspects of the pipeline outside your programmable control though. For example, SV_Position will always be offset screen space. The biggest thing to worry about it actually the output of the vertex shader stage. The rest of the pipeline will assume that output is in clip space, perform clipping, and perform the perspective division by w. Consequently you may need to set w accordingly (often to 1.0) if you want to "avoid" this division.

\$\endgroup\$
  • 2
    \$\begingroup\$ Small addition to Josh Petrie's point: the domain shader would generally output the homogenous coordinates as well. It helps to think of the domain shader as a vertex shader for the points that the tessellation pipeline outputs. More info: msdn.microsoft.com/en-us/library/windows/desktop/… \$\endgroup\$ – Jovan Jul 25 '13 at 17:04
  • \$\begingroup\$ So World-View-Projection Matrix is used to move vertex into clip space? Is clip space the same as view/camera/eye space? So I have to transform the cameraPosition from world space to view space if I'd like to get a proper LOD in hull shader? \$\endgroup\$ – Jinxi Jul 25 '13 at 17:19
  • \$\begingroup\$ Clip space is not the same as view space. The order (generally) is: model, world, view, clip. Clip is "after" view, after application of the projection transform. \$\endgroup\$ – Josh Jul 25 '13 at 17:22
  • \$\begingroup\$ clip space = screen space = projection space? The terminology is quite confusing. \$\endgroup\$ – Jinxi Jul 25 '13 at 17:39
  • 2
    \$\begingroup\$ Clip space is not screen space, either. After clip space you have the perspective divide, and then transformation to normalized device coordinates (NDC space), then screen space. Occasionally NDC space and screen space are conflated. After that is pixel or window space. \$\endgroup\$ – Josh Jul 25 '13 at 17:41

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.