Ejemplo n.º 1
0
	HRESULT PostProcessBloom::initPermanentResources(IDirect3DDevice9* pDevice, UINT width, UINT height)
	{
		m_pDevice = pDevice;

		HRESULT hr;
		HMODULE currentModule = GetCurrentModule();
		// main shader - combine 2x
		hr = D3DXCreateEffectFromResource(pDevice, currentModule, "PP_ColorCombine2.fx", NULL, NULL, 0, NULL, &m_pEffect, NULL);
		if(FAILED(hr))
			return hr;
		m_hTPostProcess = m_pEffect->GetTechniqueByName("PostProcess");
		m_hTexScene = m_pEffect->GetParameterByName(NULL, "g_txSceneColor");
		m_hTexSource = m_pEffect->GetParameterByName(NULL, "g_txSrcColor");

		// 1st shader - bright pass
		hr = D3DXCreateEffectFromResource(pDevice, currentModule, "PP_ColorBrightPass.fx", NULL, NULL, 0, NULL, &m_pEffectBrightPass, NULL);
		m_hTPostProcessBP = m_pEffectBrightPass->GetTechniqueByName("PostProcess");
		m_hTexSourceBP = m_pEffectBrightPass->GetParameterByName(NULL, "g_txSrcColor");

		// 2nd shader - down size 2x
		hr = D3DXCreateEffectFromResource(pDevice, currentModule, "PP_ColorDownFilter2.fx", NULL, NULL, 0, NULL, &m_pEffectDownSize2x, NULL);
		m_hTPostProcessD2 = m_pEffectDownSize2x->GetTechniqueByName("PostProcess");
		m_hTexSourceD2 = m_pEffectDownSize2x->GetParameterByName(NULL, "g_txSrcColor");

		// 3rd shader - down size 4x
		hr = D3DXCreateEffectFromResource(pDevice, currentModule, "PP_ColorDownFilter4.fx", NULL, NULL, 0, NULL, &m_pEffectDownSize4x, NULL);
		m_hTPostProcessD4 = m_pEffectDownSize4x->GetTechniqueByName("PostProcess");
		m_hTexSourceD4 = m_pEffectDownSize4x->GetParameterByName(NULL, "g_txSrcColor");

		// 4th shader - bloom horizontal
		hr = D3DXCreateEffectFromResource(pDevice, currentModule, "PP_ColorBloomH.fx", NULL, NULL, 0, NULL, &m_pEffectBloomH, NULL);
		m_hTPostProcessBH = m_pEffectBloomH->GetTechniqueByName("PostProcess");
		m_hTexSourceBH = m_pEffectBloomH->GetParameterByName(NULL, "g_txSrcColor");

		// 5th shader - bloom vertical
		hr = D3DXCreateEffectFromResource(pDevice, currentModule, "PP_ColorBloomV.fx", NULL, NULL, 0, NULL, &m_pEffectBloomV, NULL);
		m_hTPostProcessBV = m_pEffectBloomV->GetTechniqueByName("PostProcess");
		m_hTexSourceBV = m_pEffectBloomV->GetParameterByName(NULL, "g_txSrcColor");

		// 6th shader - gaussian blur horizontal
		hr = D3DXCreateEffectFromResource(pDevice, currentModule, "PP_ColorGBlurH.fx", NULL, NULL, 0, NULL, &m_pEffectGBlurH, NULL);
		m_hTPostProcessGBH = m_pEffectGBlurH->GetTechniqueByName("PostProcess");
		m_hTexSourceGBH = m_pEffectGBlurH->GetParameterByName(NULL, "g_txSrcColor");

		// 7th shader - gaussian blur vertical
		hr = D3DXCreateEffectFromResource(pDevice, currentModule, "PP_ColorGBlurV.fx", NULL, NULL, 0, NULL, &m_pEffectGBlurV, NULL);
		m_hTPostProcessGBV = m_pEffectGBlurV->GetTechniqueByName("PostProcess");
		m_hTexSourceGBV = m_pEffectGBlurV->GetParameterByName(NULL, "g_txSrcColor");
		return D3D_OK;
	}
Ejemplo n.º 2
0
void DxStdMtl2::DrawError()
{
	HRESULT hr = S_OK;
	LPD3DXBUFFER error;
	if(!pd3dDevice)
		pd3dDevice = GetDevice();

	if(!m_pErrorEffect)
	{
		hr = D3DXCreateEffectFromResource(pd3dDevice,hInstance,MAKEINTRESOURCE(IDR_RCDATA1),NULL,NULL,0L,NULL,&m_pErrorEffect,&error);
		if(FAILED(hr))
			return;
	}
	D3DXMATRIX projworldview, temp;

	if(!myGWindow)
		return;

	ID3D9GraphicsWindow * d3d9 = static_cast<ID3D9GraphicsWindow*>(myGWindow);

	D3DXMatrixMultiply(&temp,&d3d9->GetWorldXform(), &d3d9->GetViewXform());
	D3DXMatrixMultiply(&projworldview,&temp,&d3d9->GetProjXform());
	m_pErrorEffect->SetMatrix(_T("WorldViewProj"),&projworldview);

	int DefaultMapChannel = 1;
	Tab<int>mappingChannelTab;

	mappingChannelTab.Append(1,&DefaultMapChannel);
	mpMeshCache->GetActiveRenderMesh(m_CurCache)->SetMappingData(mappingChannelTab);
	mpMeshCache->GetActiveRenderMesh(m_CurCache)->Evaluate(pd3dDevice, mpMeshCache->GetActiveMesh(m_CurCache),0,false);

	UINT uPasses = 0;
	m_pErrorEffect->SetTechnique(_T("Error"));
	m_pErrorEffect->Begin(&uPasses, 0 );

	for(UINT uPass = 0; uPass < uPasses; uPass++)
	{
		m_pErrorEffect->BeginPass(uPass);
		mpMeshCache->GetActiveRenderMesh(m_CurCache)->Render(pd3dDevice);
		m_pErrorEffect->EndPass();
	}
	m_pErrorEffect->CommitChanges();
	m_pErrorEffect->End();	

}
Ejemplo n.º 3
0
HRESULT CShader::LoadEffect( LPDIRECT3DDEVICE9 pd3dDevice, LPCTSTR szFileName )
{
    HRESULT hr;
    LPD3DXEFFECT pEffect;

	D3DVERTEXELEMENT9	decl[MAX_FVF_DECL_SIZE];

	D3DXDeclaratorFromFVF( D3DFVF_XYZRHW | D3DFVF_TEX1, decl );
	pd3dDevice->CreateVertexDeclaration( decl, &m_pDecl );
	
#ifdef _DEBUG
    if(FAILED(hr = D3DXCreateEffectFromFile( D3DDEVICE, szFileName, NULL, NULL, 0, NULL, &pEffect, NULL )))
	{
		Error( "CShader::LoadEffect : %s 생성 실패", szFileName );
        return hr;
	}
#else

	if(FAILED(hr = D3DXCreateEffectFromResource( D3DDEVICE, NULL, MAKEINTRESOURCE(IDR_DATA2), NULL, NULL, 0, NULL, &pEffect, NULL )))
	{
		Error( "CShader::LoadEffect : %s 생성 실패", szFileName );
		return hr;
	}
#endif

	m_pEffect = pEffect;
	
    D3DXHANDLE hTechnique;
    if( FAILED(hr = m_pEffect->FindNextValidTechnique(NULL, &hTechnique)) )
	{
		Error( "CShader::LoadEffect : %s Not Valid", szFileName );
        return hr;
	}
	
	m_pEffect->SetTechnique( hTechnique );
//	m_pEffect->SetTexture( "DiffuseTexture", m_pTexture0 );

	return S_OK;
}
Ejemplo n.º 4
0
bool Box::Init(IDirect3DDevice9* pDevice, float width, float height, float x, float y, D3DCOLOR color)
{

	/*VertexData vertex [] =
	{
		//X			Y		  Z		RHW   Color
		{ D3DXVECTOR3(x, y, 0), 1.0, color },
		{ D3DXVECTOR3(x + width, y, 0), 1.0, color },
		{ D3DXVECTOR3(x, y + height, 0), 1.0, color },
		{ D3DXVECTOR3(x + width, y + height, 0), 1.0, color }
	};*/
	
	VertexData vertex[] =
	{
		//X			Y		  Z		RHW   Color
		{ D3DXVECTOR3(x, y, 0), 1.0, color, D3DXVECTOR2(0.0, 0.0) },
		{ D3DXVECTOR3(x + width, y, 0), 1.0, color, D3DXVECTOR2(1.0, 0.0) },
		{ D3DXVECTOR3(x, y + height, 0), 1.0, color, D3DXVECTOR2(0.0, 1.0) },
		{ D3DXVECTOR3(x + width, y + height, 0), 1.0, color, D3DXVECTOR2(1.0, 1.0) }
	};

	/*VertexData vertex[] =
	{
	//X			Y		  Z		RHW   Color
	{ D3DXVECTOR3(x, y, 1), color },
	{ D3DXVECTOR3(x + width, y, 1), color },
	{ D3DXVECTOR3(x, y + height, 1), color },
	{ D3DXVECTOR3(x + width, y + height, 1), color }
	};*/

	VOID* pVoid = nullptr;

	//Set up the vertex buffer

	unsigned long vertexSize = 4 * sizeof(VertexData);

	if (FAILED(pDevice->CreateVertexBuffer(vertexSize, 0, CUSTOMFVF, D3DPOOL_MANAGED, &v_buffer, NULL)))
	{
		CLog::Write("Box::Init - Couldn't create the vertex buffer");
		return false;
	}

	v_buffer->Lock(0, 0, (void**) &pVoid, 0);
	{
		memcpy(pVoid, vertex, sizeof(vertex));
	}
	v_buffer->Unlock();

	//Set up the index buffer

	short indices [] =
	{
		0, 1, 2, 3
	};

	if (FAILED(pDevice->CreateIndexBuffer(4 * sizeof(short), 0, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_pIndexBuffer, 0)))
	{
		CLog::Write("Box::Init - Couldn't create the index buffer");
		return false;
	}

	m_pIndexBuffer->Lock(0, 0, (void**) &pVoid, 0);
	{
		memcpy(pVoid, indices, sizeof(indices));
	}
	m_pIndexBuffer->Unlock();


	//Create the index declaration

	D3DVERTEXELEMENT9 decl [] =
	{
		{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
		{ 0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
		D3DDECL_END()
	};

	if (FAILED(pDevice->CreateVertexDeclaration(decl, &m_pDeclaration)))
		return false;

	//Create the shader

	LPD3DXBUFFER pErr = nullptr;

	if (FAILED(D3DXCreateEffectFromResource(pDevice, GetModuleHandle("sampp_client.asi"), MAKEINTRESOURCE(IDR_RCDATA1), 0, 0, 0, 0, &m_pShader, &pErr)))
	{
		CLog::Write("D3DXCreateEffectFromResource failed: %s", (char*) pErr->GetBufferPointer());
		pErr->Release();
		pErr = nullptr;
		return false;
	}

	//Create the texture

	if (FAILED(D3DXCreateTextureFromFile(pDevice, "rocks.jpg", &m_pTexture)))
	{
		CLog::Write("D3DXCreateTextureFromFile failed");
		return false;
	}

	//Initialize the variables

	m_fX = x;
	m_fY = y;

	m_fWidth = width;
	m_fHeight = height;

	m_pDevice = pDevice;

	m_bDraw = true;

	m_cColor = color;

	m_BarRect = { m_fX, m_fY, m_fX + m_fWidth, m_fY + m_fHeight };

	initialized = true;

	D3DXMatrixTranslation(&m_View, 0, 0, 2);
	D3DXMatrixPerspectiveFovLH(&m_Proj, D3DXToRadian(75), 1366 / 768, 0.01f, 100.0f);

	return true;
}