起因
因另一个TA同学问了一个问题
我抱着怀疑的心态,测试了一下
发现 varying 中的 sv_position 和 texcoord 的值再 fragment shader 阶段还真的不一样
而且 sv_position 还不是简单的 clipPos/clipPos.w
的操作
因此我自己做了一个试验:

结果还是不一样的

搜索发现
无意发现 [Unity]屏幕空间(视口)坐标(viewport coordinate)的几种计算方法对比分析 这篇文章中的:

也就说, clipPos to fragment shader 后的值是:x: [0~width], y: [0~height]
的
因此,fragment shader 中 clipPos.xy / _ScreenParams.xy = ScreenPos_Normalized
,也就是 x: [0~1], y: [0~1]
查看MSDN的 dx10 文档
查看了 dx10 的 语义 文档,发现有如下说明


OK,果然返回的是像素坐标,也就是说: SV_Position 在 fragment shader 使用时,就是 x : [0~width], y : [0~height]
最终 texcoord 和 sv_position 转为 0~1 的 normalized 坐标对比效果
shader 如下:

可以看到转换成了,一模一样