码迷,mamicode.com
首页 > 其他好文 > 详细

UnderStand Perspective Rasterization, SV_POSITION to Pixel, SV mean Systems Value

时间:2016-07-07 19:49:24      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

Shader "UnderStandPRR"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
 
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
 
#include "UnityCG.cginc"
 
struct appdata
{
float4 vertex : POSITION;
};
 
struct v2f
{
float4 vertex : SV_POSITION;
};
 
sampler2D _MainTex;
float4 _MainTex_ST;
 
v2f vert (appdata v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
return o;
}
 
fixed4 frag (v2f i) : SV_Target
{
// i.vertex.xy are pixel coordinates 
// i.vertex.z is depth value 
// i.vertex.w is SV_POSITION w - z value (Perspective interpolation)
return  fixed4(i.vertex.x * (_ScreenParams.z - 1), i.vertex.y * (_ScreenParams.w - 1), i.vertex.z, i.vertex.w);
}
ENDCG
}
}
}

 技术分享

 

UnderStand Perspective Rasterization, SV_POSITION to Pixel, SV mean Systems Value

标签:

原文地址:http://www.cnblogs.com/bearworks/p/5651190.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!