title: direct3d alphablend and pixel shaders
body: <p>I have a 2D scene, 2 textures set as render targets, and a vertex buffer.</p>
  
  <p>first texture is filtered out by contrast/brightness pixel shader, the second acts as a menu, which I would not like to be processed by the same shader, but want it to be alphablended with the first one. </p>
  
  <p>Everything runs fine, until I go to extreme values for brightness/contrast which looks like the fade out effect when changing the the second one and it stops to redraw at all on very extreme ones, though the data is always fed to the first one.</p>
  
  <p>Disabling AlphaBlendnable corrects it, but I loose alpha blending... Any way to clean the buffers prior to applying pixel shaders? Any help appreciated.</p>
  
  <p>pixel shader code:</p>
  
  <pre><code>float offsetBrightness = 0.0f; \
  float offsetContrast   = 0.0f; \
  float4 PSBrightnessContrast(float2 inCoord : TEXCOORD0) : COLOR0\
  {\
      float4 color = tex2D( screen, inCoord.xy); \
      color = color + offsetBrightness; \
      color = color * (1.0 + offsetContrast); \
      return saturate( color ); \
  }\
  </code></pre>
  
  <p>Rendering code</p>
  
  <pre><code>// Begin the scene
      hr = IDirect3DDevice9_BeginScene(d3ddev);
    if (FAILED(hr)) 
      throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
  
  // Render the vertex buffer contents
  hr = IDirect3DDevice9_SetStreamSource(d3ddev, 0, d3dvtc, 0, sizeof(CUSTOMVERTEX));
  if (FAILED(hr)) {
      IDirect3DDevice9_EndScene(d3ddev);
      throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
  }
  
  // we use FVF instead of vertex shader
  hr = IDirect3DDevice9_SetFVF(d3ddev, D3DFVF_CUSTOMVERTEX);
  if (FAILED(hr)) {
      IDirect3DDevice9_EndScene(d3ddev);
      throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
  }
  
  //apply shaders
  
  UINT shaderPasses;
  if(d3dxShader)
  {
      hr = d3dxShader-&gt;Begin( &amp;shaderPasses, 0 );
      if (FAILED(hr))
          throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
  }
  else
      shaderPasses = 1;
  
  for( UINT uPass = 0; uPass &lt; shaderPasses; ++uPass )
  {
      if(d3dxShader)
      {
          hr = d3dxShader-&gt;BeginPass(uPass);
          if (FAILED(hr))
              throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
      }
  
      hr = IDirect3DDevice9_SetTexture(d3ddev, 0, (LPDIRECT3DBASETEXTURE9)d3dtex);
      if (FAILED(hr)) {
          IDirect3DDevice9_EndScene(d3ddev);
          throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
      }
  
      // draw rectangle
      hr = IDirect3DDevice9_DrawPrimitive(d3ddev, D3DPT_TRIANGLEFAN, 0, 2);
      if (FAILED(hr)) {
          IDirect3DDevice9_EndScene(d3ddev);
          throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
      }
  
      if(d3dxShader)
      {
          hr = d3dxShader-&gt;EndPass();
          if (FAILED(hr))
              throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
      }
  }
  
  if(d3dxShader)
  {
      hr = d3dxShader-&gt;End();
      if (FAILED(hr))
          throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
  }
  
  // Render the vertex buffer contents
  hr = IDirect3DDevice9_SetStreamSource(d3ddev, 0, d3dvtc, 0, sizeof(CUSTOMVERTEX));
  if (FAILED(hr)) {
      IDirect3DDevice9_EndScene(d3ddev);
      throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
  }
  
  // we use FVF instead of vertex shader
  hr = IDirect3DDevice9_SetFVF(d3ddev, D3DFVF_CUSTOMVERTEX);
  if (FAILED(hr)) {
      IDirect3DDevice9_EndScene(d3ddev);
      throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
  }
  
  // Setup our texture. Using textures introduces the texture stage states,
  // which govern how textures get blended together (in the case of multiple
  // textures) and lighting information. In this case, we are modulating
  // (blending) our texture with the diffuse color of the vertices.
  hr = IDirect3DDevice9_SetTexture(d3ddev, 0, (LPDIRECT3DBASETEXTURE9)d3dtex2);
  if (FAILED(hr)) {
      IDirect3DDevice9_EndScene(d3ddev);
      throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
  }
  
  // draw rectangle
  hr = IDirect3DDevice9_DrawPrimitive(d3ddev, D3DPT_TRIANGLEFAN, 0, 2);
  if (FAILED(hr)) {
      IDirect3DDevice9_EndScene(d3ddev);
      throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );
  }
  
  // End the scene
  hr = IDirect3DDevice9_EndScene(d3ddev);
  if (FAILED(hr)) 
      throw FatalException( DXGetErrorDescription(hr), _T(__FILE__), __LINE__ );    
  </code></pre>