1. 程式人生 > >Unity 不受光照影響shader 仿Unlit/Texture

Unity 不受光照影響shader 仿Unlit/Texture

Unity 不受光照影響 shader ,類似 Unlit/Texture” shader

一:

Shader "Custom/MyShader" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)//Tint Color
	_MainTex ("Base (RGB)", 2D) = "white" {}
}

SubShader {
	Tags {  "RenderType"="Opaque" }
	LOD 100

	Pass {
	    cull front
		Lighting Off
		SetTexture [_MainTex] { combine texture } 
		SetTexture [_MainTex]
		{
			ConstantColor [_Color]
			Combine Previous * Constant
		}
	}
}
}

下面是我用surf shader 實現的

二 :
Shader "Custom/SurfTexture" {
	Properties {
		_Color ("Main Color", Color) = (1,1,1,1)
		_MainTex ("Base (RGB)", 2D) = "white" {}
		
	}
	SubShader {
		Tags { "RenderType"="Opaque" }
		LOD 200
		
		CGPROGRAM
		#pragma surface surf myLightModel  

		//命名規則:Lighting接#pragma suface之後起的名字 
  		//lightDir :點到光源的單位向量   viewDir:點到攝像機的單位向量   atten:衰減係數 
  		float4 LightingmyLightModel(SurfaceOutput s, float3 lightDir,half3 viewDir, half atten) 
  		{ 
  		 	float4 c ; 
  		 	c.rgb =  s.Albedo;
  			c.a = s.Alpha; 
    		        return c; 
  		}

		sampler2D _MainTex;
                float4 _Color;
        
		struct Input {
			float2 uv_MainTex;
			float4 _Color;
		};

		void surf (Input IN, inout SurfaceOutput o) {
			half4 c = tex2D (_MainTex, IN.uv_MainTex)*_Color;
			o.Albedo = c.rgb;
			o.Alpha = c.a;
		}
		ENDCG
	} 
	FallBack "Diffuse"
}

相關連結:http://ykxingquan.blog.163.com/blog/static/13428052013052420979/