   Transparency MultiSampling Problem (Artifacts)
  I am trying to make a some decent transparent billboarded models and implement them and I could use a little help. I am getting some strange artifacts when running in windowed mode, seems to work just fine when I go full screen. I am wondering if it has something to do with code I wrote. A couple notes : I am not using DXUT library and I will show the relevant code, hopefully some one can look at it and go " oh you forgot blah blah blah ". Please ignore commonented crap, I have been just throwing stuff against the wall and hoping it sticks. Also the billboards are run through a simple shader and I am using DirectX 9.0 November 2007 SDK. I would appreciate any help here, starting to get frustrating and I would like to get it working.Here is a link to a picture that shows the problem.www.captgoat.comThe picture is on the front page.(yes my site is underconstruction and right now its something that my GF made LOL )//-----------------------------------// Hopefully this shows up formatted correctly, if not send me and email and // tell me how to format this better so its readable, jzaharko@gmail.com//-----------------------------------HRESULT InitD3D( HWND hWnd ){    // Create the D3D object.    if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )   return E_FAIL;    // Set up the structure used to create the D3DDevice    D3DPRESENT_PARAMETERS d3dpp;    ZeroMemory( &d3dpp, sizeof(d3dpp) );    d3dpp.Windowed = TRUE;d3dpp.BackBufferWidth = SCREEN_WIDTH;d3dpp.BackBufferHeight = SCREEN_HEIGHT;d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;d3dpp.EnableAutoDepthStencil = TRUE;d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;DWORD MSQualityLevels = 0;if( SUCCEEDED( g_pD3D->CheckDeviceMultiSampleType( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,  D3DFMT_X8R8G8B8, d3dpp.Windowed,  D3DMULTISAMPLE_4_SAMPLES, &MSQualityLevels) ) ){if( SUCCEEDED( g_pD3D->CheckDeviceMultiSampleType( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,  D3DFMT_D24S8, d3dpp.Windowed,  D3DMULTISAMPLE_4_SAMPLES, &MSQualityLevels) ) ){d3dpp.MultiSampleQuality = 0;d3dpp.MultiSampleType = D3DMULTISAMPLE_4_SAMPLES;d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;}}    // Create the D3DDevice    if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,  D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE,   &d3dpp, &g_pd3dDevice ) ) )    {   return E_FAIL;    }// Turn AA on    g_pd3dDevice->SetRenderState( D3DRS_MULTISAMPLEANTIALIAS, true );// Turn off culling, so we see the front and back of the triangleg_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );// Turn on the zbuffer    g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, true );    // Turn off D3D lighting, since we are providing our own vertex colors    g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );if( FAILED (g_pD3D->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, 0, D3DRTYPE_SURFACE, (D3DFORMAT)MAKEFOURCC('A', 'T', 'O', 'C') ) ) ){MessageBox(NULL, "MSAA FAILED", "Main.exe", MB_OK);return E_FAIL;}// Screen Stats Objectg_ScreenStats = new ScreenStats( g_pd3dDevice );// Grass Objectg_GrassObject = new Grass( g_pd3dDevice );g_GrassObject->CreateBillboard();cntsPerSec = 0;QueryPerformanceFrequency((LARGE_INTEGER*)&cntsPerSec);secsPerCnt = 1.0f / (float)cntsPerSec;prevTimeStamp = 0;QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);// Set up the Projection MatrixD3DXMatrixPerspectiveFovLH( &g_matProjection, D3DX_PI/4, (FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT, 1.0f, 100.0f );g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &g_matProjection );    return S_OK;}//--------------------------------------// Important part of the render function//--------------------------------------g_pd3dDevice->SetRenderState( D3DRS_ADAPTIVETESS_Y, (D3DFORMAT)MAKEFOURCC('A', 'T', 'O', 'C') );g_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, true );g_pd3dDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);g_pd3dDevice->SetRenderState(D3DRS_ALPHAREF, 0x0000000F);// Begin the scene    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) ) {// Render the Grass ObjectD3DXHANDLE hTechnique = g_GrassShader->GetTechniqueByName( "Grass" );g_GrassShader->SetTechnique( hTechnique );g_GrassShader->Begin( &nPasses, 0 );g_GrassShader->SetMatrix( "matWorldViewProjection", &matWorldViewProjection );for( iPass = 0; iPass < nPasses; iPass++ ) {g_GrassShader->BeginPass( iPass );g_GrassShader->SetTexture( "DiffuseMap", g_Shrub1Texture );g_GrassShader->CommitChanges();g_GrassObject->DrawGrass();g_GrassShader->EndPass();}g_GrassShader->End();// Render the Tree MeshD3DXMatrixRotationY( &matRotation, angle);D3DXMatrixTranslation(&matTranslate, 1.0f,0.0f,0.0f);D3DXMatrixMultiply( &g_matWorld, &matRotation, &matTranslate );g_pd3dDevice->SetTransform( D3DTS_WORLD, &g_matWorld);matWorldViewProjection = g_matWorld * g_matView * g_matProjection;hTechnique = g_TreeShader->GetTechniqueByName("Grass");g_TreeShader->SetTechnique(hTechnique);g_TreeShader->Begin( &nPasses, 0 );g_TreeShader->SetMatrix( "matWorldViewProjection", &matWorldViewProjection );for( iPass = 0; iPass < nPasses; iPass++ ) {g_TreeShader->BeginPass( iPass );for( DWORD m = 0; m < g_dwNumMats; m++ ) {//g_pd3dDevice->SetMaterial( &g_pMeshMats[m] );//g_pd3dDevice->SetTexture( 0, g_pMeshText[m] );g_TreeShader->SetTexture( "DiffuseMap", g_pMeshText[m] );g_TreeShader->CommitChanges();g_pMesh->DrawSubset(m);}g_TreeShader->EndPass();}g_TreeShader->End();g_pd3dDevice->SetRenderState(D3DRS_ADAPTIVETESS_Y, D3DFMT_UNKNOWN);g_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, false);   
  bump   