something about the SV_POSITION

SV is short for Systems Value;

This means that they have a specific meaning to the pipeline. In the case of SV_Position, if it's attached to a vertex shader output that means that the output will contain he final transformed vertex position used for rasterization. Or if you use it for a pixel shader input, it will contain the screenspace position of the pixel. All of these SV semantics are described in the SDK documentation, in the HLSL section. Just search for "semantics". 

The vertex shader outputs vertex positions in clip space using homogenous coordinates. Usually this clip-space position is calculated in the vertex shader by transforming the incoming object-space position by a combined world * view * projection matrix. Afterwards during rasterization the perspective divide-by-w is performed on the clip-space positition, after which the position is in coordinate space you are referring to (where -1 is the bottom left of the viewport and +1 is the top right). After this you have the viewport transform, which basically flips Y, converts from [-1, 1] to [0, 1], and multiplies by the size of the viewport. At this point you have the pixel position that gets passed as SV_Position to the pixel shader, which is of the range [0, ViewportSize] where (0, 0) is the top left and [ViewportWidth, ViewportHeight] is the bottom right. 

SV_Position in the pixel shader gives you the the center point of the pixel being shaded, in a [0, bufferWidth] x [0, bufferHeight] range. (It can also be used in centroid mode with MSAA to get the centroid of the covered samples.) This value can be passed directly to Texture2D.Load to retrieve the corresponding pixel from a texture the same size as the screen. So it may not be necessary to pass screen-space UVs in an interpolator, for things like the G-buffer in deferred shading.

For reconstructing the world space position you would still need to load from the depth buffer, convert it to linear depth and combine that with the screen-space position. SV_Position wouldn't really help you with that part. (FYI, you don't need to do a full matrix multiply in the pixel shader, though; you can do most of the math in the vertex shader and reduce the pixel shader part to linear depth * an interpolated vector + camera position.)

其实目前我的理解是这个sv_position也就是个dx10版的position,只不过它可以很方便的把vs输出的信息直接拿到ps里面。

 

原文地址:https://www.cnblogs.com/RenderLife/p/2697072.html