RGB Color Swap and Grayscale Shader (Unity Engine)
Page 1 of 1
RGB Color Swap and Grayscale Shader (Unity Engine)
Color swap shader
replaces white with color 1, red with color 2, green with color 3, and blue with color 4.
Grayscale shader
was easy to write but i did it for fun. takes in an texture and grayscale it.
- Code:
Shader "Custom/ColorSwap" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_Color1 ("Base Color", Color) = (1,1,1,1)
_Color2 ("Color2", Color) = (1,1,1,1)
_Color3 ("Color3", Color) = (1,1,1,1)
_Color4 ("Color4", Color) = (1,1,1,1)
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
float4 _Color1,_Color2,_Color3,_Color4;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
if (c.r >= .1 && c.g >= .1 && c.b >= .1) c = _Color1;
else if (c.r >= .1) c = _Color2;
else if (c.g >= .1) c = _Color3;
else if (c.b >= .1) c = _Color4;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
}
replaces white with color 1, red with color 2, green with color 3, and blue with color 4.
Grayscale shader
was easy to write but i did it for fun. takes in an texture and grayscale it.
- Code:
Shader "Custom/Grayscale" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
half4 f = c;
f.r = (c.r + c.g + c.b) / 3;
f.g = f.r;
f.b = f.r;
c = f;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
InfinitasImpetum- (0%)-Lv8
- Posts : 2162
Join date : 2012-05-30
Age : 34
Similar topics
» Ogre Mesh and Skeleton XML Loader (Unity Engine)
» Unity Experiments
» Unity Voxel Experiments
» my Engine tools
» Winz2DS Engine DEV thread
» Unity Experiments
» Unity Voxel Experiments
» my Engine tools
» Winz2DS Engine DEV thread
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum