unity meta pass

简单说就是在meta pass计算

albedo,emission,specular

3个值

光照烘焙,gi计算间接光照时都会用到这些值

 

Shader "MyShader/SampleLightmap"
{
	SubShader
	{
		Pass
		{
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#pragma multi_compile _ LIGHTMAP_ON
			#include"Lighting.cginc"

			struct VertexData
			{
				float4 pos:POSITION;
				float2 uv:TEXCOORD0;
				float2 uv1:TEXCOORD1;
			};

			struct V2F
			{
				float4 pos:SV_POSITION;
				float2 uv:TEXCOORD0;
				#if defined(LIGHTMAP_ON)
					float2 uv1:TEXCOORD1;
				#endif
			};


			V2F vert(VertexData v)
			{
				V2F res;
				res.pos = UnityObjectToClipPos(v.pos);
				res.uv = v.uv;
				#if defined(LIGHTMAP_ON)
				res.uv1 = v.uv1 * unity_LightmapST.xy + unity_LightmapST.zw;
				#endif
				return res;
			}

			fixed4 frag(V2F i) :SV_TARGET
			{
				fixed4 col = fixed4(1,0,0,1);
				#if defined(LIGHTMAP_ON)
					col.rgb = DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.uv1));
				#endif
				return col;
			}
			ENDCG
		}


		Pass
		{
			Tags{ "LightMode" = "Meta" }

			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#include "UnityStandardInput.cginc"
			#include "UnityMetaPass.cginc"

	
			struct V2F
			{
				float4 pos:SV_POSITION;
				float4 uv:TEXCOORD0;
			};


			V2F vert(VertexInput v)
			{
				V2F o;
				o.pos = UnityMetaVertexPosition(v.vertex, v.uv1.xy, v.uv2.xy, unity_LightmapST, unity_DynamicLightmapST);
				o.uv = TexCoords(v);
				return o;
			}

			fixed4 frag(V2F i) :SV_TARGET
			{
				UnityMetaInput o;
				UNITY_INITIALIZE_OUTPUT(UnityMetaInput, o);
				o.Albedo = fixed3(1, 1, 0); //这里只是将漫反射添加到烘焙贴图中去
                    o.Emission = xxxx;
                    o.SpecularColor = xxxx;
return UnityMetaFragment(o); } ENDCG } } }

  

 

 

 

 

 

 

meta pass

https://blog.csdn.net/wodownload2/article/details/94554057

 

https://blog.csdn.net/cgy56191948/article/details/100766303

上一篇:Unity Shader 自制无光照的光晕效果


下一篇:Shader笔记——6.Shader动画