Drawing pixel by pixel

Started by
11 comments, last by Dave Hunt 14 years, 11 months ago
Hey everyone, I'm hoping you all can point me in the right direction. I'm writing a simple ray tracer using directX 9 and C#. What kind of calls or functionality in directx 9 would I use to draw each pixel individually after I have calculated the new color? Right now I'm just using the general mesh.DrawSubset to draw the mesh objects.. is there a way to override this or just rpelace it? Thanks in advance :)
Advertisement
It sounds like you're using MDX. If you are...don't. It's a dead project, it's no longer updated (or even included in the SDK), and there are better options available (mainly SlimDX and XNA).

Either way, Direct3D is (in general) not all optimized for a scenario where you calculate pixel colors on the CPU and then just blit them with GPU. Optimal performance comes from keeping graphics related data and calculations on the GPU so it can work with little CPI intervention. Therefore, there's no nice "SetPixel" function or anything like that. Probably the best way to do what you want is first write all of your colors to buffer in CPU memory, and then copy it to a screen-sized texture and draw the texture to the backbuffer.

It's also possible to do some (or all) of the ray tracing calculations in pixel shaders (or compute shaders with DX11). However you'll be more limited with what you can do in DX9.
Thanks for the reply... Yup I'm using MDX.. didn't realize how "dead" it was until I got stuck and now it's much too late to switch :(

I guess i'll try the buffer idea... I started reading about the pixel shader last night, just didn't quite understand how to use it...
Quote:Original post by superservo15
...now it's much too late to switch :(

Why? Unless it's a school assignment you should be able to start over any time you want.

Former Microsoft XNA and Xbox MVP | Check out my blog for random ramblings on game development

Also, switching from MDX to SlimDX should be fairly straightforward.
It IS a school assignment, and due in two days so no time to switch :(

I spent all my time on the algorithms not realizing that what I thought should be simple in directX most likely was not... any help is appreciated...
Unless my MDX memory is faulty, there are GetData/SetData methods on the texture objects. You can GetData into an array, update whatever pixel positions in the array you want, then SetData back to the texture and render the texture via the sprite interface or using a textured quad.
Hmm maybe if I can leave work early I will try SlimDX... just looked up the page and it looks cool... Wish I would have met you guys before :-p

Is drawing a scene pixel by pixel easier with SlimDX?

May or not be helpful, but:
http://www.gamedev.net/community/forums/topic.asp?topic_id=350944
-- What would Sweetness do?
With SlimDX, you use Texture.Lock which returns an array of pixels. You can then twiddle the pixels and call Texture.Unlock to update the texture. That's essentially how MDX works as well. (GetData/SetData was faulty memory. Those are XNA methods.)

SlimDX is closer to "plain" DirectX in that each DirectX interface has a corresponding SlimDX class. MDX decided we didn't want that and tried to make some things easier by making them not work like "plain" DirectX, which just made things confusing.

This topic is closed to new replies.

Advertisement