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 coder to 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);
}
}
Shaders are a dark art to my poor muggle mind, and the answer to my question is likely something extremely simple that I’m just missing. The code itself is about 98% recycled from a tutorial.
The code works fine in the Unity editor, both in normal and emulated graphics mode. However, once I build and test it on an Android device (tested on an HTC One M9 and a Google Nexus 6P), there just is no flash. Can someone point me in the right direction with this? My Google-fu was of no help.