注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Faye Euler's blog

技術交流歡迎留言

 
 
 

日志

 
 

Unity 3D 3dnDBS_Baked Shaders  

2012-05-28 13:15:50|  分类: Unity3D |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

3dnDBS_Baked is a mobile shader that bakes diffuse, bump and specular properties to produce fake surface detail.

Unity 3D 3dnDBS_Baked Shaders - Faye - Faye Eulers blog

 

Shader "3dnDBS_baked"
{
 Properties
 {
_MainColor("Main Color", Color) = (1,1,1,1)
_MainTex("Color Texture", 2D) = "black" {}
_BumpTexture("Bump Texture", 2D) = "black" {}
_SpecularTex("Specular Texture", 2D) = "black" {}
_SpecAmount("Specular Amount", Range(0,1) ) = 0.5

 }
 
 SubShader
 {
  Tags
  {
"Queue"="Geometry"
"IgnoreProjector"="False"
"RenderType"="Opaque"

  }

  
Cull Back
ZWrite On
ZTest LEqual
ColorMask RGBA
Fog{
}


  CGPROGRAM
#pragma surface surf BlinnPhongEditor  fullforwardshadows vertex:vert
#pragma target 2.0


float4 _MainColor;
sampler2D _MainTex;
sampler2D _BumpTexture;
sampler2D _SpecularTex;
float _SpecAmount;

   struct EditorSurfaceOutput {
    half3 Albedo;
    half3 Normal;
    half3 Emission;
    half3 Gloss;
    half Specular;
    half Alpha;
    half4 Custom;
   };
   
   inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
   {
half3 spec = light.a * s.Gloss;
half4 c;
c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
c.a = s.Alpha;
return c;

   }

   inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
   {
    half3 h = normalize (lightDir + viewDir);
    
    half diff = max (0, dot ( lightDir, s.Normal ));
    
    float nh = max (0, dot (s.Normal, h));
    float spec = pow (nh, s.Specular*128.0);
    
    half4 res;
    res.rgb = _LightColor0.rgb * diff;
    res.w = spec * Luminance (_LightColor0.rgb);
    res *= atten * 2.0;

    return LightingBlinnPhongEditor_PrePass( s, res );
   }
   
   struct Input {
    float2 uv_SpecularTex;
float2 uv_BumpTexture;
float2 uv_MainTex;

   };

   void vert (inout appdata_full v, out Input o) {
float4 VertexOutputMaster0_0_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_1_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_2_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_3_NoInput = float4(0,0,0,0);


   }
   

   void surf (Input IN, inout EditorSurfaceOutput o) {
    o.Normal = float3(0.0,0.0,1.0);
    o.Alpha = 1.0;
    o.Albedo = 0.0;
    o.Emission = 0.0;
    o.Gloss = 0.0;
    o.Specular = 0.0;
    o.Custom = 0.0;
    
float4 Tex2D2=tex2D(_SpecularTex,(IN.uv_SpecularTex.xyxy).xy);
float4 Multiply2=Tex2D2 * _SpecAmount.xxxx;
float4 Tex2D1=tex2D(_BumpTexture,(IN.uv_BumpTexture.xyxy).xy);
float4 Tex2D0=tex2D(_MainTex,(IN.uv_MainTex.xyxy).xy);
float4 Multiply0=Tex2D1 * Tex2D0;
float4 Add0=Multiply2 + Multiply0;
float4 Multiply1=_MainColor * Add0;
float4 Master0_1_NoInput = float4(0,0,1,1);
float4 Master0_2_NoInput = float4(0,0,0,0);
float4 Master0_3_NoInput = float4(0,0,0,0);
float4 Master0_4_NoInput = float4(0,0,0,0);
float4 Master0_5_NoInput = float4(1,1,1,1);
float4 Master0_7_NoInput = float4(0,0,0,0);
float4 Master0_6_NoInput = float4(1,1,1,1);
o.Albedo = Multiply1;

    o.Normal = normalize(o.Normal);
   }
  ENDCG
 }
 Fallback "Diffuse"
}

  评论这张
 
阅读(1094)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017