   Render to target problem
  I started my post process learning a few days ago and so far have developed a simple post process class that will apply basic blur and whatnot.  The problem I have run into is quite odd to me.  The edges of everything (mostly things that have some kind of shader applied to them) seem to become darker.  This problem has nothing to do with the post effects I have added as all I am testing at the moment is just rendering to a different target then drawing a quad to the original buffer.  It's a bit hard to explain but I have a few screen shots that might help.#pragma once#include <windows.h>// Header File For Windows#include <math.h>// Math Library Header File#include <stdio.h>// Header File For Standard Input/Output#include <mmsystem.h>#include <fstream>#include <sstream>#include <fstream>#include <cctype>#include <iomanip>#include <cmath>#include <iostream>#include <string>#include <vector>#include "GhostVars.h"typedef struct{    D3DXVECTOR4 pos;    D3DCOLOR clr;    D3DXVECTOR2 tex1;   enum FVF{FVF_Flags = D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1};}SCREEN_VERTEX;typedef struct{LPD3DXEFFECT pEffect;D3DXHANDLE worldViewProj;D3DXHANDLE Texture;} cPostEffect;class cPostProcess{public:cPostProcess(void);~cPostProcess(void);void SetEnable(bool on) { ApplyPostProcess = on; }void ToggleEnable() { ApplyPostProcess = !ApplyPostProcess; }void Init();void SetupFullscreenQuad();BOOL AddEffect(std::string FXName);void PerformPostProcess();void Begin();void End();void Apply();private:SCREEN_VERTEX Vertex[4];LPDIRECT3DTEXTURE9 pFullScreenRenderTarget[2];LPDIRECT3DSURFACE9 pFullScreenRenderTargetSurf[2];LPDIRECT3DSURFACE9 pOriginalRenderTarget;IDirect3DVertexBuffer9* vBuffer;ID3DXEffectPool *EffectPool;int rTarget;cPostEffect *PostEffect;int Size;int i;bool ApplyPostProcess;};#include "cPostProcess.h"#include "cGhost.h"#include "cGame.h"cPostProcess::cPostProcess(void){rTarget = 0;pFullScreenRenderTarget[0] = NULL;pFullScreenRenderTargetSurf[0] = NULL;pFullScreenRenderTarget[1] = NULL;pFullScreenRenderTargetSurf[1] = NULL;PostEffect = NULL;EffectPool = NULL;vBuffer = NULL;Size = 0;ApplyPostProcess = true;}cPostProcess::~cPostProcess(void){SAFE_RELEASE(pFullScreenRenderTarget[0]);SAFE_RELEASE(pFullScreenRenderTargetSurf[0]);SAFE_RELEASE(pFullScreenRenderTarget[1]);SAFE_RELEASE(pFullScreenRenderTargetSurf[1]);SAFE_RELEASE(vBuffer);SAFE_RELEASE(EffectPool);for (int i = 0; i < Size; ++i){SAFE_RELEASE(PostEffect.pEffect);}}void cPostProcess :: Init(){D3DXCreateTexture( d3dDevice, Ghost->WinInfo->init.width, Ghost->WinInfo->init.height,   1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,    D3DPOOL_DEFAULT, &pFullScreenRenderTarget[0] );pFullScreenRenderTarget[0]->GetSurfaceLevel( 0, &pFullScreenRenderTargetSurf[0] );D3DXCreateTexture( d3dDevice, Ghost->WinInfo->init.width, Ghost->WinInfo->init.height,   1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,    D3DPOOL_DEFAULT, &pFullScreenRenderTarget[1] );pFullScreenRenderTarget[1]->GetSurfaceLevel( 0, &pFullScreenRenderTargetSurf[1] );    d3dDevice->GetRenderTarget( 0, &pOriginalRenderTarget );    d3dDevice->SetRenderTarget( 0, pFullScreenRenderTargetSurf[0] );    d3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0 );d3dDevice->SetRenderTarget( 0, pFullScreenRenderTargetSurf[1] );    d3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0 );    d3dDevice->SetRenderTarget( 0, pOriginalRenderTarget );SetupFullscreenQuad();d3dDevice->CreateVertexBuffer(sizeof(SCREEN_VERTEX) * 4, D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, SCREEN_VERTEX::FVF_Flags, D3DPOOL_DEFAULT, &vBuffer, NULL);}void cPostProcess :: SetupFullscreenQuad(){    D3DSURFACE_DESC desc;    pFullScreenRenderTargetSurf[0]->GetDesc( &desc );    FLOAT fWidth5 = ( FLOAT )Ghost->WinInfo->init.width - 0.5f;    FLOAT fHeight5 = ( FLOAT )Ghost->WinInfo->init.height - 0.5f;    FLOAT fTexWidth1 = ( FLOAT )Ghost->WinInfo->init.width / ( FLOAT )desc.Width;    FLOAT fTexHeight1 = ( FLOAT )Ghost->WinInfo->init.height / ( FLOAT )desc.Height;    // Fill in the vertex values    Vertex[0].pos = D3DXVECTOR4( fWidth5, -0.5f, 0.0f, 1.0f );    Vertex[0].clr = D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f );    Vertex[0].tex1 = D3DXVECTOR2( fTexWidth1, 0.0f );    Vertex[1].pos = D3DXVECTOR4( fWidth5, fHeight5, 0.0f, 1.0f );    Vertex[1].clr = D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f );    Vertex[1].tex1 = D3DXVECTOR2( fTexWidth1, fTexHeight1 );    Vertex[2].pos = D3DXVECTOR4( -0.5f, -0.5f, 0.0f, 1.0f );    Vertex[2].clr = D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f );    Vertex[2].tex1 = D3DXVECTOR2( 0.0f, 0.0f );    Vertex[3].pos = D3DXVECTOR4( -0.5f, fHeight5, 0.0f, 1.0f );    Vertex[3].clr = D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f );    Vertex[3].tex1 = D3DXVECTOR2( 0.0f, fTexHeight1 );}BOOL cPostProcess :: AddEffect(std::string FXName){if (Size == 0)PostEffect = new cPostEffect();else{cPostEffect *tmp = new cPostEffect[Size + 1];memcpy(&tmp[0], &PostEffect[0], sizeof(cPostEffect) * Size);if (Size > 1)delete [] PostEffect;elsedelete PostEffect;PostEffect = tmp;}HRESULT hr;LPD3DXBUFFER pBufferErrors = NULL;hr = D3DXCreateEffectFromFile( d3dDevice,    FXName.c_str(),   NULL,    NULL,    D3DXSHADER_OPTIMIZATION_LEVEL3,    NULL,    &PostEffect[Size].pEffect,    &pBufferErrors );if( FAILED(hr) ){LPVOID pCompilErrors = pBufferErrors->GetBufferPointer();MessageBox(NULL, (const char*)pCompilErrors, "Fx Compile Error",MB_OK|MB_ICONEXCLAMATION);return FALSE;}PostEffect[Size].pEffect->SetTechnique(PostEffect[Size].pEffect->GetTechnique(0));PostEffect[Size].Texture = PostEffect[Size].pEffect->GetParameterByName(NULL, "g_txSrcColor");++Size;return TRUE;}void cPostProcess :: PerformPostProcess(){SCREEN_VERTEX *SVert;vBuffer->Lock(0, 4 * sizeof(SCREEN_VERTEX), (VOID**)&SVert, D3DLOCK_DISCARD);CopyMemory( SVert, Vertex, sizeof( SCREEN_VERTEX ) * 4);vBuffer->Unlock();while (i < Size){d3dDevice->BeginScene();PostEffect.pEffect->SetTexture(PostEffect.Texture, pFullScreenRenderTarget[rTarget]);UINT uPasses;PostEffect.pEffect->Begin( &uPasses, 0 );    for( int uPass = 0; uPass < uPasses; ++uPass ){PostEffect.pEffect->BeginPass( uPass );d3dDevice->SetStreamSource( 0, vBuffer, 0, sizeof( SCREEN_VERTEX ) );d3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);PostEffect.pEffect->EndPass();} PostEffect.pEffect->End();d3dDevice->SetRenderTarget( 0, pFullScreenRenderTargetSurf[rTarget] );d3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0 );d3dDevice->EndScene();rTarget = !rTarget;++i;};}void cPostProcess :: Begin(){if (!ApplyPostProcess)return;d3dDevice->SetRenderTarget( 0, pFullScreenRenderTargetSurf[1] );    d3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0 );d3dDevice->SetRenderTarget( 0, pFullScreenRenderTargetSurf[0] );    d3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0 );}void cPostProcess :: End(){if (!ApplyPostProcess)return;d3dDevice->EndScene();d3dDevice->SetRenderTarget( 0, pFullScreenRenderTargetSurf[1] );rTarget = 0;i = 0;}void cPostProcess :: Apply(){if (!ApplyPostProcess)return;PerformPostProcess();d3dDevice->BeginScene();d3dDevice->SetRenderTarget( 0, pOriginalRenderTarget );d3dDevice->SetTexture(0, pFullScreenRenderTarget[rTarget]); d3dDevice->SetFVF( SCREEN_VERTEX::FVF_Flags );d3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, Vertex, sizeof( SCREEN_VERTEX ) );d3dDevice->SetVertexShader(NULL);}Left = Rendered normallyRight = Rendered with quad from different render targetAny help would be greatly appriciated : )Jake   
  Can you please replace the images with images of a smaller size?   