Unity 为队伍设置不同颜色的shader





Shader "Custom/TeamMaskRgb" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_From("From Color",Color) = (1,1,1,1)
_To("To Color",Color) = (1,1,1,1)
_RgbRange("Rgb Range",Range(0,1))=0.1
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 150 CGPROGRAM
#pragma surface surf Lambert noforwardadd sampler2D _MainTex;
fixed4 _From;
fixed4 _To;
fixed _RgbRange; struct Input {
float2 uv_MainTex;
} ; void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
// 老师傅们都说不要用if,所以就改成step了!
fixed con = step(abs(_From.r-c.r),_RgbRange);
con = con + step(abs(_From.g-c.g),_RgbRange);
con = con + step(abs(_From.b-c.b),_RgbRange);
con = step(3,con); o.Albedo = lerp(c.rgb,c.rgb+_To-_From,con);
o.Alpha = c.a;
}
ENDCG
} Fallback "Mobile/VertexLit"
}


.png)

Shader "Custom/TeamMaskRgbEx1" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_From ("From Color", Color) = (1,1,1,1)
_To ("To Color", Color) = (1,1,1,1)
_Range ("Range", Range (0.0, 2.0)) = 0.01
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 150 CGPROGRAM
#pragma surface surf Lambert noforwardadd sampler2D _MainTex;
fixed4 _From;
fixed4 _To;
half _Range; struct Input {
float2 uv_MainTex;
} ; void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
fixed colorDistance = (c.r - _From.r)*(c.r - _From.r) + (c.g - _From.g)*(c.g - _From.g) + (c.b - _From.b)*(c.b - _From.b);
o.Albedo = lerp(c.rgb,(_To.rgb - _From.rgb + c.rgb),
saturate(1 - colorDistance / (_Range * _Range)));
o.Alpha = c.a;
}
ENDCG
} Fallback "Mobile/VertexLit"
}

.png)


Shader "Custom/TeamMaskHue" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_From("From Color",Color) = (1,1,1,1)
_To("To Color",Color) = (1,1,1,1)
_FaultTolerant("hue fault-tolerant",range(0,359)) = 2
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200 CGPROGRAM
#pragma surface surf Standard fullforwardshadows sampler2D _MainTex; struct Input {
float2 uv_MainTex;
} ; fixed4 _Color;
fixed4 _From;
fixed4 _To;
float _FaultTolerant; float getHue(float3 col) {
float r=col.r,g=col.g,b=col.b;
float _max = max(r,max(g,b));
float _min = min(r,min(g,b));
float _gradient = _max - _min;
float ret = 0;
if(_max == r) {
ret = (g-b)/_gradient;
} else if(_max == g) {
ret = 2 + (b-r)/_gradient;
} else if(_max == b) {
ret = 4 + (r-g)/_gradient;
} ret = ret*60.0; if(ret<0) {
ret = ret + 360;
}
return ret;
} void surf (Input IN, inout SurfaceOutputStandard o) {
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
float hc = getHue(c.rgb);
float hFrom = getHue(_From.rgb);
float differ = abs(hc-hFrom);
differ = lerp(differ,abs(differ-360),step(180,differ));
o.Albedo = lerp(c.rgb,c.rgb - _From.rgb + _To.rgb,
step(differ,_FaultTolerant));
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}


.png)
.png)

Shader "Custom/TeamMaskFinal" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_From("From Color",Color) = (1,1,1,1)
_To("To Color",Color) = (1,1,1,1)
_HError("Hue Error",range(0,1)) = 0 // 允许的色相误差
_SError("Saturation Error",range(0,1)) = 0 // 允许的饱和度误差
_VError("Brightness Error",range(0,1)) = 0 // 允许的亮度误差
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 150 CGPROGRAM
#pragma surface surf Lambert noforwardadd sampler2D _MainTex;
fixed4 _From;
fixed4 _To;
fixed _HError;
fixed _SError;
fixed _VError; struct Input {
float2 uv_MainTex;
} ; fixed3 RGBtoHSV(fixed3 c)
{
fixed4 K = fixed4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
fixed4 p = lerp(fixed4(c.bg, K.wz), fixed4(c.gb, K.xy), step(c.b, c.g));
fixed4 q = lerp(fixed4(p.xyw, c.r), fixed4(c.r, p.yzx), step(p.x, c.r)); float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return fixed3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
} fixed3 HSVtoRGB(fixed3 c)
{
fixed4 K = fixed4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
fixed3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * lerp(K.xxx, saturate(p - K.xxx), c.y);
} void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
fixed3 cHSV = RGBtoHSV(c);
fixed3 FromHSV= RGBtoHSV(_From);
fixed3 ToHSV= RGBtoHSV(_To); fixed diffHue = abs(cHSV.x-FromHSV.x);
diffHue = lerp(diffHue,abs(diffHue-1),step(0.5,diffHue)); fixed con = step(diffHue,_HError);
con = con + step(abs(cHSV.y-FromHSV.y),_SError);
con = con + step(abs(cHSV.z-FromHSV.z),_VError);
con = step(2.5,con);
fixed3 ret = cHSV + ToHSV - FromHSV;
// ret.x = lerp(ret.x,ret.x-1,step(1,ret.x));
// ret.x = lerp(ret.x,ret.x+1,step(ret.x,0)); o.Albedo = lerp(c.rgb,HSVtoRGB(ret),fixed3(con,con,con)); o.Alpha = c.a;
}
ENDCG
} Fallback "Mobile/VertexLit"
}


Unity 为队伍设置不同颜色的shader的更多相关文章
- highcharts设置Y轴范围及根据Y轴范围设置不同颜色
yAxis : { title : { text : '数据' }, plotLines : [ { value : 0, width : 1, color : '#808080' } ], min: ...
- echarts如何给柱形图的每个柱子设置不同颜色
总结下这几日用echarts库作基本图形遇到的一些问题. echarts快速上手可参考官网: http://echarts.baidu.com/tutorial.html#5%20%E5%88%86% ...
- 关于Unity中的模型描边与Shader切换(专题二)
模型描边 1: LOL里面的模型描边效果,点击防御塔会有描边的效果,被攻击的时候模型也要描边凸显一下2: 网上可以找到模型描边的Shader,可以直接下载使用,一组第三方的Shader, 帮我们解决了 ...
- unity灯光烘焙设置详解
游戏场景中灯光照明的构成 现实生活中的光线是有反射.折射.衍射等特性的.对这些基本特性的模拟一直以来都是计算机图形图像学的重要研究方向. 在CG中,默认的照明方式都是不考虑这些光线特性的,因此出来的效 ...
- Unity 阴影淡入淡出效果中Shader常量 unity_ShadowFadeCenterAndType和_LightShadowData的问题
由于Universal Render Pipeline目前(2020年4月1日)把阴影淡入淡出这个功能竟然给取消了…我自己拿片元位置到相机位置的距离进行了一个淡化,但是阴影边缘老是被裁切…后来研究了一 ...
- Unity目录结构设置
摄像机 Main Camera 跟随主角移动,不看 UI 剧情摄像机 当进入剧情时,可以关闭 main camera,启用剧情摄像机,不看 UI UI 摄像机 看 UI Unity编辑器常用的sett ...
- 【Unity原神AR开发实战 2022】下载原神模型,PMX转FBX,导入到Unity,AR设置,测试应用程序,生成应用程序
文章目录 一.前言 二.模型下载 1.官网下载 2.模之屋官方下载 3.第三方链接 三.pmx转fbx 1.Blender插件CATS的下载与安装 2.pmx模型的导入 四.Unity开发部分 1.V ...
- 贴图在Unity中的设置
例如:一张512X512的图片占用的内存大小,计算方法:512*512*4/1024=1.024MB. 如果在贴图设置里设置成真彩色那就等于计算的值,设置成16位色彩,内存占用会减少. 在进行性能优化 ...
- Unity QualitySettings.SetQualityLevel 设置质量级别
QualitySettings.SetQualityLevel 设置质量级别 public static void QualitySettings.SetQualityLevel(int index) ...
随机推荐
- MySQL监控全部执行过的sql语句
MySQL监控全部执行过的sql语句 查看是否开启日志记录show variables like “general_log%” ; +——————+———-+|Variable_name|Value| ...
- 20、MySQLdb
MySQLdb win64位安装python-mysqldb1.2.5 ubuntu下安装MySQLdb sudo apt-get install python-MySQLdb 导入MySQLdb库 ...
- Docker国内镜像source
现在使用docker的镜像大多基于几种基本Linux系统.虽然我不需要在容器李安装很多东西,但经常需要一些必要的工具,而基础镜像里并不包含,比如vim, ifconfig, curl等.考虑下载速度, ...
- 【问题与解决】showModalDialog is not defined 的解决方案
背景: showModalDialog 是比较老的方法了,有些浏览器不再支持弹出模态窗口了. 比如说谷歌浏览就不再支持了,有文章说明如下: Chrome’s Lack of Support for s ...
- 【C++】C++中的字符和字符串
目录结构: contents structure [-] 定义和初始化string string对象上的操作 处理string对象中的字符 C风格字符串 标准库类型string表示可变长的字符序列,使 ...
- NBU将RAC数据库恢复到单机
恢复的过程和(https://www.cnblogs.com/abclife/p/5687993.html)差不多.但是,具体过程有些不同.如果按照之前的恢复方式,在run语句中同时运行restore ...
- Mathmatica简介
作者:桂. 时间:2018-06-27 21:53:34 链接:https://www.cnblogs.com/xingshansi/p/9236502.html 前言 打算系统学习一些数学知识,容 ...
- [svc]容器网络学习索引及网络监控
整理的可能有些误失,抽时间在细细的分类完善下. 发现这篇对于网络从低到高层协议整理的还不错 每层都有一些有意思的话题 一些协议有一些设计上的弱点, 所以产生了种种的网络层安全问题 一般我们学一些 1, ...
- 什么是面向切面编程AOP--知识点汇总
最近在学这方面的内容,读到的这段话我感觉说的很清楚了:这种在运行时,动态地将代码切入到类的指定方法.指定位置上的编程思想就是面向切面的编程. 面向切面编程(AOP是Aspect Orie ...
- 【javascript】九宫格抽奖组件设计
一些主要点 1. 转圈的顺序(顺时针或者逆时针): 2. 转圈的速率(从慢到快再到慢): 3. 位置的问题(下一次抽奖的起始位置是上一次抽奖的结束位置): 4. 转圈的圈数或者移动的次数. 基本原理 ...