0

I'm new on DirectX so I don't know a lot of things about this technology. I would like to reproduce the same rendering that photoshop is doing. I mean to be able to render in real time several layers (with alpha map for each layer). Someone told me that photoshop uses DirectX/OpenGl. For my project I can use DirectX.

I found this post Direct3D rendering 2D images with "multiply" blending mode and alpha which explains exactly what i want to do but this post is quite old and he used D3D9. Maybe, there is now a simpler/faster way to create the same effect using DirectX 11 and Direct2D.

I hope you would give me some advice before I start anything.

Thank you.

Edit: I don't know if I was enough clear, I'm not asking for any code, just for a direction: if I shoud use Direct2D or Direct3D 9/10/11. If I will have to program shaders... And what would be the best to do this project ?

Community
  • 1
  • 1
Seltymar
  • 337
  • 6
  • 21
  • Whether you should use multiple draws with hardware blending or shaders depends on how many layers you expect to handle, and the requirements on that. If each layer adding/multiplying/etc against all the previous results is acceptable, then just do a very basic `SetTexture, Draw(quad)` loop; if you need more complex blending, you'll need a set of shaders for all possible blend modes taking at least two texture each, perhaps more. – ssube Feb 22 '12 at 04:28
  • @peachykeen Thank you for your comment. The number of layers is not limited and operations are quite basics as you said adding/multiplying/alpha blending. What technology would you advise me for that ? As I'm using only 2D image, can I do it with Direct2D ? – Seltymar Feb 22 '12 at 04:34
  • Since you'll be working exclusively with a single quad in D2D or D3D, there's little performance difference. In both, you'll be binding a texture or two, drawing to a texture, and looping. It may not necessarily be fast, because of all the state changes that requires. If you want the GDI+ interop and such, D2D may be a good choice, but not that it restricts your userbase for no reason (you get no performance boost or any real benefits). It should also be possible, so long as you can implement a ping-pong style render, to provide arbitrary 2-texture shader effects for additional modes. – ssube Feb 22 '12 at 05:10
  • Thank you for your advice. I will try with D2D, it doesn't seem too complicated. – Seltymar Feb 22 '12 at 07:30

2 Answers2

2

Depending on the performance you are looking for D3D or D2D would be more appropriate. D3D is much more retained mode, thus a more complex API to use, but it is what you'll want if performance is of absolute concern. D2D API is much more immediate mode, but this of course leads to a simpler API and slower performance.

Based on my experience I'd start with D2D, especially since the new D2D APIs such as ID2D1DeviceContext::DrawImage() and ID2D1Effect supports many blend and composite modes. D2D does inter operate with D3D quite nicely so in the future you can use parts of D3D if you need. D2D also provides a very nice interface to support printing, so the same rendering code can be used to print.

Unknown1987
  • 1,671
  • 13
  • 30
  • Thank you. For me, the performance is important as I want to be able to render in realtime but I think I will start by D2D as it is simpler and if it is not enough good, change for D3D. – Seltymar Feb 22 '12 at 05:29
  • Sure, but just keep in mind that D2D is perfectly capable of rendering at real time 60 FPS. IE9 and IE10 uses D2D, have a look at some of the test drive demos. – Unknown1987 Feb 22 '12 at 05:32
1

If you're using the currently shipping version of Direct2D (not the updated one in the Win8 previews), you can implement "OVER" (aka Normal) blending with alpha masks. Render the content into a PBGRA32 bitmap, and then render a mask (if needed) into an Alpha8 bitmap. Then, create a bitmap brush from the content bitmap, and use ID2D1RenderTarget::FillOpacityMask(). If the mask isn't needed then just use DrawBitmap() and skip the bitmap brush.

To implement any additional blending modes you'll need the newer Direct2D, which won't be available for everyone until Windows 8 ships (I think it's being made available for Win7 too). Or, of course, you can do it in software mode but you'll have to implement everything from scratch.

Rick Brewster
  • 3,374
  • 1
  • 17
  • 21
  • I will try to implement as you said. At the moment, I started with the introduction http://msdn.microsoft.com/en-us/magazine/dd861344.aspx . But the CreateDeviceResources() methode takes around 5 seconds. Is it normal ? I just created the RenderTarget. – Seltymar Feb 23 '12 at 02:35
  • Thank you, it works pretty well. Just the CreateHwndRenderTarget function takes around 15 seconds because my computer has just a chipset and no graphic card. It's quite long as I have several windows to initialized. Is there a way to optimize that and makes it faster ? – Seltymar Feb 27 '12 at 04:49
  • If it takes 5-15 seconds then ... I don't know. Your video card driver is hopefully just awful! :( You'll want to use something like Windows Performance Recorder and Windows Performance Analyzer, which are part of the beta release of the Windows 8 Assessment and Deployment Kit ( http://www.microsoft.com/download/en/details.aspx?id=28997 ), to dig deeper. Or just try it on another machine to make sure it's only your computer which is exhibiting that problem. – Rick Brewster Mar 22 '12 at 18:17
  • Thank you for your reply. I just made a little test and I found the problem, it's not due to my computer but to visual studio it self. When I run my program using the .exe, I don't have any problem and the image is diplayed instantly. But from visual studio (even in release mode), it takes 15 seconds. I have visual studio 2010. – Seltymar Mar 26 '12 at 07:40
  • You might have set it up so that symbols always load, and aren't being cached properly (or something). I remember I had an issue with very long debug start times (as in, Debug -> Start with Debugging). It was because it was trying and failing to download symbols from some server that was long gone. If this is the case you should see in the VS status bar that it's loading symbols, and going quite slowly. (Sorry, I forget the details, but hopefully that's the right place to go looking and ultimately fix the delay.) – Rick Brewster Apr 04 '12 at 03:06
  • In my status bar it just say "ready". In my output window of visual studio it seems to load a dll file called : igd10umd32.dll. It says exactly: "Loaded 'C:\Windows\System32\igd10umd32.dll', Cannot find or open the PDB file." When it is loaded it tells me that : "EnsureVisible: illegal tab number -1" I think this dll causes the delay, the description of the dll is LDDM User Mode Driver for Intel(R) Graphics Technology. But i don't know how to fix it. I don't know if it is important to fix it since there is no problem with the executable. – Seltymar Apr 06 '12 at 06:17
  • Yeah that sounds like a symbol loading problem. I would try to just disable symbols altogether and see if that improves things. Then go back and I think there's an option to say "don't every try loading symbols for a specific DLL." – Rick Brewster Apr 07 '12 at 23:21
  • Hi, I tried different things. first, I excluded all loading of symbols but it still takes time. After I tried with downloading symbol from microsoft symbol servers but it doesn't find the symbols for this dll. Finally I tried to exclude only this dll but it changes nothing. Am I right if I say that symbols are used only for debugging ? I didn't find your option in visual studio 2010 professional. Offtopic : paint.net has a really nice UI, I'm wondering what technology are you using if it's not secret ? – Seltymar Apr 16 '12 at 09:22