| // This shader draws a texture?on?the mesh. Shader?"Example/URPUnlitShaderTexture" { ????// The _BaseMap variable is visible in the Material's Inspector,?as a field ????// called Base Map. ????Properties ????{ ????????_BaseMap("Base Map",?2D) =?"white" ????} ????SubShader ????{ ????????Tags?{?"RenderType"?=?"Opaque"?"RenderPipeline"?=?"UniversalPipeline"?} ????????Pass ????????{ ????????????HLSLPROGRAM ????????????#pragma vertex vert ????????????#pragma fragment frag ????????????#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"??????????? ????????????struct Attributes ????????????{ ????????????????float4 positionOS???:?POSITION; ????????????????// The uv variable contains the UV coordinate?on?the texture for the ????????????????// given vertex. ????????????????float2 uv???????????:?TEXCOORD0; ????????????}; ????????????struct Varyings ????????????{ ????????????????float4 positionHCS??:?SV_POSITION; ????????????????// The uv variable contains the UV coordinate?on?the texture for the ????????????????// given vertex. ????????????????float2 uv???????????:?TEXCOORD0; ????????????}; ????????????// This macro declares _BaseMap as a Texture2D object. ????????????TEXTURE2D(_BaseMap); ????????????// This macro declares the sampler for the _BaseMap texture. ????????????SAMPLER(sampler_BaseMap); ????????????CBUFFER_START(UnityPerMaterial) ????????????????// The following line declares the _BaseMap_ST variable,?so that you ????????????????// can use the _BaseMap variable in the fragment shader. The _ST ????????????????// suffix is necessary for the tiling and offset function to work. ????????????????float4 _BaseMap_ST; ????????????CBUFFER_END ????????????Varyings vert(Attributes IN) ????????????{ ????????????????Varyings OUT; ????????????????OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz); ????????????????// The TRANSFORM_TEX macro performs the tiling and offset ????????????????// transformation. ????????????????OUT.uv = TRANSFORM_TEX(IN.uv,?_BaseMap); ????????????????return OUT; ????????????} ????????????half4 frag(Varyings IN)?:?SV_Target ????????????{ ????????????????// The SAMPLE_TEXTURE2D marco samples the texture with the given ????????????????// sampler. ????????????????half4 color = SAMPLE_TEXTURE2D(_BaseMap,?sampler_BaseMap,?IN.uv); ????????????????return color; ????????????} ????????????ENDHLSL ????????} ????} } |