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/archive/2012/09/21/2697072.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值