Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fast pixel drawing in WPF

Tags:

c#

wpf

raytracing

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.

like image 248
Gigi Avatar asked Sep 25 '12 12:09

Gigi


3 Answers

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.

like image 177
Kieren Johnstone Avatar answered Nov 15 '22 04:11

Kieren Johnstone


Another solution is WriteableBitmapEx. It extends the builtin WriteableBitmap.

like image 30
Joel Lucsy Avatar answered Nov 15 '22 05:11

Joel Lucsy


There is an open Source Project Called Direct Canvas wich is A hardware accelerated, 2D drawing API that supports vector graphics, multimedia files, extensible pixel shaders, blending modes and more!

http://directcanvas.codeplex.com/

Demo http://www.youtube.com/user/jdollah69#p/u

like image 2
Pascalsz Avatar answered Nov 15 '22 04:11

Pascalsz