其他分享
首页 > 其他分享> > unity meta pass

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

标签:res,uv1,uv,pos,unity,meta,V2F,pass
来源: https://www.cnblogs.com/nafio/p/14315093.html