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. Dismiss Notice

Understanding Attribute Maps

Discussion in 'Visual Effect Graph' started by ayruos, Mar 11, 2020.

  1. ayruos

    ayruos

    Joined:
    Nov 7, 2018
    Posts:
    14
    I'm trying to understand how attribute maps (for position, colour, etc) work, and how to go about encoding them.

    From what I understand, an attribute map is a 2D texture where each pixel is encoded with information on said position/colour/etc which to sample. But I can't seem to find any info on how they are encoded. For position, does the RGB of each pixel correspond to the XYZ? How does scaling work, RGB is 0-255 so how does that scale to a position?

    Any information/documentation on this would be helpful.

    As a more practical question, what I'm trying to do is that I have two 2D images, one RGB and another a grayscale depth map of the same image. I want to make a VFX Graph particle system from the same and the attribute maps option seems to make the most sense, but I'm struggling to understand how to translate the images I have into these attribute maps. I'm probably going to get this done beforehand using openFrameworks but can this be done real time as well? (I guess compute shaders would be needed for that - something I don't really have any experience with).
     
    qsleonard likes this.
  2. andybak

    andybak

    Joined:
    Jan 14, 2017
    Posts:
    561
    It's fairly simple. You can feed any image in and yes - RGB maps to XYZ. However you can add nodes in between the image sampler and the place were you use those values to do any rescaling or tweaking of the values.

    You shouldn't need any compute shaders unless you want a new map every frame at high frame rates and map dimensions. You can get away with small-ish maps every frame just using C# - and that's assuming you need to do any preprocessing which you might not.
     
  3. ayruos

    ayruos

    Joined:
    Nov 7, 2018
    Posts:
    14
    Okay, so if I'm understanding correctly, this is what it the attribute map translates to from the two images (color and depth) that I have.

    For position:
    attributeMapPos.r = colorImage pixel index x (scaled to 0-255)
    attributeMapPos.g = colorImage pixel index y (scaled to 0-255)
    attributeMapPos.b = depthImage[x, y] (already in 0-255 white to black, so no scaling)

    For color:
    attributeMapColor = colorImage[x, y]

    Does that sound right?
     
  4. AndrewStyan

    AndrewStyan

    Joined:
    Apr 6, 2020
    Posts:
    14
    Did you find any other info on this? I am at a similar stage.

    Position generally requires float values. So, how would they be encoded? How are HDR colors encoded?

    There are a whole set of 2d texture formats available, but I have little clue as to which one is needed - https://docs.unity3d.com/ScriptReference/TextureFormat.html
     
  5. AndrewStyan

    AndrewStyan

    Joined:
    Apr 6, 2020
    Posts:
    14