UnderStand Perspective Rasterization, SV_POSITION(gl_FragCoord) to Pixel, SV mean Systems Value

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
}
}
}

 

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