【UnityShader】学习笔记 可编程渲染管线结构及语义

官网教程:https://docs.unity3d.com/Manual/SL-VertexProgramInputs.html

#pragma vertex vert       //定义顶点着色器的入口函数

#pragma fragment frag     //定义片段着色器的入口函数

v2f vert(appdata v)

v2f:顶点着色器的输出值,片段着色器的输入值

顶点着色器:

1.计算顶点位置

2.矩阵转换

片段着色器:

1.纹理寻址

2.灯光作用


CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			
			#include "UnityCG.cginc"

			struct appdata
			{
				float4 vertex : POSITION;  //获取模型顶点信息
				float2 uv : TEXCOORD0;     
			};

			struct v2f
			{
				float2 uv : TEXCOORD0;
				float4 vertex : SV_POSITION; //表示经过MVP矩阵转化到屏幕坐标位置
			};

			v2f vert (appdata v)
			{
				v2f o;
				o.vertex = UnityObjectToClipPos(v.vertex);
				o.uv = v.uv;
				return o;
			}
			
			sampler2D _MainTex;

			fixed4 frag (v2f i) : SV_Target//输出到的render target
			{
				fixed4 col = tex2D(_MainTex, i.uv);
				// just invert the colors
				col = 1 - col;
				return col;
			}
			ENDCG

  • POSITION is the vertex position, typically a float3 or float4.
  • NORMAL is the vertex normal, typically a float3.获取法线
  • TEXCOORD0 is the first UV coordinate, typically float2float3 or float4.高精度的从顶点传递信息到片段着色器
  • TEXCOORD1TEXCOORD2 and TEXCOORD3 are the 2nd, 3rd and 4th UV coordinates, respectively.
  • TANGENT is the tangent vector (used for normal mapping), typically a float4.获取切线信息
  • COLOR is the per-vertex color, typically a float4.低精度



你可能感兴趣的:(unity3d)