Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by awplays49 · Mar 06, 2015 at 01:56 PM · unity 5flashfadeoutfadeinflashing

How to make blinding and flashing effects with lerp?

For example, in Five Nights at Freddy's 3, you can hallucinate and after hallucinations your vision starts blacking out, then the black fades, then comes back. How can I do something like this?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by illogicalcrow · Mar 06, 2015 at 05:56 PM

A lot of those effects are done with post processing shaders (which are now available free to everyone). If you haven't used shaders these are pretty easy to get. The Unity Manual has a great image effects reference ans sample set here and I adapted this tutorial to make a sample for you.

In total you will need a controller script, blackout shader, and material to hold the shader. The controller script will attach to the camera and use a float ("rate") to set shader properties of the assigned material.

 using UnityEngine;
 using System.Collections;
 
 public class Blackout : MonoBehaviour 
 {
     public Material mat;
     
     [Range(0f,1f)]
     public float rate = 1f; //0 is black, 1 is original color
     
     void Update()
     {
         mat.SetFloat("_Rate", rate);
     }
     
     void OnRenderImage(RenderTexture source, RenderTexture destination)
     {
         Graphics.Blit (source, destination, mat);
     }
 }

All of the good stuff happens in the fragment shader. In this case all we really want to do is adjust the original pixel color by a percentage rate where 0 = full black and 1 = original lit color.

 Shader "Custom/Blackout" 
 {
     Properties {
         _MainTex ("", 2D) = "white" {}
         _Rate("Amt original color", Range(0.0,1.0)) = 1.0
     }
      
     SubShader {
      
         ZTest Always Cull Off ZWrite Off Fog { Mode Off }
      
             Pass{
                 CGPROGRAM
                 #pragma vertex vert
                 #pragma fragment frag
                 #include "UnityCG.cginc"
                 
                 uniform sampler2D _MainTex;
                 uniform float _Rate;
                 
                 struct v2f 
                 {
                     float4 pos : POSITION;
                     half2 uv : TEXCOORD0;
                 };
                 
                 //Vertex Shader
                 v2f vert (appdata_img v)
                 {
                     v2f o;
                     o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
                     o.uv = MultiplyUV (UNITY_MATRIX_TEXTURE0, v.texcoord.xy);
                     return o;
                 }
                 
                 //Fragment Shader
                 fixed4 frag (v2f i) : COLOR
                 {
                     fixed4 orgCol = tex2D(_MainTex, i.uv);
                     fixed4 col = orgCol * _Rate;
                     return col;
                 }
                 
                 ENDCG
             }
     }
     
     FallBack "Diffuse"
 }

With this done pop into the editor and create a new material. Assign the blackout shader to it and assign the material to script on the camera. When you run the scene you should be able to use the "Rate" slider to interactively adjust the darkness on the screen. From here you could easily make an automatic blackout using time (`rate = Mathf.Sin (Time.time);`), but you'll probably want to push it further ;)

I would recommend looking into related shaders such as the sepia effect, color inversion, color channel adjustment, and texture multiply/overlay which are all simple effects that extend off of this. Leaving this open rather than attaching files so people can easily see/make suggestions as I am a newbie at shaders.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image awplays49 · Mar 07, 2015 at 12:54 AM 0
Share

Thank you :D

avatar image
1
Wiki

Answer by Prosto_Lyubo · Mar 07, 2015 at 01:49 AM

If You want something simpler just add proper Image to Your canvas so it overlays screen) and then manipulate it with:

  MyImage.CrossFadeColor(NewColor, fadeDuration, false);
  MyImage.CrossFadeAlpha(NewAlpha, fadeDuration, false);

You can use it to add bloody-screen effect or many others by just mixing textures. This have big advantage: You call it once and don't have to worry to lerp between values in every frame.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make object gradually fade from left to right,Make object gradually disappear from left to right. 0 Answers

Smoothly Fade in a texture 1 Answer

Sprite smooth fade out/in 2 Answers

Fade In / Out UI Image 3 Answers

why my static timer variable print 0 everytime i call the getcolor function?! 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges