1 using System;
2 using UnityEngine;
3
4 namespace UnityStandardAssets.ImageEffects
5 {
6 [ExecuteInEditMode]
7 [RequireComponent (typeof(Camera))]
8 [AddComponentMenu ("Image Effects/Other/Screen Overlay")]
9 public class ScreenOverlay : PostEffectsBase
10 {
11 public enum OverlayBlendMode
12 {
13 Additive = 0,
14 ScreenBlend = 1,
15 Multiply = 2,
16 Overlay = 3,
17 AlphaBlend = 4,
18 }
19
20 public OverlayBlendMode blendMode = OverlayBlendMode.Overlay;
21 public float intensity = 1.0f;
22 public Texture2D texture = null;
23
24 public Shader overlayShader = null;
25 private Material overlayMaterial = null;
26
27
28 public override bool CheckResources ()
29 {
30 CheckSupport (false);
31
32 overlayMaterial = CheckShaderAndCreateMaterial (overlayShader, overlayMaterial);
33
34 if (!isSupported)
35 ReportAutoDisable ();
36 return isSupported;
37 }
38
39 void OnRenderImage (RenderTexture source, RenderTexture destination)
40 {
41 if (CheckResources() == false)
42 {
43 Graphics.Blit (source, destination);
44 return;
45 }
46
47 Vector4 UV_Transform = new Vector4(1, 0, 0, 1);
48
49 #if UNITY_WP8
50 // WP8 has no OS support for rotating screen with device orientation,
51 // so we do those transformations ourselves.
52 if (Screen.orientation == ScreenOrientation.LandscapeLeft) {
53 UV_Transform = new Vector4(0, -1, 1, 0);
54 }
55 if (Screen.orientation == ScreenOrientation.LandscapeRight) {
56 UV_Transform = new Vector4(0, 1, -1, 0);
57 }
58 if (Screen.orientation == ScreenOrientation.PortraitUpsideDown) {
59 UV_Transform = new Vector4(-1, 0, 0, -1);
60 }
61 #endif
62
63 overlayMaterial.SetVector("_UV_Transform", UV_Transform);
64 overlayMaterial.SetFloat ("_Intensity", intensity);
65 overlayMaterial.SetTexture ("_Overlay", texture);
66 Graphics.Blit (source, destination, overlayMaterial, (int) blendMode);
67 }
68 }
69 }