コード例 #1
0
ファイル: SV_GMeshInfoView.cpp プロジェクト: DennisGT/GD3D11
/** Draws the meshes to the buffer */
void SV_GMeshInfoView::DrawMeshes()
{
	D3D11GraphicsEngine* g = (D3D11GraphicsEngine *)Engine::GraphicsEngine;

	g->SetupVS_ExMeshDrawCall();
	g->SetupVS_ExConstantBuffer();
	g->SetupVS_ExPerInstanceConstantBuffer();

	VisualTesselationSettings* ts = NULL;
	if(VisualInfo)
		ts = &VisualInfo->TesselationInfo;

	// Draw each texture
	for(auto it = Meshes.begin(); it != Meshes.end(); it++)
	{
		// Set up tesselation if wanted
		if(ts && !(*it).second->IndicesPNAEN.empty() && ts->buffer.VT_TesselationFactor > 0.0f)
		{
			g->Setup_PNAEN(D3D11GraphicsEngine::PNAEN_Default);
			ts->Constantbuffer->BindToDomainShader(1);
			ts->Constantbuffer->BindToHullShader(1);

			

			if((*it).first->CacheIn(-1) == zRES_CACHED_IN)
			{
				MyDirectDrawSurface7* surface = (*it).first->GetSurface();
				ID3D11ShaderResourceView* srv = surface->GetNormalmap() ? ((D3D11Texture *)surface->GetNormalmap())->GetShaderResourceView() : NULL;

				// Draw
				(*it).first->Bind(0);
				g->DrawVertexBufferIndexed( (*it).second->MeshVertexBuffer,
											(*it).second->MeshIndexBufferPNAEN,
											(*it).second->IndicesPNAEN.size() );
			}
		}else if(VisualInfo)
		{
			g->GetContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
			g->GetContext()->DSSetShader(NULL, NULL, NULL);
			g->GetContext()->HSSetShader(NULL, NULL, NULL);
			g->SetActiveHDShader("");
			g->SetActiveVertexShader("VS_Ex");

			if((*it).first && (*it).first->CacheIn(-1) == zRES_CACHED_IN)
			{
				// Draw
				(*it).first->Bind(0);
				g->DrawVertexBufferIndexed( (*it).second->MeshVertexBuffer,
											(*it).second->MeshIndexBuffer,
											(*it).second->Indices.size() );
			}
		}


		
	}

	
}
コード例 #2
0
ファイル: D3D11VShader.cpp プロジェクト: DennisGT/GD3D11
/** Applys the shaders */
XRESULT D3D11VShader::Apply()
{
	D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine;

	engine->GetContext()->IASetInputLayout(InputLayout);
	engine->GetContext()->VSSetShader(VertexShader, NULL, 0);

	return XR_SUCCESS;
}
コード例 #3
0
ファイル: D3D11PfxRenderer.cpp プロジェクト: Katharsas/GD3D11
/** Copies the given texture to the given RTV */
XRESULT D3D11PfxRenderer::CopyTextureToRTV(ID3D11ShaderResourceView* texture, ID3D11RenderTargetView* rtv, INT2 targetResolution, bool useCustomPS, INT2 offset)
{
	D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine;
	
	D3D11_VIEWPORT oldVP;
	if(targetResolution.x != 0 && targetResolution.y != 0)
	{
		UINT n=1;
		engine->GetContext()->RSGetViewports(&n, &oldVP);

		D3D11_VIEWPORT vp;
		vp.TopLeftX = (float)offset.x;
		vp.TopLeftY = (float)offset.y;
		vp.MinDepth = 0.0f;
		vp.MaxDepth = 0.0f;
		vp.Width = (float)targetResolution.x;
		vp.Height = (float)targetResolution.y;

		engine->GetContext()->RSSetViewports(1, &vp);
	}

	// Save old rendertargets
	ID3D11RenderTargetView* oldRTV = NULL;
	ID3D11DepthStencilView* oldDSV = NULL;
	engine->GetContext()->OMGetRenderTargets(1, &oldRTV, &oldDSV);

	// Bind shaders
	if(!useCustomPS)
	{
		D3D11PShader* simplePS = engine->GetShaderManager()->GetPShader("PS_PFX_Simple");
		simplePS->Apply();
	}

	engine->GetShaderManager()->GetVShader("VS_PFX")->Apply();
	
	ID3D11ShaderResourceView* srv = NULL;
	engine->GetContext()->PSSetShaderResources(0,1,&srv);

	engine->GetContext()->OMSetRenderTargets(1, &rtv, NULL);

	if(texture)
		engine->GetContext()->PSSetShaderResources(0,1, &texture);

	DrawFullScreenQuad();

	engine->GetContext()->PSSetShaderResources(0,1,&srv);
	engine->GetContext()->OMSetRenderTargets(1, &oldRTV, oldDSV);
	if(oldRTV)oldRTV->Release();
	if(oldDSV)oldDSV->Release();
	
	if(targetResolution.x != 0 && targetResolution.y != 0)
	{
		engine->GetContext()->RSSetViewports(1, &oldVP);
	}

	return XR_SUCCESS;
}
コード例 #4
0
ファイル: D3D11PFX_HDR.cpp プロジェクト: DennisGT/GD3D11
D3D11PFX_HDR::D3D11PFX_HDR(D3D11PfxRenderer* rnd) : D3D11PFX_Effect(rnd)
{
	D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine;

	// Create lum-buffer
	LumBuffer1 = new RenderToTextureBuffer(engine->GetDevice(), LUM_SIZE, LUM_SIZE, DXGI_FORMAT_R16_FLOAT, NULL, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, (int)(log(LUM_SIZE) / log(2)));
	LumBuffer2 = new RenderToTextureBuffer(engine->GetDevice(), LUM_SIZE, LUM_SIZE, DXGI_FORMAT_R16_FLOAT, NULL, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, (int)(log(LUM_SIZE) / log(2)));
	LumBuffer3 = new RenderToTextureBuffer(engine->GetDevice(), LUM_SIZE, LUM_SIZE, DXGI_FORMAT_R16_FLOAT, NULL, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, (int)(log(LUM_SIZE) / log(2)));

	engine->GetContext()->ClearRenderTargetView(LumBuffer1->GetRenderTargetView(), (float *)&D3DXVECTOR4(0,0,0,0));
	engine->GetContext()->ClearRenderTargetView(LumBuffer2->GetRenderTargetView(), (float *)&D3DXVECTOR4(0,0,0,0));
	engine->GetContext()->ClearRenderTargetView(LumBuffer3->GetRenderTargetView(), (float *)&D3DXVECTOR4(0,0,0,0));
	ActiveLumBuffer = 0;
}
コード例 #5
0
ファイル: D3D11PointLight.cpp プロジェクト: Katharsas/GD3D11
/** Renders the scene with the given view-proj-matrices */
void D3D11PointLight::RenderCubemapFace(const D3DXMATRIX& view, const D3DXMATRIX& proj, UINT faceIdx)
{
	D3D11GraphicsEngineBase* engineBase = (D3D11GraphicsEngineBase *)Engine::GraphicsEngine;
	D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *) engineBase; // TODO: Remove and use newer system!
	CameraReplacement cr;
	cr.PositionReplacement = LightInfo->Vob->GetPositionWorld();
	cr.ProjectionReplacement = proj;
	cr.ViewReplacement = view;

	// Replace gothics camera
	Engine::GAPI->SetCameraReplacementPtr(&cr);

	if(engine->GetDummyCubeRT())
		engine->GetContext()->ClearRenderTargetView(engine->GetDummyCubeRT()->GetRTVCubemapFace(faceIdx), (float *)&float4(0,0,0,0));

	// Disable shadows for NPCs
	// TODO: Only for the player himself, because his shadows look ugly when using a torch
	bool oldDrawSkel = Engine::GAPI->GetRendererState()->RendererSettings.DrawSkeletalMeshes;
	//Engine::GAPI->GetRendererState()->RendererSettings.DrawSkeletalMeshes = false;

	float range = LightInfo->Vob->GetLightRange() * 1.1f;

	// Draw cubemap face
	ID3D11RenderTargetView* debugRTV = engine->GetDummyCubeRT() != NULL ? engine->GetDummyCubeRT()->GetRTVCubemapFace(faceIdx) : NULL;
	engine->RenderShadowCube(cr.PositionReplacement, range, DepthCubemap, DepthCubemap->GetDSVCubemapFace(faceIdx), debugRTV, false);

	//Engine::GAPI->GetRendererState()->RendererSettings.DrawSkeletalMeshes = oldDrawSkel;

	// Reset settings
	Engine::GAPI->SetCameraReplacementPtr(NULL);
}
コード例 #6
0
ファイル: D3D11Vertexbuffer.cpp プロジェクト: DennisGT/GD3D11
/** Unmaps the buffer */
XRESULT D3D11VertexBuffer::Unmap()
{
	D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine;

	engine->GetContext()->Unmap(VertexBuffer, 0);

	return XR_SUCCESS;
}
コード例 #7
0
ファイル: D3D11PfxRenderer.cpp プロジェクト: Katharsas/GD3D11
/** Draws a fullscreenquad */
XRESULT D3D11PfxRenderer::DrawFullScreenQuad()
{
	D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine;
	engine->UpdateRenderStates();

	engine->GetContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	UINT offset = 0;
	UINT uStride = sizeof(SimpleVertexStruct);
	ID3D11Buffer* buffers = ScreenQuad->GetBuffer();
	engine->GetContext()->IASetVertexBuffers( 0, 1, &buffers, &uStride, &offset );

	//ID3D11Buffer* cb = NULL;
	//engine->GetContext()->VSSetConstantBuffers(0, 1, &cb);

	//Draw the mesh
	engine->GetContext()->Draw(6, 0 );
	
	return XR_SUCCESS;
}
コード例 #8
0
ファイル: D3D11PfxRenderer.cpp プロジェクト: Katharsas/GD3D11
/** Unbinds texturesamplers from the pixel-shader */
XRESULT D3D11PfxRenderer::UnbindPSResources(int num)
{
	ID3D11ShaderResourceView** srv = new ID3D11ShaderResourceView*[num];
	ZeroMemory(srv, sizeof(ID3D11ShaderResourceView*) * num);

	D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine;
	engine->GetContext()->PSSetShaderResources(0, num, srv);

	delete[] srv;
	
	return XR_SUCCESS;
}
コード例 #9
0
ファイル: D3D11PFX_HDR.cpp プロジェクト: DennisGT/GD3D11
/** Blurs the backbuffer and puts the result into TempBufferDS4_2*/
void D3D11PFX_HDR::CreateBloom(RenderToTextureBuffer* lum)
{
	D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine;
	
	INT2 dsRes = INT2(Engine::GraphicsEngine->GetResolution().x / 4, Engine::GraphicsEngine->GetResolution().y / 4);
	engine->GetShaderManager()->GetVShader("VS_PFX")->Apply();
	D3D11PShader* tonemapPS = engine->GetShaderManager()->GetPShader("PS_PFX_Tonemap");
	tonemapPS->Apply();

	HDRSettingsConstantBuffer hcb;
	hcb.HDR_LumWhite = Engine::GAPI->GetRendererState()->RendererSettings.HDRLumWhite;
	hcb.HDR_MiddleGray = Engine::GAPI->GetRendererState()->RendererSettings.HDRMiddleGray;
	hcb.HDR_Threshold = Engine::GAPI->GetRendererState()->RendererSettings.BloomThreshold;
	tonemapPS->GetConstantBuffer()[0]->UpdateBuffer(&hcb);
	tonemapPS->GetConstantBuffer()[0]->BindToPixelShader(0);

	lum->BindToPixelShader(engine->GetContext(), 1);
	FxRenderer->CopyTextureToRTV(engine->GetHDRBackBuffer()->GetShaderResView(), FxRenderer->GetTempBufferDS4_1()->GetRenderTargetView(), dsRes, true);

	D3D11PShader* gaussPS = engine->GetShaderManager()->GetPShader("PS_PFX_GaussBlur");


	/** Pass 1: Blur-H */
	// Apply PFX-VS
	D3D11PShader* simplePS = engine->GetShaderManager()->GetPShader("PS_PFX_Simple");

	// Apply blur-H shader
	gaussPS->Apply();

	// Update settings 
	BlurConstantBuffer bcb;
	bcb.B_BlurSize = 1.0f;
	bcb.B_PixelSize = float2(1.0f / FxRenderer->GetTempBufferDS4_1()->GetSizeX(), 0.0f);
	gaussPS->GetConstantBuffer()[0]->UpdateBuffer(&bcb);
	gaussPS->GetConstantBuffer()[0]->BindToPixelShader(0);

	// Copy
	FxRenderer->CopyTextureToRTV(FxRenderer->GetTempBufferDS4_1()->GetShaderResView(), FxRenderer->GetTempBufferDS4_2()->GetRenderTargetView(), dsRes, true);

	/** Pass 2: Blur V */

	// Update settings
	bcb.B_BlurSize = 1.0f;
	bcb.B_PixelSize = float2(0.0f, 1.0f / FxRenderer->GetTempBufferDS4_1()->GetSizeY());
	bcb.B_Threshold = 0.0f;
	gaussPS->GetConstantBuffer()[0]->UpdateBuffer(&bcb);
	gaussPS->GetConstantBuffer()[0]->BindToPixelShader(0);

	// Copy
	FxRenderer->CopyTextureToRTV(FxRenderer->GetTempBufferDS4_2()->GetShaderResView(), FxRenderer->GetTempBufferDS4_1()->GetRenderTargetView(), dsRes, true);

}
コード例 #10
0
ファイル: D3D11Vertexbuffer.cpp プロジェクト: DennisGT/GD3D11
/** Maps the buffer */
XRESULT D3D11VertexBuffer::Map(int flags, void** dataPtr, UINT* size)
{
	D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine;

	D3D11_MAPPED_SUBRESOURCE res;
	if (FAILED(engine->GetContext()->Map(VertexBuffer, 0, (D3D11_MAP)flags, 0, &res)))
		return XR_FAILED;

	*dataPtr = res.pData;
	*size = res.DepthPitch;

	return XR_SUCCESS;
}
コード例 #11
0
ファイル: D3D11PointLight.cpp プロジェクト: Katharsas/GD3D11
/** Debug-draws the cubemap to the screen */
void D3D11PointLight::DebugDrawCubeMap()
{
	if(!InitDone)
		return;

	D3D11GraphicsEngineBase* engineBase = (D3D11GraphicsEngineBase *)Engine::GraphicsEngine;
	D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *) engineBase; // TODO: Remove and use newer system!

	const int previewSize = POINTLIGHT_SHADOWMAP_SIZE;
	const int previewDownscale = 4;
	


	for(int i=0;i<6;i++)
	{
		INT2 pPosition;
		int stride = (previewSize / previewDownscale);
		if(i==1) // x-
		{
			pPosition.x = 0;
			pPosition.y = stride;
		}else if(i==3) // y-
		{
			pPosition.x = stride;
			pPosition.y = stride;
		}else if(i==0) // x+
		{
			pPosition.x = stride * 2;
			pPosition.y = stride;
		}else if(i==2) // y+
		{
			pPosition.x = stride * 3;
			pPosition.y = stride;
		}else if(i==5) // z-
		{
			pPosition.x = stride;
			pPosition.y = 0;
		}else if(i==4) // z+
		{
			pPosition.x = stride;
			pPosition.y = stride * 2;
		}

		INT2 pSize = INT2(previewSize / previewDownscale,previewSize / previewDownscale);

		ID3D11ShaderResourceView* srv = engine->GetDummyCubeRT()->GetSRVCubemapFace(i);
		engine->GetContext()->PSSetShaderResources(0,1, &srv);
		Engine::GraphicsEngine->DrawQuad(pPosition, pSize);
	}
}
コード例 #12
0
ファイル: D3D11PFX_HDR.cpp プロジェクト: DennisGT/GD3D11
/** Draws this effect to the given buffer */
XRESULT D3D11PFX_HDR::Render(RenderToTextureBuffer* fxbuffer)
{
	D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine;
	
	Engine::GAPI->GetRendererState()->BlendState.BlendEnabled = false;
	Engine::GAPI->GetRendererState()->BlendState.SetDirty();

	// Save old rendertargets
	ID3D11RenderTargetView* oldRTV = NULL;
	ID3D11DepthStencilView* oldDSV = NULL;
	engine->GetContext()->OMGetRenderTargets(1, &oldRTV, &oldDSV);


	RenderToTextureBuffer* lum = CalcLuminance();
	CreateBloom(lum);

	// Copy the original image to our temp-buffer
	FxRenderer->CopyTextureToRTV(engine->GetHDRBackBuffer()->GetShaderResView(), FxRenderer->GetTempBuffer()->GetRenderTargetView(), engine->GetResolution());

	// Bind scene and luminance
	FxRenderer->GetTempBuffer()->BindToPixelShader(engine->GetContext(), 0);
	lum->BindToPixelShader(engine->GetContext(), 1);

	// Bind bloom
	FxRenderer->GetTempBufferDS4_1()->BindToPixelShader(engine->GetContext(), 2);

	// Draw the HDR-Shader
	D3D11PShader* hps = engine->GetShaderManager()->GetPShader("PS_PFX_HDR");
	hps->Apply();

	HDRSettingsConstantBuffer hcb;
	hcb.HDR_LumWhite = Engine::GAPI->GetRendererState()->RendererSettings.HDRLumWhite;
	hcb.HDR_MiddleGray = Engine::GAPI->GetRendererState()->RendererSettings.HDRMiddleGray;
	hcb.HDR_Threshold = Engine::GAPI->GetRendererState()->RendererSettings.BloomThreshold;
	hcb.HDR_BloomStrength = Engine::GAPI->GetRendererState()->RendererSettings.BloomStrength;
	hps->GetConstantBuffer()[0]->UpdateBuffer(&hcb);
	hps->GetConstantBuffer()[0]->BindToPixelShader(0);

	FxRenderer->CopyTextureToRTV(FxRenderer->GetTempBuffer()->GetShaderResView(), oldRTV, engine->GetResolution(), true);

	// Show lumBuffer
	//FxRenderer->CopyTextureToRTV(currentLum->GetShaderResView(), oldRTV, INT2(LUM_SIZE,LUM_SIZE), false);

	// Restore rendertargets
	ID3D11ShaderResourceView* srv = NULL;
	engine->GetContext()->PSSetShaderResources(1,1,&srv);
	engine->GetContext()->OMSetRenderTargets(1, &oldRTV, oldDSV);
	if(oldRTV)oldRTV->Release();
	if(oldDSV)oldDSV->Release();

	return XR_SUCCESS;
}
コード例 #13
0
ファイル: D3D11PFX_HDR.cpp プロジェクト: DennisGT/GD3D11
/** Calcualtes the luminance */
RenderToTextureBuffer* D3D11PFX_HDR::CalcLuminance()
{
	D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine;

	RenderToTextureBuffer* lumRTV;
	RenderToTextureBuffer* lastLum;
	RenderToTextureBuffer* currentLum;

	// Figure out which buffers to use where
	switch(ActiveLumBuffer)
	{
	case 0:
		lumRTV = LumBuffer1;
		lastLum = LumBuffer2;
		currentLum = LumBuffer3;
		break;

	case 1:
		lumRTV = LumBuffer3;
		lastLum = LumBuffer1;
		currentLum = LumBuffer2;
		break;

	case 2:
		lumRTV = LumBuffer2;
		lastLum = LumBuffer3;
		currentLum = LumBuffer1;
		break;
	}

	D3D11PShader* lps = engine->GetShaderManager()->GetPShader("PS_PFX_LumConvert");
	lps->Apply();

	// Convert the backbuffer to our luminance buffer
	FxRenderer->CopyTextureToRTV(engine->GetHDRBackBuffer()->GetShaderResView(), currentLum->GetRenderTargetView(), INT2(LUM_SIZE,LUM_SIZE), true);

	// Create the average luminance
	engine->GetContext()->GenerateMips(currentLum->GetShaderResView());

	D3D11PShader* aps = engine->GetShaderManager()->GetPShader("PS_PFX_LumAdapt");
	aps->Apply();

	LumAdaptConstantBuffer lcb;
	lcb.LC_DeltaTime = Engine::GAPI->GetDeltaTime();
	aps->GetConstantBuffer()[0]->UpdateBuffer(&lcb);
	aps->GetConstantBuffer()[0]->BindToPixelShader(0);

	// Bind luminances
	lastLum->BindToPixelShader(engine->GetContext(), 1);
	currentLum->BindToPixelShader(engine->GetContext(), 2);
	
	// Convert the backbuffer to our luminance buffer
	FxRenderer->CopyTextureToRTV(NULL, lumRTV->GetRenderTargetView(), INT2(LUM_SIZE,LUM_SIZE), true);

	// Create the average luminance
	engine->GetContext()->GenerateMips(lumRTV->GetShaderResView());

	// Increment
	ActiveLumBuffer++;
	ActiveLumBuffer = (ActiveLumBuffer == 3 ? 0 : ActiveLumBuffer);

	return lumRTV;
}
コード例 #14
0
/** Draws this effect to the given buffer */
XRESULT D3D11PFX_HeightFog::Render(RenderToTextureBuffer* fxbuffer)
{
	D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine;

	// Save old rendertargets
	ID3D11RenderTargetView* oldRTV = NULL;
	ID3D11DepthStencilView* oldDSV = NULL;
	engine->GetContext()->OMGetRenderTargets(1, &oldRTV, &oldDSV);

	D3D11VShader* vs = engine->GetShaderManager()->GetVShader("VS_PFX");
	D3D11PShader* hfPS = engine->GetShaderManager()->GetPShader("PS_PFX_Heightfog");

	hfPS->Apply();
	vs->Apply();

	HeightfogConstantBuffer cb;
	D3DXMatrixInverse(&cb.InvProj, NULL, &Engine::GAPI->GetProjectionMatrix());

	Engine::GAPI->GetViewMatrix(&cb.InvView);
	D3DXMatrixInverse(&cb.InvView, NULL, &cb.InvView);
	cb.CameraPosition = Engine::GAPI->GetCameraPosition();
	float NearPlane=Engine::GAPI->GetRendererState()->RendererInfo.NearPlane;
	float FarPlane=Engine::GAPI->GetRendererState()->RendererInfo.FarPlane;

	D3DXMATRIX invViewProj, view;
	Engine::GAPI->GetViewMatrix(&view);
	D3DXMatrixMultiply(&invViewProj, &Engine::GAPI->GetProjectionMatrix(), &view);
	D3DXMatrixInverse(&invViewProj, NULL, &invViewProj);

	D3DXVECTOR3 vecFrustum[4];
	/*vecFrustum[0] = D3DXVECTOR3(-1.0f, -1.0f,  0.0f); // xyz
	vecFrustum[1] = D3DXVECTOR3( 1.0f, -1.0f,  0.0f); // Xyz
	vecFrustum[2] = D3DXVECTOR3(-1.0f,  1.0f,  0.0f); // xYz
	vecFrustum[3] = D3DXVECTOR3( 1.0f,  1.0f,  0.0f); // XYz*/
	vecFrustum[0] = D3DXVECTOR3(-1.0f, -1.0f,  1.0f); // xyZ
	vecFrustum[1] = D3DXVECTOR3( 1.0f, -1.0f,  1.0f); // XyZ
	vecFrustum[2] = D3DXVECTOR3(-1.0f,  1.0f,  1.0f); // xYZ
	vecFrustum[3] = D3DXVECTOR3( 1.0f,  1.0f,  1.0f); // XYZ

	// Get world space frustum corners
	PFXVS_ConstantBuffer vcb;
	for( int i = 0; i < 4; i++ )
	{
		D3DXVec3TransformCoord( &vecFrustum[i], &vecFrustum[i], &cb.InvProj );
		D3DXVec3Normalize(&vecFrustum[i], &vecFrustum[i]);
		D3DXVec3TransformNormal( &vecFrustum[i], &vecFrustum[i], &cb.InvView );
		
	}

	/*vcb.PFXVS_FrustumCorners[0] = D3DXVECTOR4(vecFrustum[0].x, vecFrustum[0].y, vecFrustum[0].z, 0.0f);
	vcb.PFXVS_FrustumCorners[1] = D3DXVECTOR4(vecFrustum[2].x, vecFrustum[2].y, vecFrustum[2].z, 0.0f);
	vcb.PFXVS_FrustumCorners[2] = D3DXVECTOR4(vecFrustum[1].x, vecFrustum[1].y, vecFrustum[1].z, 0.0f);

	vcb.PFXVS_FrustumCorners[3] = D3DXVECTOR4(vecFrustum[3].x, vecFrustum[3].y, vecFrustum[3].z, 0.0f);
	vcb.PFXVS_FrustumCorners[4] = D3DXVECTOR4(vecFrustum[1].x, vecFrustum[1].y, vecFrustum[1].z, 0.0f);
	vcb.PFXVS_FrustumCorners[5] = D3DXVECTOR4(vecFrustum[2].x, vecFrustum[2].y, vecFrustum[2].z, 0.0f);*/

	cb.HF_GlobalDensity = Engine::GAPI->GetRendererState()->RendererSettings.FogGlobalDensity;
	cb.HF_HeightFalloff = Engine::GAPI->GetRendererState()->RendererSettings.FogHeightFalloff;
	
	float height = Engine::GAPI->GetRendererState()->RendererSettings.FogHeight;
	D3DXVECTOR3 color = *Engine::GAPI->GetRendererState()->RendererSettings.FogColorMod.toD3DXVECTOR3();

	float fnear = 15000.0f;
	float ffar = 60000.0f;
	float secScale = Engine::GAPI->GetRendererState()->RendererSettings.SectionDrawRadius;

	cb.HF_WeightZNear = std::max(0.0f, WORLD_SECTION_SIZE * ((secScale - 0.5f) * 0.7f) - (ffar - fnear)); // Keep distance from original fog but scale the near-fog up to section draw distance
	cb.HF_WeightZFar = WORLD_SECTION_SIZE * ((secScale - 0.5f) * 0.8f);
	
	float atmoMax = 83200.0f; // Fixme: Calculate!	
	float atmoMin = 27799.9922f;

	cb.HF_WeightZFar = std::min(cb.HF_WeightZFar, atmoMax);
	cb.HF_WeightZNear = std::min(cb.HF_WeightZNear, atmoMin);

	if(Engine::GAPI->GetFogOverride() > 0.0f)
	{
		// Make sure the camera is inside the fog when in fog zone
		height = Toolbox::lerp(height, Engine::GAPI->GetCameraPosition().y + 10000, Engine::GAPI->GetFogOverride()); // TODO: Get this from the actual fog-distance in the fogzone!
		
		// Override fog color when in fog zone
		color = Engine::GAPI->GetFogColor();

		// Make it z-Fog
		cb.HF_HeightFalloff = Toolbox::lerp(cb.HF_HeightFalloff, 0.000001f, Engine::GAPI->GetFogOverride());

		// Turn up density
		cb.HF_GlobalDensity = Toolbox::lerp(cb.HF_GlobalDensity, cb.HF_GlobalDensity * 2, Engine::GAPI->GetFogOverride());

		// Use other fog-values for fog-zones
		float distNear = WORLD_SECTION_SIZE * ((ffar - fnear) / ffar);
		cb.HF_WeightZNear = Toolbox::lerp(cb.HF_WeightZNear, WORLD_SECTION_SIZE * 0.09f, Engine::GAPI->GetFogOverride());
		cb.HF_WeightZFar = Toolbox::lerp(cb.HF_WeightZFar, WORLD_SECTION_SIZE * 0.8, Engine::GAPI->GetFogOverride());
	}

	/*static float s_smoothHeight = Engine::GAPI->GetRendererState()->RendererSettings.FogHeight;
	static float s_smoothZF = cb.HF_WeightZFar;
	static float s_smoothZN = cb.HF_WeightZNear;

	// Fade Z-Far and z-Near
	s_smoothZF = Toolbox::lerp(s_smoothZF, cb.HF_WeightZFar, std::min(Engine::GAPI->GetFrameTimeSec() * 5.0f, 1.0f));
	s_smoothZN = Toolbox::lerp(s_smoothZN, cb.HF_WeightZNear, std::min(Engine::GAPI->GetFrameTimeSec() * 5.0f, 1.0f));

	cb.HF_WeightZNear = s_smoothZN;
	cb.HF_WeightZFar = s_smoothZF;*/

	//static D3DXVECTOR3 s_smoothColor = *Engine::GAPI->GetRendererState()->RendererSettings.FogColorMod.toD3DXVECTOR3();

	// Fade fog height in case it changes
	//s_smoothHeight = Toolbox::lerp(s_smoothHeight, height, std::min(Engine::GAPI->GetFrameTimeSec() * 5.0f, 1.0f));

	// Fade color, because leaving a fogzone would make the fog-color pop otherwise
	//D3DXVec3Lerp(&s_smoothColor, &s_smoothColor, &color, std::min(Engine::GAPI->GetFrameTimeSec() * 5.0f, 1.0f));

	//D3DXVECTOR3 fogColorMod = Engine::GAPI->GetRendererState()->RendererSettings.FogColorMod;
	cb.HF_FogColorMod = color;//Engine::GAPI->GetRendererState()->RendererSettings.FogColorMod;

	cb.HF_FogHeight = height;



	//cb.HF_FogColorMod = Engine::GAPI->GetRendererState()->GraphicsState.FF_FogColor;
	cb.HF_ProjAB = float2(	Engine::GAPI->GetProjectionMatrix()._33,
							Engine::GAPI->GetProjectionMatrix()._34);


	// Modify fog when raining
	float rain = Engine::GAPI->GetRainFXWeight();

	// Color
	D3DXVec3Lerp(cb.HF_FogColorMod.toD3DXVECTOR3(), 
		cb.HF_FogColorMod.toD3DXVECTOR3(), 
		&Engine::GAPI->GetRendererState()->RendererSettings.RainFogColor, 
		std::min(1.0f, rain * 2.0f)); // Scale color faster here, so it looks better on light rain

	// Raining Density, only when not in fogzone
	cb.HF_GlobalDensity = Toolbox::lerp(cb.HF_GlobalDensity, Engine::GAPI->GetRendererState()->RendererSettings.RainFogDensity, rain * (1.0f - Engine::GAPI->GetFogOverride()));




	hfPS->GetConstantBuffer()[0]->UpdateBuffer(&cb);
	hfPS->GetConstantBuffer()[0]->BindToPixelShader(0);

	vs->GetConstantBuffer()[0]->UpdateBuffer(&vcb);
	vs->GetConstantBuffer()[0]->BindToVertexShader(0);

	GSky* sky = Engine::GAPI->GetSky();
	hfPS->GetConstantBuffer()[1]->UpdateBuffer(&sky->GetAtmosphereCB());
	hfPS->GetConstantBuffer()[1]->BindToPixelShader(1);

	engine->GetContext()->OMSetRenderTargets(1, &oldRTV, NULL);

	// Bind depthbuffer
	engine->GetDepthBuffer()->BindToPixelShader(engine->GetContext(), 1);

	Engine::GAPI->GetRendererState()->BlendState.SetDefault();
	//Engine::GAPI->GetRendererState()->BlendState.SetAdditiveBlending();
	Engine::GAPI->GetRendererState()->BlendState.BlendEnabled = true;
	Engine::GAPI->GetRendererState()->BlendState.SetDirty();

	// Copy
	FxRenderer->DrawFullScreenQuad();


	// Restore rendertargets
	ID3D11ShaderResourceView* srv = NULL;
	engine->GetContext()->PSSetShaderResources(1,1,&srv);

	engine->GetContext()->OMSetRenderTargets(1, &oldRTV, oldDSV);
	if(oldRTV)oldRTV->Release();
	if(oldDSV)oldDSV->Release();

	return XR_SUCCESS;
}
コード例 #15
0
/** Draws this effect to the given buffer */
XRESULT D3D11PFX_GodRays::Render(RenderToTextureBuffer* fxbuffer)
{
	D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine;

	D3DXVECTOR3 sunPosition = *Engine::GAPI->GetSky()->GetAtmosphereCB().AC_LightPos.toD3DXVECTOR3();
	sunPosition *= Engine::GAPI->GetSky()->GetAtmosphereCB().AC_OuterRadius;
	sunPosition += Engine::GAPI->GetCameraPosition(); // Maybe use cameraposition from sky?

	D3DXMATRIX& view = Engine::GAPI->GetRendererState()->TransformState.TransformView;
	D3DXMATRIX& proj = Engine::GAPI->GetProjectionMatrix();

	D3DXMATRIX viewProj = proj * view;
	D3DXMatrixTranspose(&viewProj, &viewProj);
	D3DXMatrixTranspose(&view, &view);

	D3DXVECTOR3 sunViewPosition;
	D3DXVec3TransformCoord(&sunViewPosition, &sunPosition, &view); // This is for checking if the light is behind the camera
	D3DXVec3TransformCoord(&sunPosition, &sunPosition, &viewProj);

	if(sunViewPosition.z < 0.0f)
		return XR_SUCCESS; // Don't render the godrays when the sun is behind the camera

	GodRayZoomConstantBuffer gcb;
	gcb.GR_Weight = 1.0f;
	gcb.GR_Decay = Engine::GAPI->GetRendererState()->RendererSettings.GodRayDecay;
	gcb.GR_Weight = Engine::GAPI->GetRendererState()->RendererSettings.GodRayWeight;
	gcb.GR_Density = Engine::GAPI->GetRendererState()->RendererSettings.GodRayDensity;
	
	gcb.GR_Center.x = sunPosition.x/2.0f +0.5f;
	gcb.GR_Center.y = sunPosition.y/-2.0f +0.5f;

	gcb.GR_ColorMod = Engine::GAPI->GetRendererState()->RendererSettings.GodRayColorMod;

	if(abs(gcb.GR_Center.x - 0.5f) > 0.5f)
		gcb.GR_Weight *= std::max(0.0f, 1.0f - (abs(gcb.GR_Center.x - 0.5f) - 0.5f) / 0.5f);

	if(abs(gcb.GR_Center.y - 0.5f) > 0.5f)
		gcb.GR_Weight *= std::max(0.0f, 1.0f - (abs(gcb.GR_Center.y - 0.5f) - 0.5f) / 0.5f);



	ID3D11RenderTargetView* oldRTV=NULL;
	ID3D11DepthStencilView* oldDSV=NULL;

	engine->GetContext()->OMGetRenderTargets(1, &oldRTV, &oldDSV);

	D3D11VShader* vs = engine->GetShaderManager()->GetVShader("VS_PFX");
	D3D11PShader* maskPS = engine->GetShaderManager()->GetPShader("PS_PFX_GodRayMask");
	D3D11PShader* zoomPS = engine->GetShaderManager()->GetPShader("PS_PFX_GodRayZoom");
	
	maskPS->Apply();
	vs->Apply();

	// Draw downscaled mask
	engine->GetContext()->OMSetRenderTargets(1, FxRenderer->GetTempBufferDS4_1()->GetRenderTargetViewPtr(), NULL);

	engine->GetHDRBackBuffer()->BindToPixelShader(engine->GetContext(), 0);
	engine->GetGBuffer1()->BindToPixelShader(engine->GetContext(), 1);

	D3D11_VIEWPORT vp;
	vp.TopLeftX = 0.0f;
	vp.TopLeftY = 0.0f;
	vp.MinDepth = 0.0f;
	vp.MaxDepth = 1.0f;
	vp.Width = (float)FxRenderer->GetTempBufferDS4_1()->GetSizeX();
	vp.Height = (float)FxRenderer->GetTempBufferDS4_1()->GetSizeY();

	engine->GetContext()->RSSetViewports(1, &vp);

	FxRenderer->DrawFullScreenQuad();

	// Zoom
	zoomPS->Apply();

	zoomPS->GetConstantBuffer()[0]->UpdateBuffer(&gcb);
	zoomPS->GetConstantBuffer()[0]->BindToPixelShader(0);

	FxRenderer->CopyTextureToRTV(FxRenderer->GetTempBufferDS4_1()->GetShaderResView(), FxRenderer->GetTempBufferDS4_2()->GetRenderTargetView(), INT2(0,0), true);

	// Upscale and blend
	Engine::GAPI->GetRendererState()->BlendState.SetAdditiveBlending();
	Engine::GAPI->GetRendererState()->BlendState.SetDirty();

	FxRenderer->CopyTextureToRTV(FxRenderer->GetTempBufferDS4_2()->GetShaderResView(), oldRTV, INT2(engine->GetResolution().x, engine->GetResolution().y));

	vp.Width = (float)engine->GetResolution().x;
	vp.Height = (float)engine->GetResolution().y;

	engine->GetContext()->RSSetViewports(1, &vp);

	engine->GetContext()->OMSetRenderTargets(1, &oldRTV, oldDSV);
	if(oldRTV)oldRTV->Release();
	if(oldDSV)oldDSV->Release();
	return XR_SUCCESS;
}
コード例 #16
0
ファイル: SV_GMeshInfoView.cpp プロジェクト: DennisGT/GD3D11
/** Updates the view */
void SV_GMeshInfoView::UpdateView()
{
	if(IsHidden())
		return;

	D3D11GraphicsEngine* g = (D3D11GraphicsEngine *)Engine::GraphicsEngine;

	D3DXMatrixPerspectiveFovLH(&ObjectProjMatrix, (float)D3DXToRadian(FOV), GetSize().height / GetSize().width, 0.01f, 10000.0f);
	D3DXMatrixTranspose(&ObjectProjMatrix, &ObjectProjMatrix);

	g->SetDefaultStates();
	Engine::GAPI->GetRendererState()->RasterizerState.CullMode = GothicRasterizerStateInfo::CM_CULL_NONE;
	Engine::GAPI->GetRendererState()->RasterizerState.SetDirty();

	D3DXMATRIX oldProj = Engine::GAPI->GetProjTransform();

	// Set transforms
	Engine::GAPI->SetWorldTransform(ObjectWorldMatrix);
	Engine::GAPI->SetViewTransform(ObjectViewMatrix);
	Engine::GAPI->SetProjTransform(ObjectProjMatrix);

	// Set Viewport
	D3D11_VIEWPORT oldVP; 
	UINT numVP = 1;
	g->GetContext()->RSGetViewports(&numVP, &oldVP);

	D3D11_VIEWPORT vp;
	vp.TopLeftX = 0;
	vp.TopLeftY = 0;
	vp.Width = GetSize().width;
	vp.Height = GetSize().height;
	vp.MinDepth = 0.0f;
	vp.MaxDepth = 1.0f;

	g->GetContext()->RSSetViewports(1, &vp);

	// Clear
	g->GetContext()->ClearRenderTargetView(RT->GetRenderTargetView(), (float *)&D3DXVECTOR4(0,0,0,0));
	g->GetContext()->ClearDepthStencilView(DS->GetDepthStencilView(), D3D11_CLEAR_DEPTH, 1.0f, 0); 

	// Bind RTV
	g->GetContext()->OMSetRenderTargets(1, RT->GetRenderTargetViewPtr(), DS->GetDepthStencilView());

	// Setup shaders
	g->SetActiveVertexShader("VS_Ex");
	g->SetActivePixelShader("PS_DiffuseAlphaTest");

	switch(RenderMode)
	{
	case RM_Lit:
		g->SetActivePixelShader("PS_Preview_TexturedLit");
		DrawMeshes();
		break;

	case RM_Textured:
		g->SetActivePixelShader("PS_Preview_Textured");
		DrawMeshes();
		break;

	case RM_TexturedWireFrame:
		g->SetActivePixelShader("PS_Preview_Textured");
		DrawMeshes();
		// No break here, render wireframe right after

	case RM_Wireframe:
		g->SetActivePixelShader("PS_Preview_White");
		Engine::GAPI->GetRendererState()->RasterizerState.Wireframe = true;
		Engine::GAPI->GetRendererState()->RasterizerState.SetDirty();
		DrawMeshes();
		Engine::GAPI->GetRendererState()->RasterizerState.Wireframe = false;
		Engine::GAPI->GetRendererState()->RasterizerState.SetDirty();
		break;
	}
	// Reset viewport
	g->GetContext()->RSSetViewports(1, &oldVP);
	Engine::GAPI->SetProjTransform(oldProj);

	// Update panel
	Panel->SetD3D11TextureAsImage(RT->GetTexture(), INT2(RT->GetSizeX(), RT->GetSizeY()));
}