Search Unity

hi everyone,I have a problem with shader.

Discussion in 'Shaders' started by zengfanxing, Jul 3, 2015.

  1. zengfanxing

    zengfanxing

    Joined:
    Jul 1, 2015
    Posts:
    2
    Shader "Custom/Facula"
    {
    Properties
    {
    _MainTex ("Texture", 2D) = "white" {} //main texture
    _MainPower ("Texture Power", Range(1.0,3.0)) = 1.6 //facula power
    _MainAlpha ("Main Alpha", Range(0.0,1.0)) = 1 //contorl transparency
    _TextureFac ("Texture Facula (Alpha)", 2D) = "white" {} //alpha texture,influence facula
    _RimColor ("Rim Color", Color) = (1,0,0,0) //rim color
    _RimPower ("Rim Power", Range(0.1,5.0)) = 0.1 //rim power
    _FaculaColor ("Facula Color", Color) = (1,1,1,0) //facula color
    _FaculaPower ("Facula Power", Range(0.0,2.0)) = 0.4 //facula power
    }
    SubShader
    {
    Tags {"Queue" = "Transparent"}
    LOD 250
    ZWrite Off
    ZTest Always
    CGPROGRAM
    #include "UnityCG.cginc"
    #pragma surface surf Lambert alpha:fade interpolateview noshadow nofog noforwardadd exclude_path:deferred
    struct Input
    {
    float2 uv_MainTex;
    float2 uv2_TextureFac;
    float3 viewDir;
    //float4 screenPos;
    //float3 worldRefl;
    };
    sampler2D _MainTex;
    float _MainPower;
    float _MainAlpha;
    sampler2D _TextureFac;
    float4 _RimColor;
    float _RimPower;
    float4 _FaculaColor;
    float _FaculaPower;

    void surf (Input IN, inout SurfaceOutput o)
    {
    o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb*_MainPower; //main color
    fixed alpha=tex2D(_TextureFac,IN.uv2_TextureFac).a; //sampler alpha texture
    o.Emission = _FaculaColor*_FaculaPower*alpha; //if alpha not equal to zero,so emission facula
    fixed dotValue=dot (normalize(IN.viewDir), o.Normal);
    if(dotValue<=0.3) //control rim width
    {
    half rim = 1.0 - saturate(dotValue);
    o.Emission = _RimColor.rgb * pow (rim, _RimPower); //rim color
    }
    o.Alpha=_MainAlpha; //control model alpha
    }
    ENDCG
    }
    Fallback "Diffuse"
    }

    this shader,how alter can let facula always face to camera.
    all help and advise will be very thanks.