Search Unity

UI Over RenderTexture

Discussion in 'Shaders' started by kneave, Jul 21, 2016.

  1. kneave

    kneave

    Joined:
    Aug 14, 2014
    Posts:
    17
    Howdo,

    I'm just getting started with Compute Shaders and I've implemented Conway's Game of Life on a compute shader, I'm gobsmacked by the improvement in performance! I'm hitting what is likely a rookie error though.

    I've started to tidy it up by adding a UI to show the current times to render on CPU or GPU, to select the game field size, etc, and when I run the program the field is rendered over the top of the UI even though I've set the canvas to screen space overlay.

    To create the texture I'm doing this in the C# script:

    Code (CSharp):
    1.  
    2. RenderTexture tex = new RenderTexture(width, height, 0);
    3. tex.enableRandomWrite = true;
    4. tex.Create();
    5.  
    6. computeShader.SetTexture(2, "tex", tex);
    The shader is this:

    Code (CSharp):
    1. // Create a RenderTexture with enableRandomWrite flag and set it
    2. // with cs.SetTexture
    3. RWTexture2D<float4> tex;
    4.  
    5. [numthreads(16, 16, 1)]
    6. void DrawTexture(uint2 id : SV_DispatchThreadID)
    7. {
    8.     float w, h;
    9.     tex.GetDimensions(w, h);
    10.  
    11.     //  assumes h = w for now
    12.     uint cellId = id.y * w + id.x;
    13.  
    14.     tex[id] = float4(0.0, worldState[cellId], 0.0, 1.0);
    15. }
    Is there a way to have the UI draw over this texture or should I be using a different type of shader to draw this? Sorry if this is a daft question, I'm new enough to this side of things I'm still learning the words to use so not sure what to search for.

    Thanks,
    Keegan