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) ...
随机推荐
- C# ExecutionContext 实现
网上关于ExecutionContext的说明比较少,我们来看看微软的描述吧, 名称 说明 Capture() 捕获从当前线程的执行上下文. CreateCopy() 创建当前执行上下文的副本. ...
- opencv+python-图片文本倾斜校正
# -*- coding: UTF-8 -*- import numpy as np import cv2 ## 图片旋转 def rotate_bound(image, angle): #获取宽高 ...
- Print all attributes and values in a Javascript Object
function printObject(o) { var out = ''; for (var p in o) { out += '\n' + ':: ' + p + '(' + typeof(o[ ...
- 使用Deeplearning4j进行GPU训练时,出错的解决方法
一.问题 使用deeplearning4j进行GPU训练时,可能会出现java.lang.UnsatisfiedLinkError: no jnicudnn in java.library.path错 ...
- 【Python】 解析Python中的运算符
Python中的运算符相比较于传统的C/C++差别不是很大,主要是一些个别的运算符上的差别.包括:算术.比较.赋值.位.逻辑.成员.身份等.它们的优先级: 符号 说明 ** 指数(最高优先级) ~,+ ...
- Form 组件的学习
学习链接:http://www.cnblogs.com/haiyan123/p/7778888.html Form组件可以做的几件事情: 1.用户请求数据验证 2.自动生成错误信息 3.打包用户提交的 ...
- jquery裁剪图片插件cropit示例
重装农药第16天!! jquery裁剪图片插件cropit示例 背景:做的手机网页项目,用html file控件上传图片,有些手机拍照后图片会很大,20M以上的,用之前的H5 formdata上传的话 ...
- atitit r9 doc on home ntpc .docx
卷 p2soft 的文件夹 PATH 列表 卷序列号为 9AD0-D3C8 D:. │ Aittit pato 面对拒绝 的回应.docx │ Atitit 中国明星数量统计 attilax. ...
- redis跳跃表
最近在阅读redis设计与实现,关于redis数据结构zset的一种底层实现跳跃表一直没有太理解,所以在搜了一下资料,终于搞懂了它的设计思路,记录一下. 参考链接:https://mp.weixin. ...
- odoo jQuery is not defined
The steps1.Query your db as this query.select id, create_date, store_fname, datas_fname from ir_atta ...