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: alt text

2 Answers

2

Ok, since you ment post-processing, I tried to change the greyscale post-processing shader and it worked pretty fine.

Here’s the shader:
[1410-GrayscaleEffect.txt|1410]

Just change the extension to .shader

Here’s the script:

[1411-GrayscaleEffect.txt|1411]

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 :wink:

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 :wink:

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"

}

I think it isn't that hard to create it from this shader.