Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //context - GraphicsContext
- //texture - Height map texture with disabled mipmaps, streaming and imported as greyscale!!!
- var image = texture.GetDataAsImage(context.CommandList);
- var heightData = GetHeightDataFromTexture(image);
- //Method makes greyscale reading from Xenko image
- private byte[,] GetHeightDataFromTexture(Image image)
- {
- var box = image.ToDataBox().First();
- var dataArray = new int[box.SlicePitch / 4];
- Marshal.Copy(box.DataPointer, dataArray, 0, dataArray.Length);
- var imageWidth = box.RowPitch / 4;
- var imageHeight = box.SlicePitch / box.RowPitch;
- var heightData = new byte[imageWidth, imageHeight];
- for (int y = 0; y < imageHeight; y++)
- {
- for (int x = 0; x < imageWidth; x++)
- {
- heightData[x, y] = (byte) (dataArray[y * imageWidth + x] & 0xFF);
- }
- }
- return heightData;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement