Esempio n. 1
0
void CFarTextureHandler::DrawFarTexture(const CSolidObject* obj, CVertexArray* va)
{
	const int farTextureNum = cache[obj->team][obj->model->id];

	// not found in the atlas
	if (farTextureNum <= 0)
		return;

	const float3 interPos = obj->drawPos + UpVector * obj->model->height * 0.5f;

	// indicates the orientation to draw
	static const int USHRT_MAX_ = (1 << 16);
	const int orient_step = USHRT_MAX_ / numOrientations;

	int orient = GetHeadingFromVector(-camera->forward.x, -camera->forward.z) - obj->heading;
		orient += USHRT_MAX_;          // make it positive only
		orient += (orient_step >> 1);  // we want that frontdir is from -orient_step/2 upto orient_step/2
		orient %= USHRT_MAX_;          // we have an angle so it's periodical
		orient /= orient_step;         // get the final direction index

	const float iconSizeX = float(this->iconSizeX) / texSizeX;
	const float iconSizeY = float(this->iconSizeY) / texSizeY;
	const float2 texcoords = GetTextureCoords(farTextureNum - 1, orient);

	const float3 curad = camera->up *    obj->model->radius;
	const float3 crrad = camera->right * obj->model->radius;

	va->AddVertexQT(interPos - curad + crrad, texcoords.x, texcoords.y );
	va->AddVertexQT(interPos + curad + crrad, texcoords.x, texcoords.y + iconSizeY);
	va->AddVertexQT(interPos + curad - crrad, texcoords.x + iconSizeX, texcoords.y + iconSizeY);
	va->AddVertexQT(interPos - curad - crrad, texcoords.x + iconSizeX, texcoords.y );
}
Esempio n. 2
0
void HDRLight::_scene_to_sceneScaled()
{
	PDIRECT3DSURFACE9 pSurfScaledScene = NULL;
	g_pTexSceneScaled->GetSurfaceLevel( 0, &pSurfScaledScene );
	
	g_HDREffect->SetTechnique("DownScale4x4");

	RECT rectSrc;
	rectSrc.left = 0;
	rectSrc.top = 0;
	rectSrc.right = g_D3dpp.BackBufferWidth;
	rectSrc.bottom = g_D3dpp.BackBufferHeight;

	CoordRect coords;
	GetTextureCoords( g_pTexScene, &rectSrc, g_pTexSceneScaled, NULL, &coords );
	D3DXVECTOR2 avSampleOffsets[MAX_SAMPLES];
	GetSampleOffsets_DownScale4x4(g_D3dpp.BackBufferWidth,g_D3dpp.BackBufferHeight,avSampleOffsets);
	g_HDREffect->SetValue( "g_avSampleOffsets", avSampleOffsets, sizeof( avSampleOffsets ) );

	g_pd3dDevice->SetRenderTarget( 0, pSurfScaledScene );
	g_pd3dDevice->SetTexture( 0, g_pTexScene );
	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();
	SAFE_RELEASE(pSurfScaledScene);
}
Esempio n. 3
0
//-----------------------------------------------------------------------------
// Name: Scene_To_SceneScaled()
// Desc: m_pTexScene�� 1/4�� �ؼ� m_pTexSceneScale�� �ִ´�
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::Scene_To_SceneScaled()
{
    // �ʰ��� �κп� �߽ɺκ��� �����Ѵ�
    CoordRect coords;
    RECT rectSrc;
    rectSrc.left   = (m_d3dsdBackBuffer.Width  - m_dwCropWidth ) / 2;
    rectSrc.top    = (m_d3dsdBackBuffer.Height - m_dwCropHeight) / 2;
    rectSrc.right  = rectSrc.left + m_dwCropWidth;
    rectSrc.bottom = rectSrc.top  + m_dwCropHeight;
    // ������Ÿ�ٿ� ���߿� �ؽ�ó��ǥ ���
    GetTextureCoords( m_pTexScene, &rectSrc, m_pTexSceneScaled, NULL, &coords );

    // �ֺ� 16�ؼ��� ���ø������� �ؼ�
	// 0.5�� �߽ɿ� ���߱����� ����
    int index=0;
    D3DXVECTOR2 offsets[MAX_SAMPLES];

    for( int y=0; y < 4; y++ ) {
        for( int x=0; x < 4; x++ ) {
            offsets[ index ].x = (x - 1.5f) / m_d3dsdBackBuffer.Width;
            offsets[ index ].y = (y - 1.5f) / m_d3dsdBackBuffer.Height;
            index++;
        }
    }
	m_pEffect->SetValue("g_avSampleOffsets", offsets, sizeof(offsets));
    
	// 16�ؼ��� ���ø��ؼ� �� ��հ��� ��ҹ��ۿ� ����ϳ�
    m_pd3dDevice->SetRenderTarget( 0, m_pSurfSceneScaled );
    m_pEffect->SetTechnique("DownScale4x4");
	m_pEffect->Begin(NULL, 0);
	m_pEffect->Pass(0);
    m_pd3dDevice->SetTexture( 0, m_pTexScene );
	DrawFullScreenQuad( coords.u0, coords.v0, coords.u1, coords.v1 );
	m_pEffect->End();

    return S_OK;
}
Esempio n. 4
0
//-----------------------------------------------------------------------------
// Name: BrightPass_To_StarSource
// Desc: ��ҹ��ۿ� �����Ҷ� ��������� �����ϱ� ���ؼ�
//       ���콺�� �����⸦ �Ѵ�
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::BrightPass_To_StarSource()
{
    // ����� ���� ������ ���� �������� ũ�� ����
    D3DSURFACE_DESC desc;
	m_pTexStarSource->GetLevelDesc( 0, &desc );
	RECT rectDest = {0,0,desc.Width,desc.Height};
    InflateRect( &rectDest, -1, -1 );// ����Ұ��� ũ�⸦ 1��ŭ ���δ�
    m_pd3dDevice->SetRenderState( D3DRS_SCISSORTESTENABLE, TRUE );
    m_pd3dDevice->SetScissorRect( &rectDest );

    // �ؽ�ó��ǥ ����
    CoordRect coords;
    GetTextureCoords( m_pTexBrightPass, NULL, m_pTexStarSource,
					&rectDest, &coords );

    // ���� �̹����� ũ��κ��� ���콺��������� ���
    D3DXVECTOR2 offsets[MAX_SAMPLES];
    D3DXVECTOR4 weights[MAX_SAMPLES];
    m_pTexBrightPass->GetLevelDesc( 0, &desc );
    GetGaussBlur5x5( desc.Width, desc.Height, offsets, weights );
    m_pEffect->SetValue("g_avSampleOffsets", offsets, sizeof(offsets));
    m_pEffect->SetValue("g_avSampleWeights", weights, sizeof(weights));
    
    // ���콺 ������
    m_pEffect->SetTechnique("GaussBlur5x5");
    m_pd3dDevice->SetRenderTarget( 0, m_pSurfStarSource );
    m_pEffect->Begin(NULL, 0);
    m_pEffect->Pass(0);
    m_pd3dDevice->SetTexture( 0, m_pTexBrightPass );
	DrawFullScreenQuad( coords.u0, coords.v0, coords.u1, coords.v1 );
    m_pEffect->End();

    m_pd3dDevice->SetRenderState( D3DRS_SCISSORTESTENABLE, FALSE );

    return S_OK;
}
Esempio n. 5
0
/*
void HDRLight::_starSource_To_BloomSource()
{
	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_pTexStarSource, &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_pTexStarSource, &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_pTexStarSource );
	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( coords.fLeftU,coords.fTopV,coords.fRightU,coords.fBottomV );

		g_HDREffect->EndPass();
	}

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

	SAFE_RELEASE( pSurfBloomSource );
}*/
void HDRLight::_renderBloom()
{
	UINT uiPassCount, uiPass;
	int i = 0;


	D3DXVECTOR2 avSampleOffsets[MAX_SAMPLES];
	FLOAT afSampleOffsets[MAX_SAMPLES];
	D3DXVECTOR4 avSampleWeights[MAX_SAMPLES];

	PDIRECT3DSURFACE9 pSurfScaledHDR;
	g_pTexSceneScaled->GetSurfaceLevel( 0, &pSurfScaledHDR );

	PDIRECT3DSURFACE9 pSurfBloom;
	g_apTexBloom[0]->GetSurfaceLevel( 0, &pSurfBloom );

	PDIRECT3DSURFACE9 pSurfHDR;
	g_pTexScene->GetSurfaceLevel( 0, &pSurfHDR );

	PDIRECT3DSURFACE9 pSurfTempBloom;
	g_apTexBloom[1]->GetSurfaceLevel( 0, &pSurfTempBloom );

	PDIRECT3DSURFACE9 pSurfBloomSource;
	g_apTexBloom[2]->GetSurfaceLevel( 0, &pSurfBloomSource );

	// Clear the bloom texture
	g_pd3dDevice->ColorFill( pSurfBloom, NULL, D3DCOLOR_ARGB( 0, 0, 0, 0 ) );


	RECT rectSrc;
	GetTextureRect( g_pTexBloomSource, &rectSrc );
	InflateRect( &rectSrc, -1, -1 );

	RECT rectDest;
	GetTextureRect( g_apTexBloom[2], &rectDest );
	InflateRect( &rectDest, -1, -1 );

	CoordRect coords;
	GetTextureCoords( g_pTexBloomSource, &rectSrc, g_apTexBloom[2], &rectDest, &coords );

	D3DSURFACE_DESC desc;
	g_pTexBloomSource->GetLevelDesc( 0, &desc );


	g_HDREffect->SetTechnique( "GaussBlur5x5" );

	GetSampleOffsets_GaussBlur5x5( desc.Width, desc.Height, avSampleOffsets, avSampleWeights, 1.0f );

	g_HDREffect->SetValue( "g_avSampleOffsets", avSampleOffsets, sizeof( avSampleOffsets ) );
	g_HDREffect->SetValue( "g_avSampleWeights", avSampleWeights, sizeof( avSampleWeights ) );

	g_pd3dDevice->SetRenderTarget( 0, pSurfBloomSource );
	g_pd3dDevice->SetTexture( 0, g_pTexBloomSource );
	g_pd3dDevice->SetScissorRect( &rectDest );
	g_pd3dDevice->SetRenderState( D3DRS_SCISSORTESTENABLE, TRUE );
	g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT );
	g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT );


	g_HDREffect->Begin( &uiPassCount, 0 );

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

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

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

	g_apTexBloom[2]->GetLevelDesc( 0, &desc );

	GetSampleOffsets_Bloom( desc.Width, afSampleOffsets, avSampleWeights, 3.0f, 2.0f );
	for( i = 0; i < MAX_SAMPLES; i++ )
	{
		avSampleOffsets[i] = D3DXVECTOR2( afSampleOffsets[i], 0.0f );
	}


	g_HDREffect->SetTechnique( "Bloom" );
	g_HDREffect->SetValue( "g_avSampleOffsets", avSampleOffsets, sizeof( avSampleOffsets ) );
	g_HDREffect->SetValue( "g_avSampleWeights", avSampleWeights, sizeof( avSampleWeights ) );

	g_pd3dDevice->SetRenderTarget( 0, pSurfTempBloom );
	g_pd3dDevice->SetTexture( 0, g_apTexBloom[2] );
	g_pd3dDevice->SetScissorRect( &rectDest );
	g_pd3dDevice->SetRenderState( D3DRS_SCISSORTESTENABLE, TRUE );
	g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT );
	g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT );


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

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

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


	g_apTexBloom[1]->GetLevelDesc( 0, &desc );

	GetSampleOffsets_Bloom( desc.Height, afSampleOffsets, avSampleWeights, 3.0f, 2.0f );
	for( i = 0; i < MAX_SAMPLES; i++ )
	{
		avSampleOffsets[i] = D3DXVECTOR2( 0.0f, afSampleOffsets[i] );
	}


	GetTextureRect( g_apTexBloom[1], &rectSrc );
	InflateRect( &rectSrc, -1, -1 );

	GetTextureCoords( g_apTexBloom[1], &rectSrc, g_apTexBloom[0], NULL, &coords );


	g_HDREffect->SetTechnique( "Bloom" );
	g_HDREffect->SetValue( "g_avSampleOffsets", avSampleOffsets, sizeof( avSampleOffsets ) );
	g_HDREffect->SetValue( "g_avSampleWeights", avSampleWeights, sizeof( avSampleWeights ) );

	g_pd3dDevice->SetRenderTarget( 0, pSurfBloom );
	g_pd3dDevice->SetTexture( 0, g_apTexBloom[1] );
	g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT );
	g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT );


	g_HDREffect->Begin( &uiPassCount, 0 );

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

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

		g_HDREffect->EndPass();
	}
	g_HDREffect->End();

	SAFE_RELEASE( pSurfBloomSource );
	SAFE_RELEASE( pSurfTempBloom );
	SAFE_RELEASE( pSurfBloom );
	SAFE_RELEASE( pSurfHDR );
	SAFE_RELEASE( pSurfScaledHDR );
}
Esempio n. 6
0
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 );
}
Esempio n. 7
0
void HDRLight::_sceneScaled_To_BrightPass()
{
	D3DXVECTOR2 avSampleOffsets[MAX_SAMPLES];
	D3DXVECTOR4 avSampleWeights[MAX_SAMPLES];


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


	D3DSURFACE_DESC desc;
	g_pTexSceneScaled->GetLevelDesc( 0, &desc );

	// 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_pTexSceneScaled, &rectSrc );
	InflateRect( &rectSrc, -1, -1 );

	// Get the destination rectangle.
	// Decrease the rectangle to adjust for the single pixel black border.
	RECT rectDest;
	GetTextureRect( g_pTexBrightPass, &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_pTexSceneScaled, &rectSrc, g_pTexBrightPass, &rectDest, &coords );

	// The bright-pass filter removes everything from the scene except lights and
	// bright reflections
	g_HDREffect->SetTechnique( "BrightPassFilter" );

	g_pd3dDevice->SetRenderTarget( 0, pSurfBrightPass );
	g_pd3dDevice->SetTexture( 0, g_pTexSceneScaled );
	g_pd3dDevice->SetTexture( 1, g_pTexAdaptedLuminanceCur );
	g_pd3dDevice->SetRenderState( D3DRS_SCISSORTESTENABLE, TRUE );
	g_pd3dDevice->SetScissorRect( &rectDest );
	g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT );
	g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT );
	g_pd3dDevice->SetSamplerState( 1, D3DSAMP_MINFILTER, D3DTEXF_POINT );
	g_pd3dDevice->SetSamplerState( 1, D3DSAMP_MAGFILTER, D3DTEXF_POINT );

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

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

		// Draw a fullscreen quad to sample the RT
		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( pSurfBrightPass );
}