Shader Optimization

¼ÎÀÌ´õ ÃÖÀûÈ­¸¦ À§ÇÑ ÆÁ¿¡ ´ëÇؼ­ ¾Ë¾Æ º¸ÀÚ

approxview :
ºä ¹æÇâÀ» »ç¿ëÇÏ´Â ½¦ÀÌ´õ(i.e. Specular)¿¡ ÀÖ¾î, °¢ Çȼ¿¸¶´Ù°¡ ¾Æ´Ñ Á¤Á¡¸¶´Ù ºä ¹æÇâÀ» Á¤±ÔÈ­ÇÕ´Ï´Ù. ´ë·«ÀûÀÎ °ªÀÌÁö¸¸, º¸Åë ÀÌ°ÍÀ¸·Î ÃæºÐÇÕ´Ï´Ù.

halfasview :
Specular ½¦ÀÌ´õ À¯ÇüÀ» ´õ ºü¸£°Ô ÇÕ´Ï´Ù. Half-vector (¶óÀÌÆà ¹æÇâ°ú ºä º¤ÅÍÀÇ Áß°£)ÀÌ °è»êµÇ¾î Á¤Á¡¸¶´Ù Ç¥ÁØÈ­ µÈ, lighting function(¶óÀÌÆà ÇÔ¼ö)Àº ¹Ì¸® Áß°£ º¤Å͸¦ ºä º¤ÅÍ ´ë½Å Àμö·Î ¹Þ½À´Ï´Ù.

noforwardadd :
Forward Rendering¿¡¼­ ÁöÇ⼺ ¶óÀÌÆ®¸¸ ¿Ïº®ÇÏ°Ô Áö¿øÇÕ´Ï´Ù. ³ª¸ÓÁö ¶óÀÌÆ®´Â, Á¤Á¡ ¶óÀÌÆ®¿Í ¿Í ±¸¸é Á¶È­(spherical harmonics) È¿°ú¸¦ °è¼Ó Ç¥ÇöÇÒ ¼ö ÀÖ½À´Ï´Ù. ÀÌ°ÍÀº ½¦ÀÌ´õ¸¦ ÀÛ°Ô ¸¸µé¸ç, ¿©·¯ ¶óÀÌÆ®°¡ Á¸ÀçÇÏ°í À־ Ç×»ó ÇϳªÀÇ Æнº·Î ·»´õ¸µµË´Ï´Ù.

noambient :
½¦ÀÌ´õÀÇ ambient ¶óÀÌÆà ¹× ±¸¸é Á¶È­¸¦ ¹«È¿È­ÇÕ´Ï´Ù. ÀÌ¿¡ µû¶ó ¾à°£ »¡¶óÁý´Ï´Ù.


Shader "Custom/VertSinTest"
{
    SubShader
      {         
        Tags { "RenderType" = "Opaque" }
        CGPROGRAM
 
        #pragma surface surf MobileBlinnPhong exclude_path:prepass nolightmap noforwardadd halfasview
        
        struct Input {
            float4 color : COLOR;
        };
        
        inline fixed4 LightingMobileBlinnPhong (SurfaceOutput s, fixed3 lightDir, fixed3 halfDir, fixed atten)
        {
            fixed diff = max(0, dot(s.Normal, lightDir));
            fixed nh = max(0, dot(s.Normal, halfDir));
            fixed spec = pow(nh, s.Specular * 128) * s.Gloss;
            
            fixed4 c;
            c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec) * (atten *2);
            c.a = 0.0f;
            return c;
        }
        
        void surf (Input IN, inout SurfaceOutput o)
        {
            o.Albedo = 1;
        }
        
        ENDCG
       }
      Fallback "Diffuse"
}

"À¯´ÏƼ Shader¿Í Effect Á¦ÀÛ"¿¡ ÀÖ´Â ¿¹Á¦



Shader "Custom/MobileShader"
{
    Properties
    {
        _Diffuse ("Base (RGB) Specular Amount (A)", 2D) = "white" {}
        _SpecIntensity ("Specular Width", Range(0.01, 1)) = 0.5
        _NormalMap ("Normal Map", 2D) = "bump"{}
    }
    
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200
        
        CGPROGRAM
        #pragma surface surf MobileBlinnPhong exclude_path:prepass nolightmap noforwardadd halfasview

        sampler2D _Diffuse;
        sampler2D _NormalMap;
        fixed _SpecIntensity;

        struct Input
        {
            half2 uv_Diffuse;
        };
        
        inline fixed4 LightingMobileBlinnPhong (SurfaceOutput s, fixed3 lightDir, fixed3 halfDir, fixed atten)
        {
            fixed diff = max (0, dot (s.Normal, lightDir));
            fixed nh = max (0, dot (s.Normal, halfDir));
            fixed spec = pow (nh, s.Specular*128) * s.Gloss;
            
            fixed4 c;
            c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec) * (atten*2);
            c.a = 0.0;
            return c;
        }

        void surf (Input IN, inout SurfaceOutput o)
        {
            fixed4 diffuseTex = tex2D (_Diffuse, IN.uv_Diffuse);
            o.Albedo = diffuseTex.rgb;
            o.Gloss = diffuseTex.a;
            o.Alpha = 0.0;
            o.Specular = _SpecIntensity;
            o.Normal = UnpackNormal(tex2D(_NormalMap, IN.uv_Diffuse));
        }
        ENDCG
    }
    FallBack "Diffuse"
}

Âü°í)
http://docs.unity3d.com/kr/current/Manual/SL-ShaderPerformance.html