Exemplo n.º 1
0
static ID3D10ShaderResourceView *BrightnessImage(ID3D10ShaderResourceView *pTexture, sImageInfo *pInfo)
{
	ID3D10Device *device = GutGetGraphicsDeviceDX10();

	int w = pInfo->m_iWidth/4;
	int h = pInfo->m_iHeight/4;
	float fTexelW = 1.0f/(float)w;
	float fTexelH = 1.0f/(float)h;

	D3D10_VIEWPORT vp = {0, 0, w, h, 0.0f, 1.0f};
	device->RSSetViewports(1, &vp);

	device->VSSetShader(g_pBlurVS);
	device->PSSetShader(g_pBrightnessPS);

	ID3D10Buffer *buffer_array[2] = {g_pVSConstantBuffer, g_pBrightnessConstantBuffer};

	device->VSSetConstantBuffers(0, 2, buffer_array);
	device->PSSetConstantBuffers(0, 2, buffer_array);

	UINT stride = sizeof(Vertex_VT);
	UINT offset = 0;

	g_pDevice->IASetInputLayout(g_pVertexLayout);
	g_pDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
	g_pDevice->IASetVertexBuffers(0, 1, &g_pVertexBuffer, &stride, &offset);

	device->OMSetRenderTargets(1, &g_pFrameRTView[1], NULL);

	Vector4 *pConstants;
	g_pBrightnessConstantBuffer->Map( D3D10_MAP_WRITE_DISCARD, NULL, (void **) &pConstants);
	pConstants[0] = g_vBrightnessOffset;
	pConstants[1] = g_vBrightnessScale;
	g_pBrightnessConstantBuffer->Unmap();

	g_pDevice->PSSetShaderResources(0, 1, &pTexture);
	g_pDevice->Draw(4, 0);

	return g_pFrameSRView[1];
}
Exemplo n.º 2
0
static ID3D10ShaderResourceView *BlurImage(ID3D10ShaderResourceView *pTexture, sImageInfo *pInfo)
{
	int w = pInfo->m_iWidth/4;
	int h = pInfo->m_iHeight/4;
	float fTexelW = 1.0f/(float)w;
	float fTexelH = 1.0f/(float)h;

	D3D10_VIEWPORT vp = {0, 0, w, h, 0.0f, 1.0f};
	g_pDevice->RSSetViewports(1, &vp);

	const int num_samples = KERNELSIZE;
	Vector4 vTexOffsetX[num_samples];
	Vector4 vTexOffsetY[num_samples];

	for ( int i=0; i<num_samples; i++ )
	{
		vTexOffsetX[i].Set(g_uv_offset_table[i] * fTexelW, 0.0f, 0.0f, g_weight_table[i]);
		vTexOffsetY[i].Set(0.0f, g_uv_offset_table[i] * fTexelH, 0.0f, g_weight_table[i]);
	}

	Vector4 *pConstants;

	ID3D10Device *device = GutGetGraphicsDeviceDX10();

	device->VSSetShader(g_pBlurVS);
	device->PSSetShader(g_pBlurPS);

	ID3D10Buffer *buffer_array[2] = {g_pVSConstantBuffer, g_pBlurConstantBuffer};

	device->VSSetConstantBuffers(0, 2, buffer_array);
	device->PSSetConstantBuffers(0, 2, buffer_array);

	UINT stride = sizeof(Vertex_VT);
	UINT offset = 0;

	g_pDevice->IASetInputLayout(g_pVertexLayout);
	g_pDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
	g_pDevice->IASetVertexBuffers(0, 1, &g_pVertexBuffer, &stride, &offset);

	// 水平模糊
	{
		device->OMSetRenderTargets(1, &g_pFrameRTView[0], NULL);

		g_pBlurConstantBuffer->Map( D3D10_MAP_WRITE_DISCARD, NULL, (void **) &pConstants);
		memcpy(pConstants, vTexOffsetX, sizeof(Vector4)*num_samples);
		g_pBlurConstantBuffer->Unmap();

		g_pDevice->PSSetShaderResources(0, 1, &pTexture);
		g_pDevice->Draw(4, 0);
	}
	// 垂直模糊
	{
		device->OMSetRenderTargets(1, &g_pFrameRTView[1], NULL);

		g_pBlurConstantBuffer->Map( D3D10_MAP_WRITE_DISCARD, NULL, (void **) &pConstants);
		memcpy(pConstants, vTexOffsetY, sizeof(Vector4)*num_samples);
		g_pBlurConstantBuffer->Unmap();

		g_pDevice->PSSetShaderResources(0, 1, &g_pFrameSRView[0]);
		g_pDevice->Draw(4, 0);
	}

	return g_pFrameSRView[1];
}