Search Unity

RenderTarget conversion to Texture3D (for simple read/sample operations) possible?

Discussion in 'Shaders' started by scheingirl, May 9, 2013.

  1. scheingirl

    scheingirl

    Joined:
    Apr 23, 2013
    Posts:
    3
    Is it possible in Unity to get a normal shader resource view on an unordered access view like in plain DX11?

    For example:
    I want to use Compute Shader kernels to write to several RWTexture3D (in C# RenderTarget with isVolume flag set...), which works like many other examples here. In the next kernel I need that Rendertarget as Input and would like to have it as straight read only Texture3D, but I couldn't get it to work.
    In DX11 you just created one shader resource view for cached read operations and an unordered access view for random read and write ops on the same Texture. So that worked quite easy :wink: (although some care needs to be taken...)

    I tried to convert my project, to only use RenderTargets but the problem here is the limitation of the Load operation of the RWTexture3d<float4> (some error like: load operation only allowed for a typed single 32 bit float member or something similar...)

    Of course I'm just talking about RWTexture3d<float4> and Texture3d<float4>.

    I also thought it's maybe possible to use the Rendertargets.colorbuffer for creating a new Texture3D instance, but couldn't find any doc telling about.. but I guess that's not possible, is it?


    So guys give me some input!!!
    Thanks in advance!!! :D
     
  2. smb02dunnal

    smb02dunnal

    Joined:
    May 5, 2012
    Posts:
    439
    I assume Unity is doing a lot of stuff in the conditioning stage of it's shader pipeline, and I assume this is where it works out whether a UAV or SRV needs to be bound based on the name of the parameter you are trying to bind from C#' and probably which register to bind to.

    Anyways.... To cut a long story short, to do what you ask you just need to create the RenderTexture with the isVolume flag true AND the enableReadWrite flag true. Then bind your RT like normal into a RWTexture3D<float4> slot in one kernel, and in the next just bind the same RT into the Texture3D<float4> slot.

    Those flags you set at the start will of created the UAV, SRV, RTV and probably the DSV in the background.
     
  3. scheingirl

    scheingirl

    Joined:
    Apr 23, 2013
    Posts:
    3
    Hey, thanks for your response!
    I figured it some time ago ;) I wasn't sure if theres a need from within C# to setup the different views, but as you said, there's going on a lot of intern stuff.