2 pixel shaders

This is a discussion on 2 pixel shaders within the Game Programming forums, part of the General Programming Boards category; I started playing around a bit with pixel shaders (man are they fun ). Now assume I want 2 shaders ...

  1. #1
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    2 pixel shaders

    I started playing around a bit with pixel shaders (man are they fun ). Now assume I want 2 shaders to execute after each other, 1 for the induvidual face then 1 for the entire screen (after everything is rendered), is there an easy way to do this or do I have to render to some offscreen surface then render that surface to the screen using the other shader?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    I'm not sure but I believe you'll have to render everything to an offscreen texture and then render that texture using the post-processing pixel shader like you said. I don't believe you can use the first method you said and I can't really think of another method off the top of my head.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    In order to do this you must render your scene to an offscreen texture which acts as the screen image. All of the shaders relevant to creating the scene will then be executed normally just as if you were rendering to the actual screen.

    After rendering is complete then you must pass in the offscreen texture as the source texture or input texture to the post-processing pixel shader.

    1. The shaders relevant to the scene have nothing to do with the post-processing shader.
    2. The shaders for the scene execute just as they would if you were rendering to the screen.
    3. The post-processing shader operates on the final offscreen texture and then outputs to that texture as well.
    4. Setup a full screen-quad and call SetTexture() and set the texture to the offscreen texture you have altered. Draw the quad. The quad will not have the offscreen texture as it's texture and you are taking full advantage of the hardware acceleration available to you.

    This can also be done with a clever use of the SetRenderTarget() method in IDirect3DDevice9.

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    I already managed to do this, by using a D3DXRenderToSurface structure. Notes for anyone trying to do the same:

    § Do NOT render using a D3DXSprite structure, shaders won't have any effect!
    § Do NOT render using a mesh, XYZRHW is not supported!

    Thanks anyway!
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    On a sidenote, shaders are more limited than I first thought. Unless you have the latest gfx card with shader v666.0 you can't do too much. It took a lot of modifying around before I managed to get a grayscale shader with a factor (0 = no grayscale, 1 = full grayscale) to compile. Got lots of "too advanced" error messages...

    What really disappoints me is that it seems you cannot to access another pixel in the texture in shader v1.3 (highest version my card seems to support). I wanted to create a heat effect with the screen blurring around, but that seems very distant right now...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    How are you compiling your shaders? This is where I got rather confused - I'd like to compile them w/o leaving MSVC's IDE - does MS have a tool for this that plugs into the IDE?

  7. #7
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    I do it at runtime using D3DXCompileShader().
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  8. #8
    ---
    Join Date
    May 2004
    Posts
    1,379
    Quote Originally Posted by Magos
    I do it at runtime using D3DXCompileShader().
    You mean it interprets it at run time? or it compiles it at compile time?

  9. #9
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    At runtime. I have these psh (pixel shader) and vsh (vertex shader) ASCII files with the HLSL language in them. When the exe runs it loads them, calls D3DXCompileShader() and I get some binary data back which I use when creating the shader objects.

    It's most likely possible to pre-compile the shader files but I haven't noticed any speed reduction so I guess the compilation is pretty fast anyway, no need to pre-compile.

    Also, modability++ if they aren't pre-compiled .
    Last edited by Magos; 06-13-2005 at 06:53 PM.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Changing pixel colour
    By redruby147 in forum C Programming
    Replies: 11
    Last Post: 06-09-2009, 05:28 AM
  2. How can I make this code more elegant?
    By ejohns85 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2009, 08:55 AM
  3. Reading pixel color data from screen
    By JJFMJR in forum Windows Programming
    Replies: 8
    Last Post: 08-22-2008, 12:27 PM
  4. Getting Pixel Colour Screen
    By god_of_war in forum C++ Programming
    Replies: 3
    Last Post: 03-14-2006, 12:17 PM
  5. Pixel Shaders.
    By Cheeze-It in forum Game Programming
    Replies: 1
    Last Post: 05-21-2002, 01:16 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21