Search Unity

Question Data from ComputeShader to Shader

Discussion in 'General Graphics' started by Shushustorm, May 8, 2023.

  1. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    1,084
    Hey everyone!

    I read a bit about getting data from CPU to GPU and vice versa, but I couldn't find anything about moving data from ComputeShader to a fragment shader. Is this not possible?
    Do I really have to move from Compute to CPU and then to fragment shader? For example, when I calculate an object's color within Compute and I want to use the color in a fragment shader, I need the CPU to be involved?

    Best wishes,
    Shu
     
  2. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    675
    You can absolutely do that without involving the CPU. Just store the compute results in a buffer or render texture that you read from in the fragment shader.

    Only catch is that you need an UAV memory barrier between the two draw calls with some graphic APIs (OpenGL, DX12 but not DX11), but Unity is taking care of that automatically if I remember correctly.
     
    Shushustorm and arkano22 like this.
  3. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    1,084
    I see! Makes sense! Thanks for the suggestions! That's great!