Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

CRT Shader Android Problem

Discussion in 'Shaders' started by antique, Aug 29, 2015.

  1. antique

    antique

    Joined:
    Mar 8, 2015
    Posts:
    5
    Hello, I'm testing camera effect from this tutorial http://www.gamasutra.com/blogs/SvyatoslavCherkasov/20140531/218753/Shader_tutorial_CRT_emulation.php. Everything works well on pc, but when I run this on android (OnePlusOne) there are only shades of red :(

    This is my shader code:

    Code (CSharp):
    1. Shader "Custom/RetroShader"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex("Base (RGB)", 2D) = "white" {}
    6.     }
    7.  
    8.         SubShader
    9.     {
    10.         Pass
    11.     {
    12.         ZTest Always Cull Off ZWrite Off Fog{ Mode off }
    13.  
    14.         CGPROGRAM
    15.  
    16. #pragma vertex vert
    17. #pragma fragment frag
    18. #pragma fragmentoption ARB_precision_hint_fastest
    19. #include "UnityCG.cginc"
    20. #pragma target 3.0
    21.  
    22.     struct v2f
    23.     {
    24.         float4 pos      : POSITION;
    25.         float2 uv       : TEXCOORD0;
    26.         float4 scr_pos : TEXCOORD1;
    27.     };
    28.  
    29.     uniform sampler2D _MainTex;
    30.  
    31.     v2f vert(appdata_img v)
    32.     {
    33.         v2f o;
    34.         o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    35.         o.uv = MultiplyUV(UNITY_MATRIX_TEXTURE0, v.texcoord);
    36.         o.scr_pos = ComputeScreenPos(o.pos);
    37.         return o;
    38.     }
    39.  
    40.     half4 frag(v2f i) : COLOR
    41.     {
    42.         half4 color = tex2D(_MainTex, i.uv);
    43.  
    44.         float2 ps = i.scr_pos.xy *_ScreenParams.xy / i.scr_pos.w;
    45.  
    46.         int pp = (int)(ps.x) % 3;
    47.         float4 outcolor = float4(0, 0, 0, 1);
    48.  
    49.         if (pp == 0) outcolor.r = color.r;
    50.         else if (pp == 1) outcolor.g = color.g;
    51.         else if (pp == 2) outcolor.b = color.b;
    52.        
    53.         return outcolor;
    54.     }
    55.  
    56.         ENDCG
    57.     }
    58.     }
    59.         FallBack "Diffuse"
    60. }
    61.  
     
  2. antique

    antique

    Joined:
    Mar 8, 2015
    Posts:
    5
    I tried to make another simple effect of scanlines every 2 pixels but it doesn't work on android either. This is my code:

    Code (CSharp):
    1. Shader "Custom/RetroShader"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex("Base (RGB)", 2D) = "white" {}
    6.     }
    7.  
    8.         SubShader
    9.     {
    10.         Pass
    11.     {
    12.         ZTest Always Cull Off ZWrite Off Fog{ Mode off }
    13.  
    14.         CGPROGRAM
    15.  
    16. #pragma vertex vert
    17. #pragma fragment frag
    18. //#pragma fragmentoption ARB_precision_hint_fastest
    19. #include "UnityCG.cginc"
    20. //#pragma target 3.0
    21.  
    22.     struct v2f
    23.     {
    24.         float4 pos      : POSITION;
    25.         float2 uv       : TEXCOORD0;
    26.         float4 scr_pos : TEXCOORD1;
    27.     };
    28.  
    29.     uniform sampler2D _MainTex;
    30.  
    31.     v2f vert(appdata_img v)
    32.     {
    33.         v2f o;
    34.         o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    35.         o.uv = MultiplyUV(UNITY_MATRIX_TEXTURE0, v.texcoord);
    36.         o.scr_pos = ComputeScreenPos(o.pos);
    37.         return o;
    38.     }
    39.  
    40.     half4 frag(v2f i) : COLOR
    41.     {
    42.         half4 color = tex2D(_MainTex, i.uv);
    43.  
    44.         float2 ps = i.scr_pos.xy *_ScreenParams.xy / i.scr_pos.w;
    45.  
    46.         int yPos = (int)(ps.y);
    47.  
    48.         if (((yPos / 2) & 1) == 0)
    49.         {
    50.             color *= 0.5f;
    51.         }
    52.  
    53.         return color;
    54.     }
    55.  
    56.         ENDCG
    57.     }
    58.     }
    59.         FallBack "Diffuse"
    60. }
    I completely don't know what's wrong :/ It works perfectly on pc.