public override void Convert(ResourceLocation source, ResourceLocation dest) { ContentBinaryReader br = new ContentBinaryReader(source); BinaryDataReader data = br.ReadBinaryData(); float xllcorner = data.GetDataSingle("xllcorner"); float yllcorner = data.GetDataSingle("yllcorner"); int width = data.GetDataInt32("width"); int height = data.GetDataInt32("height"); float[] demData = new float[height * width]; int bits = data.GetDataInt32("bits", 32); ContentBinaryReader br2 = data.GetData("data"); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { demData[i * width + j] = br2.ReadSingle(); } } br2.Close(); data.Close(); Half[] demData16 = Half.ConvertToHalf(demData); // ========================================================= BinaryDataWriter result = new BinaryDataWriter(); result.AddEntry("xllcorner", xllcorner); result.AddEntry("yllcorner", yllcorner); result.AddEntry("width", width); result.AddEntry("height", height); result.AddEntry("bits", 16); Stream dataStream = result.AddEntryStream("data"); ContentBinaryWriter bw = new ContentBinaryWriter(dataStream); for (int i = 0; i < demData.Length; i++) { bw.Write(demData16[i].InternalValue); } bw.Close(); bw = new ContentBinaryWriter(dest); bw.Write(result); bw.Close(); }
public ShaderResourceView BuildHeightmapSRV(Device device) { var texDec = new Texture2DDescription { ArraySize = 1, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = Format.R16_Float, SampleDescription = new SampleDescription(1, 0), Height = HeightMapHeight, Width = HeightMapWidth, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, Usage = ResourceUsage.Default }; var hmap = Half.ConvertToHalf(_heightMap.ToArray()); var hmapTex = new Texture2D( device, texDec, new DataRectangle( HeightMapWidth * Marshal.SizeOf(typeof(Half)), new DataStream(hmap.ToArray(), false, false) ) ); hmapTex.DebugName = "heightmap texture"; BuildHeightMapThumb(); var srvDesc = new ShaderResourceViewDescription { Format = texDec.Format, Dimension = ShaderResourceViewDimension.Texture2D, MostDetailedMip = 0, MipLevels = -1 }; var srv = new ShaderResourceView(device, hmapTex, srvDesc); Util.ReleaseCom(ref hmapTex); return(srv); }