Hey there,
i'm trying to read a 16b floating point texture into a float array.
However, no matter what i do it comes out as complete garbage.
In order to test this i create a new texture from the data and save it.
See the attached screenshots, one is the source image, the other is the resulting garbage.
If anyone knows what's going on here, every bit of help is greatly appreciated!
Here's how i load the heightmap and read the data. The image was saved as R16 DDS using the Nvidia Photoshop plugin.
var desc = new ImageLoadInformation
{
Format = SharpDX.DXGI.Format.R16_Float,
Filter = FilterFlags.None,
Width = 4097,
Height = 4097,
MipLevels = 1,
CpuAccessFlags = CpuAccessFlags.Read,
OptionFlags = ResourceOptionFlags.None,
Usage = ResourceUsage.Staging,
BindFlags = BindFlags.None,
MipFilter = FilterFlags.None,
};
var texture = Texture2D.FromFile<Texture2D>(Engine.Device, "height16b.dds", desc);
var buffer = new Half[4097 * 4097];
var box = Engine.Device.ImmediateContext.MapSubresource(texture, 0, MapMode.Read, MapFlags.None);
Utilities.Read<Half>(box.DataPointer, buff, 0, buff.Length);
Engine.Device.ImmediateContext.UnmapSubresource(texture, 0);
Here's how i create a new texture from the array and save it:
int byteSize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(Half));
DataStream stream = new DataStream(buffer.Length * byteSize, true, true);
stream.WriteRange(buffer);
int pitch = size * byteSize;
DataRectangle rect = new DataRectangle(stream.DataPointer, pitch);
Texture2D result = new Texture2D(Engine.Device, new Texture2DDescription
{
ArraySize = 1,
BindFlags = BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
Format = SharpDX.DXGI.Format.R16_Float,
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
Height = size,
Width = size,
MipLevels = 1,
OptionFlags = ResourceOptionFlags.None,
Usage = ResourceUsage.Default
}, rect);
Texture2D.ToFile(Engine.Device.ImmediateContext, result , ImageFileFormat.Dds, "G:\\test16bit.dds");