Jump to content
  • Advertisement
Sign in to follow this  
undergnd

Shader for pixel shuffling

This topic is 3793 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm working on a project that intercept frames that are transmitted to the display, modify the pixel arrangement in sub pixel level (RGB), and send them to the display... What I think is there should be a some kind of buffer in the video card that stores frames that will be transmitted to the display.... Is there anyway to read "the buffer", and swap the pixel arrangement in the frame and put it back to "the buffer" so that the display will receive and display modified frame..?? My plan is this... I'll make a simple application (dialog based), minimized to the system tray, that will receive a certain hot key, such as F9... When F9 is pressed.. the application will read the frames right before they are transmitted to the display and swap the columns in sub pixel level as follows... suppose that I have 1024x768 display.. then a frame will be.. -- Row0: R0 G0 B0 R1 G1 B1 R2 G2 B2 ... R511 G511 B511 R512 G512 B512 ... R1022 G1022 B1022 R1023 G1023 B1023 Row1: R0 G0 B0 R1 G1 B1 R2 G2 B2 ... R511 G511 B511 R512 G512 B512 ... R1022 G1022 B1022 R1023 G1023 B1023 Row2: R0 G0 B0 R1 G1 B1 R2 G2 B2 ... R511 G511 B511 R512 G512 B512 ... R1022 G1022 B1022 R1023 G1023 B1023 . . . Row767: R0 G0 B0 R1 G1 B1 R2 G2 B2 ... R511 G511 B511 R512 G512 B512 ... R1022 G1022 B1022 R1023 G1023 B1023 -- I want to modify above frame like below before it is transferred to the display... -- Row0: R0 G512 B0 R512 G0 B512 R1 G513 B1 R513 G1 B513 ... R511 G1023 B511 R1023 G511 B1023 Row1: R0 G512 B0 R512 G0 B512 R1 G513 B1 R513 G1 B513 ... R511 G1023 B511 R1023 G511 B1023 Row2: R0 G512 B0 R512 G0 B512 R1 G513 B1 R513 G1 B513 ... R511 G1023 B511 R1023 G511 B1023 . . . Row767: R0 G512 B0 R512 G0 B512 R1 G513 B1 R513 G1 B513 ... R511 G1023 B511 R1023 G511 B1023 -- Supposed that if I have a 1024x768 image, left half is purple (255,0,255) and right half is green (0, 255, 0).. When I trigger the "conversion" the display will display white (255,255,255) on the left half of the screen and black(0,0,0) on the right half of the screen... I talked to nVidia and a guy told me that "It is theoretically possible.. and I need to use shader... I am quite new to video programming in vc++... (I have EE background.. and currently it is done by a hardware and we want to remove the hardware and do it in the software) I don't know what is a shader... even though I started studying it... I'll understand what the shader is soon.. and how to make it... BUT.. does any one knows where I have to read..?? I mean.. where is the place in the video memory that the frames will be stored before they are transmitted to the display..?? and how can I read that memory location..?? Any help will be helpful... Thank you very much.. Have a nice day... [Edited by - undergnd on February 4, 2008 9:18:51 AM]

Share this post


Link to post
Share on other sites
Advertisement
Writing the pixel shader should be simple enough to do. You might even find it quicker to do the change on the CPU, depending on how you get at the data that needs to be modified.

The difficult bit will be changing the output of the video card for all applications. The problem is that the screen buffer is held in the video card's memory and is output directly to the monitor(s) by the hardware (i.e. a DAC in the case of a CRT monitor). Some programs will also write directly to that buffer.

Unless it's only output from one specific application that you want to modify (and you have the source code for it) what I'd suggest would be to use the secondary monitor output that most modern video cards have. You could take continuous screenshots from one monitor, and display your processed version of them on the other. Would that fit your needs?

Some more details on why you want to do this might be helpful so that we can suggest alternative solutions.

Share this post


Link to post
Share on other sites
Thank you for the answer, Adam_42...

My company manufactures the autostereoscopic displays...
I have developed a board that performs the function above, and it is quite expensive... My boss want me to remove the board and implement that function in software... and he doesn't have any intention to hire a software engineer...

nVidia's Consumer 3D driver doesn't the very similar thing (relocating pixels)... My contact at nVidia told me that it is done by driver level.. and he can't teach me how to do that... also, he didn't recommend me to write another stereo driver since it might conflich nVidia driver (including stereo driver)... so that he mentioned about using shader to read "the buffer", perform pixel manipulation, and write it back to the buffer...

I prepared pseudo code for the pixel operation but the problem is I don't know where to read and write back...

Thank you very much...

Share this post


Link to post
Share on other sites
It's possible (but somewhat awkward) to do in software if you limit yourself to D3D (and maybe OpenGL) games that are running in fullscreen mode. That's because you can hook those APIs and get your code in the right place.

They will all work on a double buffered output - that is they draw to the 'back buffer' while the 'front buffer' is being displayed on screen. At the end of drawing they then ask D3D to swap the two buffers. It's at that point you need to jump in and adjust the back buffer before the swap actually takes place. You'll probably need to create a spare screen sized buffer to do your processing in (which should be created at about the same time as the back buffer).

There's an old post about hooking D3D here which should help getting you started.

You'll probably also want to make yourself a simple D3D based program to test this with, and so you get to know the D3D API yourself.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!