Shader "My/URP_Unlit" { Properties { _MainTex ("Texture", 2D) = "white" {} } SubShader { Tags { "RenderPipeline" = "UniversalPipeline" //这是用于URP的shader "RenderType" = "Opaque" } HLSLINCLUDE #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" //所有属性都要缓存到CBuffer中, 这样才能兼容SRP Batcher CBUFFER_START(UnityPerMaterial) float4 _MainTex_ST; CBUFFER_END ENDHLSL Pass { Tags { "LightMode" = "UniversalForward" } //渲染pass HLSLPROGRAM #pragma vertex vert //指定顶点着色器函数 #pragma fragment frag //指定片元着色器函数 struct Attributes { //程序传入顶点着色器的数据 float4 vertex : POSITION; //用模型空间顶点坐标填充该变量 float2 uv : TEXCOORD0; //用模型的第一套纹理坐标(uv)填充该变量 }; struct Varings { //顶点着色器传入片元着色器的数据 float2 uv : TEXCOORD0; float4 vertex : SV_POSITION; //该变量存放了裁剪空间的顶点坐标 }; //变量 TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex); Varings vert(Attributes v) { //顶点着色器 Varings o; VertexPositionInputs positionInputs = GetVertexPositionInputs(v.vertex.xyz); //顶点坐标从模型空间转裁剪空间 o.vertex = positionInputs.positionCS; o.uv = TRANSFORM_TEX(v.uv, _MainTex); //应用贴图的tiling和offset return o; } float4 frag(Varings i) : SV_Target { //片元着色器(逐像素) float4 c = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv); //根据纹理坐标获取像素颜色 return c; } ENDHLSL } } }
参考
【Unity Shader】在URP里写Shader(二):从一个Unlit Shader开始 - 知乎
标签:MainTex,uv,shader,unlit,URP,float4,顶点,着色器 From: https://www.cnblogs.com/sailJs/p/18604954