Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualHodgman

Posted 04 June 2014 - 04:35 PM

To do an if/else between two different post-processing shaders:
1) read the depth of each pixel, use it to reconstruct position, test if the position is within your bounding box. Return white for true and black for false.
2) generate mipmaps for this black/white texture.
3) render your optional "if" post-processing quad. In the vertex shader, read from the 1x1 pixel mipmap of the black/white texture. If some threshold isn't met (tex>0 for "any pixels from the box visible", tex==1 for "all visible pixels are in the box") then multiply the vertex position by zero, which effectively hides the quad.
4) render an alternative "else" post-processing quad. In the vertex shader, perform the same test, but inverted (using 1-tex).

 

[edit]There's a bunch of caveats involved in doing this kind of thing in D3D9 though.

* To read the depth buffer in step (1), you either need to use D3DFMT_INTZ, or render depth to a regular texture yourself using a shader.

* To read from a texture in a vertex shader ("VTF") in steps (3/4), you likely need to use a floating point texture format such as D3DFMT_R16F or D3DFMT_A16B16G16R16F.

* Step 2 is automatic in D3D9 if you created that texture with the D3DUSAGE_AUTOGENMIPMAP flag.


#2Hodgman

Posted 04 June 2014 - 04:33 PM

To do an if/else between two different post-processing shaders:
1) read the depth of each pixel, use it to reconstruct position, test if the position is within your bounding box. Return white for true and black for false.
2) generate mipmaps for this black/white texture.
3) render your optional "if" post-processing quad. In the vertex shader, read from the 1x1 pixel mipmap of the black/white texture. If some threshold isn't met (tex>0 for any pixels from the box visible, tex==1 for all visible pixels are in the box), then multiple the vertex positions by zero, which hides the quad.
4) render an alternative "else" post-processing quad. In the vertex shader, perform the same test, but inverted (using 1-tex).

 

[edit]There's a bunch of caveats involved in doing this kind of thing in D3D9 though.

* To read the depth buffer in step (1), you either need to use D3DFMT_INTZ, or render depth to a regular texture yourself using a shader.

* To read from a texture in a vertex shader ("VTF") in steps (3/4), you likely need to use a floating point texture format such as D3DFMT_R16F or D3DFMT_A16B16G16R16F.

* Step 2 is automatic in D3D9 if you created that texture with the D3DUSAGE_AUTOGENMIPMAP flag.


#1Hodgman

Posted 04 June 2014 - 04:17 PM

In post-processing:
1) read the depth of each pixel, use it to reconstruct position, test if the position is within your bounding box. Return white for true and black for false.
2) generate MIPS for this black/white texture.
3) render your optional "if" post-processing quad. In the vertex shader, read from the 1x1 pixel mipmap of the black/white texture. If some threshold isn't met (tex>0 for any pixels from the box visible, tex==1 for all visible pixels are in the box), then multiple the vertex positions by zero, which hides the quad.
4) render an alternative "else" post-processing quad. In the vertex shader, perform the same test, but inverted (using 1-tex).

PARTNERS