- Home /
Fade A Whole Scene From Black & White to Colour
For anyone whos played the New Call of Duty, Modern Warfare 2, this will be very fimilar, I would like to fade a whole scene from black & white to colour and I do not have a clue where to start, Can anyone help me achive this?
Answer by duck · Jan 06, 2010 at 10:11 PM
This can be done by following these steps. First, you'll need Unity Pro, because modifying the scene with a full screen image effect is a Pro-only feature.
Now, Unity Pro comes with a fullscreen Greyscale image effect, but it's all-or-nothing, you can't fade it in or out, you can only switch it on or off. So what I'm going to do is give you the instructions to tweak these files to add fading functionality to it. Specifically, I will add a variable which controls the fade amount, which you can then modify yourself at runtime. Here's what you have to do:
Make sure the Pro Standard Assets are imported into your project. You'll be editing a couple of files in here, but these are only copies of your Pro Standard Assets - if you start another project and include Pro Standard Assets, you'll get the original unmodified versions again.
In your project view, look in the "Pro Standard Assets / Image Based" folder. Inside are two files named "Grayscale Effect". One is a C# script, and one is a .shader file. Open the .shader file to edit the source (it's the one with the "S" icon).
Add this line inside the "Properties" section (at line 5):
_EffectAmount ("Effect Amount", Range (0,1)) = 1.0
Add this line under the "uniform" declarations (at line 22):
uniform float _EffectAmount;
Modify the 'return' line to look like this (which is now at line 31):
return lerp(original, output, _EffectAmount);
Now save and close GreyscaleEffect.shader, and open the other "GreyscaleEffect" file, which is a C# file called "GreyscaleEffect.cs"
Under the Public variable declarations, add this line (at line 8):
public float effectAmount = 1;
Just before the 'Graphics.Blit' line, add this line (at line 13):
material.SetFloat("_EffectAmount", effectAmount);
You now have an extra variable in the Greyscale script which you can modify to control the fading. You can modify this value either in the animation editor, or via another script.
Just add this image effect script to your camera, then create a reference to the GreyscaleEffect script instance at runtime. You can then modify the "effectAmount" variable anywhere from 0.0 to 1.0 to fade the effect in and out. Note: there's no error checking for whether that value goes beyond 1.0, or lower than 0.0 so you'll have to manage that yourself (weird colourful effects ensue if you don't!).
Thankyou SO $$anonymous$$UCH! very detailed response AWESO$$anonymous$$E!
Got a question though, Don't supose you could tell me how to fade the "effectAmount" variable, over time, on Runtime (assu$$anonymous$$g that does mean when I run the game).
Cheeky of me to ask but you obviously have a very clear idea of what your doing! :D
@duck: Thanks a lot for this solution. It works perfectly.
@Caiuse: what you need to do is to interpolate the new effectAmount
variable from 0 to 1 to fade from colour to grayscale and 1 to 0 for vice versa. Take a look at $$anonymous$$athf.Lerp
Is this still a pro-only feature in Unity 5?