1
\$\begingroup\$

I am trying to convert my color grading 2d lookup texture into 3d LUT. When I simply use:

ColorAtlas.GetData(data);
ColorAtlas3D.SetData(data);

I get this:

enter image description here

I tried building my 2d atlass horizontally but it did not helped - the data was messed up in a different way.

So my question is how can I influence the order of the data I get from the 2d atlas and how can I properly pass it into my 3d atlas?

Update: I know that I can GetData from a specific Rectangular area and put it into several arrays, but the result is still the same. This is what I tried:

        Color[] data2D = new Color[0];

        for (int i = 0; i < 32; i++)
        {
            Color[] data = new Color[32 * 32];
            GraphicsDevice.SetRenderTarget(null);

            ColorAtlas.GetData(0, new Rectangle(0, i*32, 32, 32), data, 0, data.Length);

            int oldLength = data2D.Length;

            Array.Resize<Color>(ref data2D, oldLength + data.Length);
            Array.Copy(data, 0, data2D, oldLength, data.Length);
        }
        ColorAtlas3D.SetData(data2D);
\$\endgroup\$
  • \$\begingroup\$ What you have look right to me. It might be worth trying copying across the data level by level rather than buffering it in an array. \$\endgroup\$ – Martin Apr 1 '14 at 16:40
  • \$\begingroup\$ What do you mean? Right now all I am doing is trying different combinations of reading data from the 2d texture to find the one that will fit into the 3d one properly. \$\endgroup\$ – cubrman Apr 1 '14 at 16:41
  • \$\begingroup\$ I don't think you can copy the data level by level. The 2d texture does not know about levels and the 3d one only accepts 1 dimensional array of data. \$\endgroup\$ – cubrman Apr 1 '14 at 16:45
  • \$\begingroup\$ At the moment you're reading out the data, buffering it up in an array and then writing it all in one go. I'm not sure why that isn't working, but I think it might be worthwhile trying reading the data (in 32x32 sections) and then writing those sections to the Texture3D straight away (there's an overload of setdata for that). \$\endgroup\$ – Martin Apr 1 '14 at 16:46
  • \$\begingroup\$ I tried doing this in a loop: ColorAtlas3D.SetData(data, i*32, data.Length); right after ColorAtlas.GetData(0, new Rectangle(0, i*32, 32, 32), data, 0, data.Length); and it shows an error "The size of the data passed in is too large or too small for this resource." \$\endgroup\$ – cubrman Apr 1 '14 at 16:52
1
\$\begingroup\$

You were right, Martin. The SurfaceFormat settings were off in the 2d texture. But for anyone wondering, here is a quick map how GetData/SetData works for the default GetData(data)/SetData(data): enter image description here

So basically your layers should be located BELOW your first picture in the 2d atlass to put them into the 3d texture seamlessly.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.