コード例 #1
0
ファイル: AtgPostProcess.cpp プロジェクト: 0xdeafcafe/Yrs2013
//--------------------------------------------------------------------------------------
// Name: Downsample2x2Texture()
// Desc: Scale down pSrcTexture by 1/2 x 1/2 and place the result in pDstTexture
//--------------------------------------------------------------------------------------
VOID PostProcess::Downsample2x2Texture( LPDIRECT3DTEXTURE9 pSrcTexture,
                                        LPDIRECT3DTEXTURE9 pDstTexture,
                                        DWORD dwEdramOffset )
{
    // Make sure that the required shaders and objects exist
    assert( m_pDownScale2x2PS );
    assert( pSrcTexture && pDstTexture );

    XGTEXTURE_DESC SrcDesc;
    XGGetTextureDesc( pSrcTexture, 0, &SrcDesc );

    // Create and set a render target
    D3DSURFACE_PARAMETERS surfaceParams = { 0 };
    surfaceParams.Base = dwEdramOffset;
    PushRenderTarget( 0L, CreateRenderTarget( pDstTexture, &surfaceParams ) );

    XMVECTOR avSampleOffsets[MAX_SAMPLES];
    GetSampleOffsets_DownScale2x2( SrcDesc.Width, SrcDesc.Height, avSampleOffsets );
    g_pd3dDevice->SetPixelShaderConstantF( PSCONST_avSampleOffsets, ( FLOAT* )avSampleOffsets, MAX_SAMPLES );

    // Create an exact 1/2 x 1/2 copy of the source texture
    g_pd3dDevice->SetPixelShader( m_pDownScale2x2PS );

    g_pd3dDevice->SetTexture( 0, pSrcTexture );
    g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT );
    g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP );
    g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP );

    // TODO: This should use border addressing with a black border!
    //m_pStarSourceTexture->Format.ClampX      = GPUCLAMP_CLAMP_TO_BORDER;
    //m_pStarSourceTexture->Format.ClampY      = GPUCLAMP_CLAMP_TO_BORDER;
    //m_pStarSourceTexture->Format.BorderColor = GPUBORDERCOLOR_ABGR_BLACK;
    //g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER );
    //g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER );

    // Draw a fullscreen quad to sample the RT
    DrawFullScreenQuad();

    g_pd3dDevice->Resolve( D3DRESOLVE_RENDERTARGET0, NULL, pDstTexture, NULL,
                           0, 0, NULL, 1.0f, 0L, NULL );

    // Cleanup and return
    PopRenderTarget( 0L )->Release();
    g_pd3dDevice->SetPixelShader( NULL );
}
コード例 #2
0
ファイル: HDRLight.cpp プロジェクト: YameteYY/DreamEngine
void HDRLight::_brightSource_ToBloomSource()
{
	D3DXVECTOR2 avSampleOffsets[MAX_SAMPLES];

	// Get the new render target surface
	PDIRECT3DSURFACE9 pSurfBloomSource;
	g_pTexBloomSource->GetSurfaceLevel( 0, &pSurfBloomSource );

	// Get the rectangle describing the sampled portion of the source texture.
	// Decrease the rectangle to adjust for the single pixel black border.
	RECT rectSrc;
	GetTextureRect( g_pTexBrightPass, &rectSrc );
	InflateRect( &rectSrc, -1, -1 );

	// Get the destination rectangle.
	// Decrease the rectangle to adjust for the single pixel black border.
	RECT rectDest;
	GetTextureRect( g_pTexBloomSource, &rectDest );
	InflateRect( &rectDest, -1, -1 );

	// Get the correct texture coordinates to apply to the rendered quad in order 
	// to sample from the source rectangle and render into the destination rectangle
	CoordRect coords;
	GetTextureCoords( g_pTexBrightPass, &rectSrc, g_pTexBloomSource, &rectDest, &coords );

	// Get the sample offsets used within the pixel shader
	D3DSURFACE_DESC desc;
	g_pTexBrightPass->GetLevelDesc( 0, &desc );

	GetSampleOffsets_DownScale2x2( desc.Width, desc.Height, avSampleOffsets );
	g_HDREffect->SetValue( "g_avSampleOffsets", avSampleOffsets, sizeof( avSampleOffsets ) );

	// Create an exact 1/2 x 1/2 copy of the source texture
	g_HDREffect->SetTechnique( "DownScale2x2" );

	g_pd3dDevice->SetRenderTarget( 0, pSurfBloomSource );
	g_pd3dDevice->SetTexture( 0, g_pTexBrightPass );
	g_pd3dDevice->SetScissorRect( &rectDest );
	g_pd3dDevice->SetRenderState( D3DRS_SCISSORTESTENABLE, TRUE );
	g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT );
	g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP );
	g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP );

	UINT uiPassCount, uiPass;
	g_HDREffect->Begin( &uiPassCount, 0 );

	for( uiPass = 0; uiPass < uiPassCount; uiPass++ )
	{
		g_HDREffect->BeginPass( uiPass );

		// Draw a fullscreen quad
		DrawFullScreenQuad(g_pd3dDevice, coords.fLeftU,coords.fTopV,coords.fRightU,coords.fBottomV );

		g_HDREffect->EndPass();
	}

	g_HDREffect->End();
	g_pd3dDevice->SetRenderState( D3DRS_SCISSORTESTENABLE, FALSE );

	SAFE_RELEASE( pSurfBloomSource );
}