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 toTexture2D.Loadto 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里面。

优质内容筛选与推荐>>
1、linux 安装 jdk
2、Luogu P2447 [SDOI2010]外星千足虫 高斯消元
3、powershell加载EXE进内存运行
4、exports default 和export的使用方式
5、(十三)多窗口切换


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号