- Home /
Modifying Greyscale Shader for selective Colouring.
I would like to achieve a selective colouring effect where everything is coloured in greyscale besides the colour red, preferrably by editing the greyscale effect default unity pro shader. However i have no idea how to do such a thing, how would i go about it?
A reference example:
Answer by Tim-Michels · Jun 27, 2012 at 10:04 AM
Ok, since you ment post-processing, I tried to change the greyscale post-processing shader and it worked pretty fine.
Here's the shader: link text
Just change the extension to .shader
Here's the script:
Change the extension to .cs
I had to change the extensions in order to upload these files, so correct them. Put the first attachement (shader) inside Standard Assets / Image Effects (Pro Only) / _Sources / Shaders, and put the cs script in Standard Assets / Image Effects (Pro Only)
Altough the shader isn't optimized, this still deserves a thumbs up ;)
This appears to be quite what i was looking for! The greyscaled image might not be as dark as it was with the default greyscale shader but that is a $$anonymous$$or issue. $$anonymous$$uch appreciated.
Answer by Tim-Michels · Jun 25, 2012 at 10:32 AM
Here's the code for something I tried to get the effect you want. It's far from perfect, but I would really want you to try it out and let me know if its what you need.
When you create a material with this shader, you will have two sliders to tweak tresholds.
Cheers ;)
Shader
Shader "Custom/GreyRedScale" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_RedPower ("Red Power", Range(0.001,1.0)) = 1.0
_RedDelta ("Red Delta", Range(0.001,1.0)) = 1.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
float _RedPower;
float _RedDelta;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
half avg = c.r + c.g + c.b;
avg *= 0.333;
half4 nC = half4(avg,avg,avg,c.a);
half avg2 = c.g+c.b;
avg2 *= 0.5;
if(c.r > _RedPower && (c.r - avg2) > _RedDelta)
{
nC.rgb = half3(c.r,avg2,avg2);
}
o.Albedo = nC.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
This appears to be quite a lovely material shader. However i was talking about a Post-Proccessing effect shader.