Search code examples
c#wpfraytracing

Fast pixel drawing in WPF


I would like to write a simple ray tracer using WPF. It is a learning project and thus I favour configurability over performance (otherwise I'd go for C++).

I still want relatively fast pixel drawing. A previous question on StackOverflow contains code to achieve this in WPF, by obtaining a GDI bitmap. From the relatively little I know about Windows programming,

  1. GDI is slow
  2. DirectX is fast
  3. WPF uses DirectX underneath (not sure which parts of WPF though)

Is it possible to obtain pixel-level access using DirectX (not GDI) through the WPF Canvas (or similar)?

I will also consider suggestions for incorporating DirectX API calls within a WPF window (alongside other WPF controls) if that is possible.

Thanks in advance.


Solution

  • Interesting, but with raytracing, writing the pixels to the screen will (should) not be the slow part. You can use WriteableBitmap for the purpose, though. It's certainly quick enough for what you want.

    http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.aspx

    (For info, I use it in this emu/IDE - http://0x10c-devkit.com/ - and it can refresh a low res display with great performance. There's the source to that on the github repository, the LEM1802 plugin.)

    Ah, this bit: https://github.com/kierenj/0x10c-DevKit/blob/master/PluginAPI/NyaElektriska.LEM1802/GPU.cs - see UpdateDisplay.