UnityShader学习实践(hsv转rbg)
2016-04-21 09:22
393 查看
Shader "Custom/RGBtoHSV" {
Properties
{
_H("hue",Range(0,360))=0.1
_S("saturation",Range(0,1.0))=0
_V("value",Range(0, 1.0)) = 0
_A("Alpha", Range(0,1.0))=1.0
}
SubShader
{
Tags { "Queue"="Transparent" "RenderType"="Transparent" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
uniform fixed _H;
uniform fixed _S;
uniform fixed _V;
uniform fixed _A;
fixed4 HSVtoRGB()
{
fixed R;
fixed G;
fixed B;
if (_S == 0)
{
R = G = B = _V;
}
else
{
_H /= 60;
fixed i = (int)_H;
fixed f = _H-i;
fixed a = _V*(1 - _S);
fixed b = _V*(1 - f*_S);
fixed c = _V*(1 - (1 - f)*_S);
if (i == 0)
{
R = _V; G = c; B = a;
}
else if (i == 1)
{
R = b; G = _V; B = a;
}
else if (i == 2)
{
R = a; G = _V; B = c;
}
else if (i == 3)
{
R = a; G = b; B = _V;
}
else if (i == 4)
{
R = c; G = a; B = _V;
}
else if (i == 5)
{
R = _V; G = a; B = b;
}
}
return fixed4(R, G, B,_A);
}
float4 vert(float4 v:POSITION) : SV_POSITION
{
return mul(UNITY_MATRIX_MVP, v);
}
fixed4 frag() : COLOR
{
return HSVtoRGB();
}
ENDCG
}
}
FallBack "Diffuse"
}
Shader "Custom/RGBtoHSV" {
Properties
{
_H("hue",Range(0,360))=0.1
_S("saturation",Range(0,1.0))=0
_V("value",Range(0, 1.0)) = 0
_A("Alpha", Range(0,1.0))=1.0
}
SubShader
{
Tags { "Queue"="Transparent" "RenderType"="Transparent" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
uniform fixed _H;
uniform fixed _S;
uniform fixed _V;
uniform fixed _A;
fixed4 HSVtoRGB()
{
fixed R;
fixed G;
fixed B;
if (_S == 0)
{
R = G = B = _V;
}
else
{
_H /= 60;
fixed i = (int)_H;
fixed f = _H-i;
fixed a = _V*(1 - _S);
fixed b = _V*(1 - f*_S);
fixed c = _V*(1 - (1 - f)*_S);
if (i == 0)
{
R = _V; G = c; B = a;
}
else if (i == 1)
{
R = b; G = _V; B = a;
}
else if (i == 2)
{
R = a; G = _V; B = c;
}
else if (i == 3)
{
R = a; G = b; B = _V;
}
else if (i == 4)
{
R = c; G = a; B = _V;
}
else if (i == 5)
{
R = _V; G = a; B = b;
}
}
return fixed4(R, G, B,_A);
}
float4 vert(float4 v:POSITION) : SV_POSITION
{
return mul(UNITY_MATRIX_MVP, v);
}
fixed4 frag() : COLOR
{
return HSVtoRGB();
}
ENDCG
}
}
FallBack "Diffuse"
}
Properties
{
_H("hue",Range(0,360))=0.1
_S("saturation",Range(0,1.0))=0
_V("value",Range(0, 1.0)) = 0
_A("Alpha", Range(0,1.0))=1.0
}
SubShader
{
Tags { "Queue"="Transparent" "RenderType"="Transparent" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
uniform fixed _H;
uniform fixed _S;
uniform fixed _V;
uniform fixed _A;
fixed4 HSVtoRGB()
{
fixed R;
fixed G;
fixed B;
if (_S == 0)
{
R = G = B = _V;
}
else
{
_H /= 60;
fixed i = (int)_H;
fixed f = _H-i;
fixed a = _V*(1 - _S);
fixed b = _V*(1 - f*_S);
fixed c = _V*(1 - (1 - f)*_S);
if (i == 0)
{
R = _V; G = c; B = a;
}
else if (i == 1)
{
R = b; G = _V; B = a;
}
else if (i == 2)
{
R = a; G = _V; B = c;
}
else if (i == 3)
{
R = a; G = b; B = _V;
}
else if (i == 4)
{
R = c; G = a; B = _V;
}
else if (i == 5)
{
R = _V; G = a; B = b;
}
}
return fixed4(R, G, B,_A);
}
float4 vert(float4 v:POSITION) : SV_POSITION
{
return mul(UNITY_MATRIX_MVP, v);
}
fixed4 frag() : COLOR
{
return HSVtoRGB();
}
ENDCG
}
}
FallBack "Diffuse"
}
Shader "Custom/RGBtoHSV" {
Properties
{
_H("hue",Range(0,360))=0.1
_S("saturation",Range(0,1.0))=0
_V("value",Range(0, 1.0)) = 0
_A("Alpha", Range(0,1.0))=1.0
}
SubShader
{
Tags { "Queue"="Transparent" "RenderType"="Transparent" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
uniform fixed _H;
uniform fixed _S;
uniform fixed _V;
uniform fixed _A;
fixed4 HSVtoRGB()
{
fixed R;
fixed G;
fixed B;
if (_S == 0)
{
R = G = B = _V;
}
else
{
_H /= 60;
fixed i = (int)_H;
fixed f = _H-i;
fixed a = _V*(1 - _S);
fixed b = _V*(1 - f*_S);
fixed c = _V*(1 - (1 - f)*_S);
if (i == 0)
{
R = _V; G = c; B = a;
}
else if (i == 1)
{
R = b; G = _V; B = a;
}
else if (i == 2)
{
R = a; G = _V; B = c;
}
else if (i == 3)
{
R = a; G = b; B = _V;
}
else if (i == 4)
{
R = c; G = a; B = _V;
}
else if (i == 5)
{
R = _V; G = a; B = b;
}
}
return fixed4(R, G, B,_A);
}
float4 vert(float4 v:POSITION) : SV_POSITION
{
return mul(UNITY_MATRIX_MVP, v);
}
fixed4 frag() : COLOR
{
return HSVtoRGB();
}
ENDCG
}
}
FallBack "Diffuse"
}
相关文章推荐
- Unity IOC注入详细配置(MVC,WebApi)
- 第一篇文章 用来测试
- UnityTestTools测试工具
- Unity学习笔记一 - Survival Shooter Tutorial
- 【Unity】7.6 自定义输入
- 【Unity】7.5 移动设备输入
- 【Unity】7.4 游戏外设输入
- 【Unity】7.3 键盘输入
- 【Unity】7.2 鼠标输入
- 【Unity】7.1 Input类的方法和变量
- 【Unity】第7章 输入控制
- Unity Shaders and Effects Cookbook (4-1)(4-2)静态立方体贴图的创建与使用
- [Unity通信]快速接入sdk
- Unity之数据持久化(PlayerPrefs)
- unity 集成 RenderDoc 调试shader的方法
- Unity3d-编辑器-PrefabUtility.CreateEmptyPrefab PrefabUtility.CreatePrefab失败
- 2D游戏获得子节点的最小最大位置
- 【Unity】5.2 天空盒
- 【Unity】5.1 3D坐标系基础知识
- 【Unity】第5章 3D坐标系和天空盒