Rendering to 64-bit textures using DirectX


I am trying to render to a 64 bit floating point texture, and later on to read the values from the texture but can't seem to get it to work.

What I am trying to do is to render a number of lines to a texture, setting the color of each line to 1 in the red color-channel and then use additive blending to get a kind of density map where the value represents the number of lines crossing (two lines crossing giving a red value of 2 and so on). Using a 32-bit integer texture this works fine, but I can't get it to work at all with 64-bit textures (wich I need since the 8 bits of the red channel is not enough). What I get stuck on is that there don't seem to be any predefined color format for 64-bits and I do not now how to represent the color channels in a way that makes it possible to read the values of a separate color channel later on.

Below is a very simple example (2 lines crossing eachother) of my code for creating lines, render to texture (using RenderToSurface) and reading from texture using 32-bit textures. I am using C# and DirectX.

private void SetUpTextureAndRenderSurface()
_rtsHelper = new RenderToSurface(_device, _textureWidth, _textureHeight, Format.A8R8G8B8, true, DepthFormat.D16);
_renderTexture = new Texture(_device, _textureWidth, _textureHeight, 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);

_renderSurface = _renderTexture.GetSurfaceLevel(0);

private void SetUpVertices()
_vertices = new CustomVertex.TransformedColored[4];
_vertices[0] = new CustomVertex.TransformedColored((float)0, height * 0.5f, 0f, 0f, Color.FromArgb(255, 0, 0).ToArgb());
_vertices[1] = new CustomVertex.TransformedColored((float)width, height * 0.5f, 0f, 0f, Color.FromArgb(255, 0, 0).ToArgb());
_vertices[2] = new CustomVertex.TransformedColored((float)0, height * 0f, 0f, 0f, Color.FromArgb(255, 0, 0).ToArgb());
_vertices[3] = new CustomVertex.TransformedColored((float)width, height * 1f, 0f, 0f, Color.FromArgb(255, 0, 0).ToArgb());

private void SetUpBuffer()
_vertexBuffer = new VertexBuffer(typeof(CustomVertex.TransformedColored), 4, _device, Usage.Dynamic | Usage.WriteOnly, CustomVertex.TransformedColored.Format, Pool.Default);
_vertexBuffer.SetData(_vertices, 0, LockFlags.None);

private void RenderTexture(int orderNumber)
//Render lines to texture
_device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);

_device.SetStreamSource(0, _vertexBuffer, 0);
_device.VertexFormat = CustomVertex.TransformedColored.Format;

for (int line = 0; line < 2; line++)
_device.DrawPrimitives(PrimitiveType.LineStrip, (line * 2), 1);


//Load texture into surface that can be locked and read from
Surface fdbck = _device.CreateOffscreenPlainSurface(_textureWidth, _textureHeight, Format.A8R8G8B8, Pool.Scratch);

SurfaceLoader.FromSurface(fdbck, _renderSurface, Filter.None, 0);

//Lock texture and store values in array
uint[,] data2 = (uint[,])fdbck.LockRectangle(typeof(uint), LockFlags.None, new int[] { _textureHeight, _textureWidth });
int[,] values = new int[_textureWidth, _textureHeight];

for (int j = 0; j < _textureHeight; j++)
for (int i = 0; i < _textureWidth; i++)
values[i, j] = Color.FromArgb((int)data2[j, i]).R;

Anyone got any idea how to do this using a 64-bit floating point texture (A16B16G16R16F)? I have been trying to solve this on my own for a couple of days now, and don't seem to get any closer to a solution.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!