首页 > 编程语言 > 详细

Unity Diffuse Metal Shader Mod

时间:2016-03-11 06:25:28      阅读:306      评论:0      收藏:0      [点我收藏+]

技术分享

 

技术分享

 

Shader "MetalShader"
{
Properties {
_MainTex ("Base (RGB) RefStrGloss (A)", 2D) = "white" {}
_SkyTex ("SkyCube", Cube) = "" {}
_BumpMap ("Normalmap", 2D) = "bump" {}
_Color ("Main Color", Color) = (1,1,1,1)
_FresnelColor ("Fresnel Color", Color) = (0.5,0.5,0.5,1)
_Specular ("Specular", Range (0, 10)) = 5
}
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf MetalSpecular

fixed4 _Color;
fixed4 _FresnelColor;
float _Specular;
sampler2D _MainTex;
sampler2D _BumpMap;
samplerCUBE _SkyTex;

half4 LightingMetalSpecular (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
{
half diff = max (0, dot (s.Normal, lightDir));
half fFresnel = saturate(dot(s.Normal, viewDir));

float3 vReflection = 2 * s.Normal * fFresnel - viewDir;
float4 envMap = texCUBE(_SkyTex, vReflection);
envMap.rgb *= s.Gloss * envMap.a * s.Specular;

float fFresnelSq = fFresnel * fFresnel;
float4 metalColor = fFresnel * _Color +
fFresnelSq * _FresnelColor +
fFresnelSq * fFresnelSq * (1- _FresnelColor);

float fEnvContribution = saturate(1.0 - 0.5 * fFresnel);

half4 c;
c.rgb = (envMap.rgb * fEnvContribution + metalColor * diff * _LightColor0.rgb) * atten;
c.a = s.Alpha;
return c;
}

struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;
};

void surf (Input IN, inout SurfaceOutput o)
{
fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = tex.rgb;
o.Gloss = tex.a;
o.Specular = _Specular;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
o.Alpha = 1;
}
ENDCG
}
Fallback Off
}

Unity Diffuse Metal Shader Mod

原文:http://www.cnblogs.com/bearworks/p/5264166.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!