Search Unity

Android - Updating Sampler2D at runtime not working

Discussion in 'Shaders' started by FreeGameDev, Aug 16, 2017.

  1. FreeGameDev

    FreeGameDev

    Joined:
    Dec 1, 2015
    Posts:
    67
    I am trying to send video camera data to my shader at runtime. (Also, tried with just a plain video) Everything works great in the PC version but when I build to android all I get is a grey screen. Here is the code I have in the frag section. Any idea why this is not working on Android? Also did not work on WebGL.
    Code (CSharp):
    1.             float4 frag (v2f i) : SV_Target
    2.             {  
    3.                     float4 back    = tex2D(_BufferTexture, i.uv);
    4.                     float4 front = tex2D(_Buffer2Texture, i.uv);
    5.                     float4 change = (front - back);      
    6.                     return change;
    In the camera script I have
    Code (CSharp):
    1. void Update () {
    2.         if (Cam.didUpdateThisFrame)
    3.         {
    4.             Graphics.CopyTexture(Cam, _Buffer2Texture);
    5.             //I also update the BufferTexture but a frame back
    6.         }
    7.  
    8. }
    I only posted the relevant parts of the code.
    Thanks
     
  2. FreeGameDev

    FreeGameDev

    Joined:
    Dec 1, 2015
    Posts:
    67
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,339
  4. FreeGameDev

    FreeGameDev

    Joined:
    Dec 1, 2015
    Posts:
    67
    Yup that was the problem... Thanks bgolus.
    Is there any other way to do what I am trying without CopyTexture?
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,339
  6. FreeGameDev

    FreeGameDev

    Joined:
    Dec 1, 2015
    Posts:
    67
    Yeah I tried that too, I get the same results.
    I think it is more or less equivalent to Graphics.CopyTexture.