• 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 /
This question was closed Mar 07, 2016 at 05:49 PM by Silverfell for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Silverfell · Mar 04, 2016 at 08:07 PM · shadersmobile devices

I have a fullscreen shader that makes the camera it's applied to flash white. It works fine in the editor, but not on mobile devices.

Here is the code for the shader itself:

 Shader "Hidden/WhiteFlash"
 {
     Properties{
         _MainTex("Base (RGB)", 2D) = "white" {}
     _flash("Flash intensity", Range(0, 1)) = 0
     }
         SubShader{
         Pass{
         CGPROGRAM
 #pragma vertex vert_img
 #pragma fragment frag
 
 #include "UnityCG.cginc"
 
             uniform sampler2D _MainTex;
         uniform float _flash;
 
         float4 frag(v2f_img i) : COLOR{
             float4 c = tex2D(_MainTex, i.uv);
 
             //float lum = c.r*.3 + c.g*.59 + c.b*.11;
 
             float3 fl = float3(1, 1, 1);
 
             float4 result = c;
             result.rgb = lerp(c.rgb, fl, _flash);
             return result;
         }
             ENDCG
         }
     }
 }
 

And here is the script that controls its values:

 public class WhiteFlash : MonoBehaviour
 {
 
     public float intensity;
     private Material material;
 
     // Creates a private material used to the effect
     void Awake()
     {
         material = new Material(Shader.Find("Hidden/WhiteFlash"));
     }
 
     // Postprocess the image
     void OnRenderImage(RenderTexture source, RenderTexture destination)
     {
         if (intensity == 0)
         {
             Graphics.Blit(source, destination);
             return;
         }
 
         material.SetFloat("_flash", intensity);
         Graphics.Blit(source, destination, material);
     }
 }


Please understand that shaders are black magic to me, and the answer to my question is likely something extremely simple I'm just missing. The code itself is about 98% recycled from a tutorial I found online.

The code works find in the Unity editor, in normal and emulated (OpenGL es 2.0) mode. However, come build time, the flashes just don't materialize. Can anyone point me in the right direction with this? My Google-fu was of no help.

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

  • Sort: 
avatar image
1
Best Answer

Answer by Jessespike · Mar 04, 2016 at 08:33 PM

Note that a shader might be not included into the player build if nothing references it! In that case, Shader.Find will work only in the editor, and will result in pink "missing shader" materials in the player build. Because of that, it is advisable to use shader references instead of finding them by name. To make sure a shader is included into the game build, do either of: 1) reference it from some of the materials used in your scene, 2) add it under "Always Included Shaders" list in ProjectSettings/Graphics or 3) put shader or something that references it (e.g. a Material) into a "Resources" folder.

Source: http://docs.unity3d.com/ScriptReference/Shader.Find.html

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 Silverfell · Mar 07, 2016 at 03:51 PM 0
Share

This was it! Thank you.

avatar image
0

Answer by Magius96 · Mar 07, 2016 at 04:06 PM

Its not a shader, but I'll provide an alternate method for ya. You're just trying to make the screen flash white, right? You could simply place a white texture just in front of the camera and set it inactive. Then to make it flash, set it active, then a frame or two later set it inactive again.

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 Silverfell · Mar 07, 2016 at 05:47 PM 0
Share

Thank you for your suggestion, but that's the method I've been using so far. Sadly, it causes massive overdraw even when the white texture is fully transparent. Excess overdraw is one of the reasons I turned to shaders.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

What can cause objects to not render on mobile? 1 Answer

Stencil buffer on mobile 0 Answers

Make shader outer glow wider 0 Answers

Apply a shader to multiple 2D sprites 2 Answers

How do i change the color of "Default_Particle"? 1 Answer


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