SaraJ Posted October 13, 2008 Posted October 13, 2008 Hi, 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 _rtsHelper.BeginScene(_renderSurface); _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); } _rtsHelper.EndScene(Filter.None); _device.Present(); //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. Quote
Nate Bross Posted October 17, 2008 Posted October 17, 2008 I don't quite understand what your objective is could you clarify a little bit more? It's possible there is another approach to this problem that may have a more simple implementation. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
SaraJ Posted October 21, 2008 Author Posted October 21, 2008 I have been able to narrow the problem down a bit. What I am trying to do is to render a number of lines to a texture, using DrawUserPrimitives or DrawPrimitives and an array of vertices. This works fine using a 32 bit texture where the VertexFormat defines the position of each vertex and colour as a 32 bit integer. However I do need to use a 64 bit floating point texture (64 bits since I need higher definition than 8 bits per colour channel, and floating points since I need to use blending, which my graphics card only support for floating point textures). My problem is that I don't know how to render lines to a 64 bit floating point texture. I suppose the DrawUserPrimitives is still the way of drawing lines, but then I need a VertexFormat that defines the position of a vertex and its colour as a 64 bit floating point value. All predefined VertexFormats of Direct3D use 32 bit colours. Anyone knows how to define this kind of VertexFormat? And how to define colour as 64 bit floating points? (in a similar manner as when defining 32 bit integer colour as a value of 0-255 per colour channel, and then adding as colour=a*256^3 + r*256^2 + g*256 +b) Quote
Nate Bross Posted October 21, 2008 Posted October 21, 2008 Maybe I'm dense, but I'm having trouble visualizing what you are trying to do, can you post a screen shot of it working with 32bit textures? Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
SaraJ Posted October 21, 2008 Author Posted October 21, 2008 This is just a simplified picture of what I am trying to do. In a real example there would be a couple of hundred of lines with a red colour value of 1. Here is only three lines with a red colour value of 150. [ATTACH]5637._xfImport[/ATTACH] Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.