0

I searched a lot without finding how to have a compute shader draw lines and characters in a texture2D.

My application has to do a lot of processing and generate a bitmap in a texture2D which is then rendered on screen and downloaded back to CPU and finally saved in a file. After the bitmap is generated, I have to draw lines (and other simple geometric shapes) as well as character strings to annotate the bitmap. I'm stuck on this stage.

btw: I'm using MSVC2015, DirectX/DirectCompute11, NVidia K4200 GPU.

Any help appreciated.

fpiette
  • 11,983
  • 1
  • 24
  • 46
  • @scheff the probelm is not to draw on screen but to use DirectCompute (GPU processing). That is the code is in a compute shader program. – fpiette Aug 09 '19 at 09:05
  • Ah, oh... Should've read more carefully. – Scheff's Cat Aug 09 '19 at 09:07
  • Considering, how complicated this might become on GPU side... Why not add your lines and other things after download (/ before saving to file) on CPU side? This is probably much easier to achieve because you have a lot available which is ready for use. – Scheff's Cat Aug 09 '19 at 09:09
  • Why are you using compute shader to draw lines and stuff instead of normal? – user7860670 Aug 09 '19 at 09:13
  • I want to use compute shader because the images are really large and position of lines are dependent on the computation done to generate the image, computation done by a shader. Rendering on CPU is very slow for large image. Actually I already have the image processing application implemented 100% on CPU side using GDI. Processing is really very slow. I speak about images having 250 mega-pixel in size with 16bit per pixel (gray scale) that is a 500MB image. For rendering on screen, it has to be converted to RGBA. – fpiette Aug 09 '19 at 09:38
  • @Scheff this text rendering article is about OpenGL. I use DirectX/DirectCompute. It is not about 3D rendering, I only 2D and application is mostly computing. – fpiette Aug 09 '19 at 09:41
  • I've found an article expalining how to draw lines and circles. And it works! http://recreationstudios.blogspot.com/2010/04/simple-compute-shader-example.html – fpiette Aug 09 '19 at 09:59
  • The previous article mention in my above comment made me think that an acceptable solution is to use any "classic" algorithm to draw line on a rasterized image. And looked for some and found this one interesting: https://github.com/ArminJo/STMF3-Discovery-Demos/blob/master/lib/graphics/src/thickLine.cpp This is C code but very easy to translate to HLSL. This implementation produce lines of any thickness. – fpiette Aug 12 '19 at 05:47

1 Answers1

0

I finally solved my problem by implementing a classic algorithm to draw line on a rasterized image. I started from this code which is C code but very easy to translate to HLSL. This implementation produce lines of any thickness.

I also wrote code to write characters to the texture2D the old way: I got a dot matrix font (There are a lot free to find on the internet), stored in a ByteAddressBuffer and copy pixel from that font to the texture2D. I make it easy to use by writing a few functions to "print" various data at given coordinates in the texture2D. That works very well for what I needed.

fpiette
  • 11,983
  • 1
  • 24
  • 46