Unity Fresnel Hero(Dota2) Shader


Shader "HeroShader" {
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_RimColor ("Rim Color", Color) = (0.97,0.88,1,0.75)
_RimPower ("Rim Power", Float) = 2.5
_Fresnel ("Fresnel Value", Float) = 0.28
_MainTex ("Base (RGB)", 2D) = "white" {}
_BumpMap ("Bump (RGB)", 2D) = "bump" {}
_SpecularTex ("Specular Level (R) Gloss (G)", 2D) = "gray" {}
_RimTex ("Rim ramp (RGB) Fresnel ramp (A)", 2D) = " grey" {}
_WrapTex ("Wrap ramp (RGBA)", 2D) = "black" {}
_Cutoff ("Alpha cutoff", Range (0,1)) = 0.5
}
SubShader {
Tags { "RenderType" = "Opaque" }
AlphaTest Greater [_Cutoff]
Blend Off
Cull Off
CGPROGRAM
#pragma surface surf BumpSpecSkin
#include "UnityCG.cginc"
float4 _Color;
float _Shininess;
sampler2D _MainTex;
sampler2D _WrapTex;
sampler2D _RimTex;
sampler2D _BumpMap;
sampler2D _SpecularTex;
float4 _RimColor;
float _RimPower;
float _Fresnel;
inline float CalcFresnel(float3 viewDir, float3 h, float fresnelValue)
{
float fresnel = pow(1.0 - dot(viewDir, h), 5.0);
fresnel += fresnelValue * (1.0 - fresnel);
return fresnel;
}
half4 LightingBumpSpecSkin (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
{
float rimf = dot(s.Normal, viewDir);
half4 rim = tex2D (_RimTex, rimf.xx);
half3 h = normalize (lightDir + viewDir);
float fresnel = CalcFresnel ( viewDir, h, lerp ( 0.2, _Fresnel, s.Specular ) );
half diffusePos = dot(s.Normal, lightDir) * 0.5 + 0.5;
half4 diffuse = tex2D (_WrapTex, diffusePos.xx);
diffuse.rgb *= rim.rgb;
float nh = saturate( dot( h, s.Normal ) );
float spec = pow (nh, 128 * s.Gloss) * s.Specular * fresnel ;
half4 c;
c.rgb = ((s.Albedo + spec * rim.a) * (diffuse + diffusePos) + spec)* (atten * 2) * _LightColor0.rgb;
c.a = s.Alpha;
return c;
}
struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;
float3 viewDir;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 texcol = tex2D( _MainTex, IN.uv_MainTex);
o.Albedo = texcol.rgb * _Color.rgb;
o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
float3 specMap = tex2D(_SpecularTex, IN.uv_MainTex).rgb;
o.Specular = specMap.r;
o.Gloss = specMap.g;
half3 rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
o.Emission = _RimColor.rgb * pow(rim, _RimPower);
o.Alpha = texcol.a * _Color.a;
}
ENDCG
}
Fallback "VertexLit"
}
Unity Fresnel Hero(Dota2) Shader的更多相关文章
- Unity内置的shader include files
Unity内置的shader include files:这些文件都以.cninc结尾, HLSLSupport.cginc:自动包含,一些跨平台编译相关的宏和定义. UnityShaderVaria ...
- 【Unity Shaders】Mobile Shader Adjustment—— 什么是高效的Shader
本系列主要参考<Unity Shaders and Effects Cookbook>一书(感谢原书作者),同时会加上一点个人理解或拓展. 这里是本书所有的插图.这里是本书所需的代码和资源 ...
- unity 切圆角矩形 --shader编程
先上个效果图 制作思路 如上图我们要渲染的就是上图带颜色的部分 步骤: 先获取黄色和蓝绿部分 例如以下图 算法 |U|<(0.5-r)或|V|<(0.5-r) 注意的是模型贴图最大值是1. ...
- 【原创翻译】初识Unity中的Compute Shader
一直以来都想试着自己翻译一些东西,现在发现翻译真的很不容易,如果你直接把作者的原文按照英文的思维翻译过来,你会发现中国人读起来很是别扭,但是如果你想完全利用中国人的语言方式来翻译,又怕自己理解的不到位 ...
- Unity Shaders Vertex & Fragment Shader入门
http://blog.csdn.net/candycat1992/article/details/40212735 三个月以前,在一篇讲卡通风格的Shader的最后,我们说到在Surface Sha ...
- 【Unity Shaders】Mobile Shader Adjustment —— 为手机定制Shader
本系列主要參考<Unity Shaders and Effects Cookbook>一书(感谢原书作者),同一时候会加上一点个人理解或拓展. 这里是本书全部的插图.这里是本书所需的代码和 ...
- unity, 在image effect shader中用_CameraDepthTexture重建世界坐标
--------------更新 更简单的方法: //depth: raw depth, nonlinear, 0 at near plane, 1 at far plan float4 scre ...
- Unity 3D动态修改Shader状态,使物体透明等等
Unity动态改Shader状态透明 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- ...
- unity中使用自定义shader进行光照贴图烘培无法出现透明度的坑爹问题
最近开发中在对场景进行光照贴图烘焙时发现一个坑爹问题,在使用自定义shader的时候,shader命名中必须包含Transparent路径,否则烘焙的时候不对alpha通道进行计算,烘焙出来都是狗皮膏 ...
随机推荐
- VS2010无法打开CSS问题
安装了VS2010的SP1补丁后,发现打开css文件时出现下面问题: 一点击css文件就弹出:未能完成操作.未指定的错误.无法正常进入. [解决方法]安装最新Web Standards Update补 ...
- Cocos2d-x 学习资料收集
框架源代码: http://code.google.com/p/cocos2d-x/downloads/list 搭建环境 http://blog.csdn.net/ccf19881030/artic ...
- “jni.h”: No such file or directory
VS2010解决方案: 进入 “包含目录“ 方式: 右键项目属性页-> 配置属性->VC++目录->包含目录 在”包含目录“中编辑 添加以下路径: C:\Program Files\ ...
- Object To Enum
public static T ObjectToEnum<T>(object o) { try { return (T)Enum.Parse(typeof(T), o.ToString() ...
- 基于url拦截实现权限控制
用户表,角色表,用户角色表,权限表,权限角色表 1.用户通过认证(可以是验证用户名,密码等) 2.登陆拦截器,为公开的url放行, 登陆时,将用户信息放入session中,获得用户的权限集合,将集合放 ...
- Invalid segment BIN$xxx and dba_recyclebin was empty (回收站空,释放无效的BIN$xx空间)
近来有套库空间紧张,发现有很大BIN$开头的TABLE partition,index partition 类型的段,查询确认是2个月前删除的对象,手动清空过dba_recyclebin使用purge ...
- windows下安装wamp和wordpress
安装wamp WAMP是一个windows上的php开发集成环境,一键安装php,apache和mysql,非常方便. 双击wampserver2.2exxxxxxxxxx.exe文件进行安装,安装过 ...
- SQL反模式部分内容笔记
规范化: 1, 以一种我们能够理解的方式表达这个世界中的事物; 2, 减少数据冗余存储, 防止异常或者不一致的数据; 3, 支持完整性约束. Tips: 提高数据的性能不在此列表中. 意义: 规范化 ...
- 复选框字段数组拆分后循环选项值,if判断根据选项值,前端输出html
{php $specials = explode(',',$r[special]);} <div class="special"> {loop $specials $s ...
- 使用Express搭建服务器
Express是基于Node.js平台,快速.开放.极简的web开发框架.所以,使用Express之前,请确保已安装Node.js. 1.创建一个目录作为当前工作目录: $ mkdir myapp $ ...