Skip to main content
GameDev.net gamedev.net
🔒 Locked

Manipulating brightness/contrast/etc on a surface

Started by gogothebee Feb 6, 2009 at 8:25 AM 5 replies 1.7k views
Original Post
gogothebee
gogothebee
Hi, I'm developing the Direct3D video driver for MPlayer and I have a simple question. I want to implement MPlayer's brightness/contrast/etc. controls in my driver, but I'm not sure how I should proceed. I was naive enough to believe that there is an API, which can manipulate the contents of a offscreen plain surface, which I use to copy each frame into or the RGB backbuffer I StretRect onto, but there's no such thing. What's your advice? I want to do the conversion on the GPU. There is already a software filter working on the CPU, but this is not the point. I'm pretty new to Direct3D programming and DirectX as a whole. Should I write a pixel shader to do the work or there is an easier way? Thank you in advance!
Nik02
Nik02
Pixel shader is the way to go.

I'd prefer shaders over raw C++ for the fact that HLSL has a very robust vectorized type system that proves a very useful tool in pixel data manipulation. HLSL, as a language, is very similar to C and is not very difficult to learn.

As for the performance, GPU can be order of magnitude faster than CPU in precisely this type of work.
Niko Suni
gogothebee
gogothebee
I was thinking that pixel shaders will be required, but I wasn't sure. Of course I want to do this on the GPU - this is the whole point :)

Can you point me to a good pixel shader programming guide? If you don't know, don't worry - I'll have to search anyway... I guess I'll need to user vertex shader as well in order to "vectorize" the operation I'm doing on more than one pixel. I'll get started soon.
Nik02
Nik02
Check the DirectX SDK for several samples that use pixel shaders. NVidia and AMD/ATI developer sites also have good material. If you want to play with pixel shaders visually, download the FX Composer from developer.nvidia.com, watch the tutorials and you'll be well on your way to writing your own shaders. When you do, I recommend using the Effect framework which does a lot of setup for you.


Quote:
Original post by gogothebee
I guess I'll need to user vertex shader as well in order to "vectorize" the operation I'm doing on more than one pixel. I'll get started soon.


You only need a minimal vertex shader so as to get a quad (two triangles) to your render target. The heavy lifting in image processing is usually done in pixel shader. All shader operations are automatically run in parallel on the GPU so you don't have to explicitly worry about "threading" with individual pixels or vertices - the hardware does its own work allocation and load balancing.
Niko Suni
gogothebee
gogothebee
This sounds great! Thanks for the comprehensive answer. I'm on my way!
solenoidz
solenoidz
I just wondered why your nick seemed so familiar to me..Then I figured it out. :)
I found this resource very straight-foreward for beginers.
http://www.facewound.com/tutorials/shader1/
gogothebee
gogothebee
Here is an interesting discussion as well:

http://virtualdub.org/blog/pivot/entry.php?id=241


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.