I've recently started learning how to write shaders and how to apply them to a camera i tried to use a few of my custom shaders on android but they just returned a black screen or flickering black/white screen with a few pixel being the other shade, or rarely a random colour even the default invert preset does it i can only think of the tex2d function not returning the colour of the screen pixel or _mainTex not being set to the rendered image of the camera (it wouldnt explain the rare random coloured pixels tho) this is one of my custom shaders thats acting weird on android for example Code (CSharp): Shader "Camera/circleInvert" { Properties { _MainTex ("Texture", 2D) = "white" {} _speed ("Circle Speed", float) = 1 _size ("Circle Size", float) = 1 } SubShader { // No culling or depth Cull Off ZWrite Off ZTest Always Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float2 uv : TEXCOORD0; float4 vertex : SV_POSITION; }; v2f vert (appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = v.uv; return o; } sampler2D _MainTex; float _size; float _speed; fixed4 frag (v2f i) : SV_Target { float2 uvMid = i.uv - 0.5; float dist = sqrt(uvMid.x * uvMid.x + uvMid.y * uvMid.y); float timing = ( sign( sin(_Time[1] * _speed+dist * _size)) + 1)/2.; i.uv.y = timing * i.uv.y + (1-timing) * (1-i.uv.y); fixed4 col = tex2D(_MainTex, i.uv); col.rgb = timing * col.rgb + (1-timing)*(1-col.rgb); return col; } ENDCG } } } does anyone know why it wont work on android?
Try commenting out everything in your frag function and leave just lines 54 and 56. If this doesn't work, then there's indeed some problem outside of the shader.
this just returns a black screen as said in my question, even the default template (which is just colour inversion) returns a flashing screen with random pixel not being inverted and some rare pixels even having a random color if needed i can upload screenshots of the different expectations and outcomes tried with unity versions 2019.3.0 and 2019.1.6
ive not known of logcat yet but this is the error: (the shader is still the above with only get colour and return)
i have a monobehavior class in which i use graphic.blit in onRenderImage code(it works normaly in editor and windows builds): Code (CSharp): [ExecuteInEditMode] public class CameraMaterials : MonoBehaviour { [SerializeField] List<Material> materials = new List<Material>(); private void OnRenderImage(RenderTexture source, RenderTexture destination) { foreach(Material shader in materials) { Graphics.Blit(source, source, shader); } Graphics.Blit(source, destination); } }
The problem is caused by using the same render texture as a source and destination for blit Graphics.Blit(source, source, shader);