Shader-自发光强度

梦想游戏人
目录:
Unity

可用于比如 汽车游戏刹车灯,红绿灯 变亮变暗等情景

对SurfaceOutput的Emission 属性Albedo 乘以系数

CS文件

  • public class NewBehaviourScript : MonoBehaviour {
  • public Material _m;
  • public float _intensity;
  • public Color _color;
  • // Use this for initialization
  • void Start () {
  • _m = GetComponent<Renderer>().material;
  • }
  • void Update()
  • {
  • _m.SetColor("_color", _color);
  • _m.SetFloat("_instensity", _intensity);
  • }
  • }
public class NewBehaviourScript : MonoBehaviour {


    public Material _m;
    public float _intensity;
    public Color _color;

	// Use this for initialization
	void Start () {
        _m = GetComponent<Renderer>().material;

      
	}
	
 void Update()
    {
        _m.SetColor("_color", _color);
        _m.SetFloat("_instensity", _intensity);

    }

   

}

表面着色器Shader文件

  • Shader "Custom/NewShader" {
  • Properties {
  • _MainTex ("Base (RGB)", 2D) = "white" {}
  • _color("color",Color)=(1,1,1)
  • _v("vector",vector)=(92,2,2,2)
  • _intensity("_intensity",Range(0,5))=0
  • }
  • SubShader {
  • Tags { "RenderType"="Opaque" }
  • LOD 200
  • CGPROGRAM
  • #pragma surface surf Lambert
  • sampler2D _MainTex;
  • float3 _color;
  • float4 _v;
  • float _intensity;
  • struct Input {
  • float2 uv_MainTex;
  • };
  • void surf (Input IN, inout SurfaceOutput o) {
  • half4 c = tex2D (_MainTex, IN.uv_MainTex);
  • // _intensity=0.5;
  • c.rgb=_color;
  • o.Albedo = c.rgb;
  • o.Emission=o.Albedo*_intensity;
  • }
  • ENDCG
  • }
  • FallBack "Diffuse"
  • }
Shader "Custom/NewShader" {
	Properties {
		_MainTex ("Base (RGB)", 2D) = "white" {}
        _color("color",Color)=(1,1,1)   
        _v("vector",vector)=(92,2,2,2) 
        
        _intensity("_intensity",Range(0,5))=0
	}
	SubShader {
		Tags { "RenderType"="Opaque" }
		LOD 200
		
		CGPROGRAM
		#pragma surface surf Lambert

		sampler2D _MainTex;
		float3 _color;
float4  _v;
float _intensity;

		struct Input {
			float2 uv_MainTex;
		};

		void surf (Input IN, inout SurfaceOutput o) {
			half4 c = tex2D (_MainTex, IN.uv_MainTex);
            
 //  _intensity=0.5;
        c.rgb=_color;
           	o.Albedo = c.rgb;
            o.Emission=o.Albedo*_intensity;
            
		}
		ENDCG
	} 
	FallBack "Diffuse"
}

效果:

Scroll Up