/// <summary> /// Activate the black and white filter for a given player. /// Important: parameters about duration are set in the shader-initialization. /// </summary> /// <param name="playerId">Id of the player to apply the shader</param> public void ActivateBlackAndWhite(int playerId) { PostProcessingEffect ppEffect = _fixEffects[PostprocessingType.BlackAndWhite]; ppEffect.Activate(playerId, true); ppEffect.SetParameterForPlayer(playerId, "startTime", Time.CurrentTime); }
/// <summary> /// Activate the shockwave filter for a given player. /// Important: parameters about duration are set in the shader-initialization. /// </summary> /// <param name="position">3D-space coordinate of the position for the shockwave</param> /// <param name="animationLength">Length of the animation for the shockwave to go over the whole screen</param> /// <param name="deactivate">Deactivate the shader after <paramref name="deactivateAfter"/></param> /// <param name="deactivateAfter">If <paramref name="deactivate"/> is set to true, after this many seconds the effect is disabled for this player-id.</param> public void ActivateShockWave(Vector3 position, float animationLength = 0.6f, bool deactivate = true, float deactivateAfter = 5.0f) { PostProcessingEffect ppEffect = new PostProcessingEffect(PostprocessingType.ShockWave, false, _loadedEffects[PostprocessingType.ShockWave], position); for (int playerId = 0; playerId < GameManager.NumPlayers; ++playerId) { Vector2 screenPosition = Screen.Cameras[playerId].WorldToScreenPoint01(position); ppEffect.Activate(playerId, true); ppEffect.SetParameterForPlayer(playerId, "startTime", Time.CurrentTime); ppEffect.SetParameterForPlayer(playerId, "centerCoord", screenPosition); ppEffect.SetParameterForPlayer(playerId, "animationLength", animationLength); ppEffect.SetParameter("shockParams", new Vector3(10.0f, 0.8f, 0.1f)); } _effects.Add(ppEffect); if (deactivate) { // ReSharper disable once ObjectCreationAsStatement new Timer(deactivateAfter, () => DectivateShader(ppEffect.Id)); } }
private PostProcessingManager(List <PostprocessingType> initialized) { foreach (PostprocessingType pType in Enum.GetValues(typeof(PostprocessingType))) { string fileName = pType.ToString(); _loadedEffects[pType] = File.Load <Effect>("Other/effects/" + fileName); } foreach (PostprocessingType pType in initialized) { PostProcessingEffect ppEffect = new PostProcessingEffect(pType, false, _loadedEffects[pType]); _fixEffects[pType] = ppEffect; ppEffect.SetParameter("players", GameManager.NumPlayers); // Special parameters for some effects switch (pType) { case PostprocessingType.BlackAndWhite: ppEffect.SetParameter("durationFadeIn", 0.1f); ppEffect.SetParameter("durationFadeOut", 1.9f); ppEffect.SetParameter("max", 1.0f); ppEffect.SetParameter("min", 0.1f); break; case PostprocessingType.GaussianBlur: ppEffect.SetParameter("screenSize", new Vector2(Screen.Width, Screen.Height)); break; case PostprocessingType.TwoPassBlur: ppEffect.SetParameter("screenSize", new Vector2(Screen.Width, Screen.Height)); break; case PostprocessingType.DepthOfField: float nearClip = Camera.Near; float farClip = Camera.FarDepth; farClip = farClip / (farClip - nearClip); ppEffect.SetParameter("Distance", Distance); ppEffect.SetParameter("Range", Range); ppEffect.SetParameter("Near", nearClip); ppEffect.SetParameter("Far", farClip); PostProcessingEffect ppBlur = new PostProcessingEffect(PostprocessingType.TwoPassBlur, false, _loadedEffects[PostprocessingType.TwoPassBlur]); ppBlur.SetParameter("players", GameManager.NumPlayers); ppBlur.SetParameter("screenSize", new Vector2(Screen.Width, Screen.Height)); ppBlur.SetParameter("active", new Vector4(1, 1, 1, 1)); for (var i = 0; i < GameManager.NumPlayers; i++) { ppEffect.Activate(i, true); ppBlur.Activate(i, true); } _twoPassEffect = ppBlur; break; case PostprocessingType.Chromatic: for (var i = 0; i < GameManager.NumPlayers; i++) { ppEffect.Activate(i, true); } break; case PostprocessingType.Vignette: for (var i = 0; i < GameManager.NumPlayers; i++) { ppEffect.Activate(i, true); } break; case PostprocessingType.ColorGrading: ppEffect.SetParameter("Size", 16f); ppEffect.SetParameter("SizeRoot", 4f); ppEffect.SetParameter("LUT", File.Load <Texture2D>("Images/lut/lut")); for (var i = 0; i < GameManager.NumPlayers; i++) { ppEffect.Activate(i, true); } break; case PostprocessingType.ShockWave: ppEffect.SetParameter("centerCoord", new Vector2(0.5f, 0.5f)); ppEffect.SetParameter("shockParams", new Vector3(10.0f, 0.8f, 0.1f)); break; case PostprocessingType.Wave: ppEffect.SetParameter("centerCoord", new Vector2(0.5f, 0.5f)); ppEffect.SetParameter("shockParams", new Vector3(10.0f, 0.8f, 0.1f)); break; } _effects.Add(ppEffect); } }