コード例 #1
0
ファイル: D3D11PointLight.cpp プロジェクト: Katharsas/GD3D11
/** Renders all cubemap faces at once, using the geometry shader */
void D3D11PointLight::RenderFullCubemap()
{
	D3D11GraphicsEngineBase* engineBase = (D3D11GraphicsEngineBase *)Engine::GraphicsEngine;
	D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *) engineBase; // TODO: Remove and use newer system!

	// 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 no npcs if this is a static light. This is archived by simply not drawing them in the first update
	bool noNPCs = !DrawnOnce;//!LightInfo->Vob->IsStatic();

	// Draw cubemap
	std::map<MeshKey, WorldMeshInfo*, cmpMeshKey>* wc = &WorldMeshCache;

	// Don't use the cache if we have moved
	if(WorldCacheInvalid)
		wc = NULL;

	engine->RenderShadowCube(LightInfo->Vob->GetPositionWorld(), range, DepthCubemap, NULL, NULL, false, LightInfo->IsIndoorVob, noNPCs, &VobCache, &SkeletalVobCache, wc);

	//Engine::GAPI->GetRendererState()->RendererSettings.DrawSkeletalMeshes = oldDrawSkel;
}
コード例 #2
0
ファイル: D3D11PfxRenderer.cpp プロジェクト: Katharsas/GD3D11
/** Renders the SMAA-Effect */
XRESULT D3D11PfxRenderer::RenderSMAA()
{
	D3D11GraphicsEngine* engine = (D3D11GraphicsEngine*)Engine::GraphicsEngine;
	FX_SMAA->RenderPostFX(engine->GetHDRBackBuffer()->GetShaderResView());

	return XR_SUCCESS;
}
コード例 #3
0
ファイル: D3D11Vertexbuffer.cpp プロジェクト: DennisGT/GD3D11
/** Unmaps the buffer */
XRESULT D3D11VertexBuffer::Unmap()
{
	D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine;

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

	return XR_SUCCESS;
}
コード例 #4
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;
}
コード例 #5
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;
}
コード例 #6
0
ファイル: GOcean.cpp プロジェクト: DennisGT/GD3D11
/** Draws the ocean */
void GOcean::Draw()
{
	if(Patches.empty())
		return;

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

	engine->SetDefaultStates();
	FFTOceanSimulator->updateDisplacementMap(Engine::GAPI->GetTimeSeconds());

	engine->DrawOcean(this);
}
コード例 #7
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;
}
コード例 #8
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;
}
コード例 #9
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);
	}
}
コード例 #10
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;
}
コード例 #11
0
ファイル: GOcean.cpp プロジェクト: DennisGT/GD3D11
/** Initializes the ocean */
XRESULT GOcean::InitOcean()
{
	D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine;

	PlaneMesh = new GMesh;
	if(XR_SUCCESS != PlaneMesh->LoadMesh("system\\GD3D11\\Meshes\\PlaneSubdiv.3ds"))
	{
		delete PlaneMesh;
		PlaneMesh = NULL;
		return XR_FAILED;
	}

	// Create ocean simulating object
	// Ocean object
	OceanParameter ocean_param;

	// The size of displacement map. In this sample, it's fixed to 512.
	ocean_param.dmap_dim			= 512;
	// The side length (world space) of square patch
	ocean_param.patch_length		= 2000.0f;
	// Adjust this parameter to control the simulation speed
	ocean_param.time_scale			= 0.8f;
	// A scale to control the amplitude. Not the world space height
	ocean_param.wave_amplitude		= 0.35f;
	// 2D wind direction. No need to be normalized
	ocean_param.wind_dir			= D3DXVECTOR2(0.8f, 0.6f);
	// The bigger the wind speed, the larger scale of wave crest.
	// But the wave scale can be no larger than patch_length
	ocean_param.wind_speed			= 600.0f;
	// Damp out the components opposite to wind direction.
	// The smaller the value, the higher wind dependency
	ocean_param.wind_dependency		= 0.07f;
	// Control the scale of horizontal movement. Higher value creates
	// pointy crests.
	ocean_param.choppy_scale		= 1.3f;

	FFTOceanSimulator = new OceanSimulator(ocean_param, engine->GetDevice());

	// Update the simulation for the first time.
	FFTOceanSimulator->updateDisplacementMap(0);

	// Create fresnel map
	CreateFresnelMap(engine->GetDevice());

	return XR_SUCCESS;
}
コード例 #12
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);
}
コード例 #13
0
ファイル: D3D11Vertexbuffer.cpp プロジェクト: DennisGT/GD3D11
/** Creates the vertexbuffer with the given arguments */
XRESULT D3D11VertexBuffer::Init(void* initData, unsigned int sizeInBytes, EBindFlags EBindFlags, EUsageFlags usage, ECPUAccessFlags cpuAccess, const std::string& fileName)
{
	HRESULT hr;
	D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine;

	if (sizeInBytes == 0)
	{
		LogError() << "VertexBuffer size can't be 0!";
	}

	SizeInBytes = sizeInBytes;

	// Create our own vertexbuffer
	D3D11_BUFFER_DESC bufferDesc;
	bufferDesc.ByteWidth = sizeInBytes;
	bufferDesc.Usage = (D3D11_USAGE)usage;
	bufferDesc.BindFlags = (D3D11_BIND_FLAG)EBindFlags;
	bufferDesc.CPUAccessFlags = (D3D11_CPU_ACCESS_FLAG)cpuAccess;
	bufferDesc.MiscFlags = 0;

	// In case we dont have data, allocate some to satisfy D3D11
	char* data = NULL;
	if (!initData)
	{
		data = new char[bufferDesc.ByteWidth];
		memset(data, 0, bufferDesc.ByteWidth);

		initData = data;
	}

	D3D11_SUBRESOURCE_DATA InitData;
	InitData.pSysMem = initData;
	InitData.SysMemPitch = 0;
	InitData.SysMemSlicePitch = 0;

	LE(engine->GetDevice()->CreateBuffer(&bufferDesc, &InitData, &VertexBuffer));

#ifndef PUBLIC_RELEASE
	VertexBuffer->SetPrivateData(WKPDID_D3DDebugObjectName, fileName.size(), fileName.c_str());
#endif

	delete[] data;

	return XR_SUCCESS;
}
コード例 #14
0
ファイル: D3D11PfxRenderer.cpp プロジェクト: Katharsas/GD3D11
/** Called on resize */
XRESULT D3D11PfxRenderer::OnResize(const INT2& newResolution)
{
	D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine;

	// Create temp-buffer
	delete TempBuffer;
	TempBuffer = new RenderToTextureBuffer(engine->GetDevice(), newResolution.x, newResolution.y, DXGI_FORMAT_R16G16B16A16_FLOAT, NULL);

	delete TempBufferDS4_1;
	TempBufferDS4_1 = new RenderToTextureBuffer(engine->GetDevice(), newResolution.x / 4, newResolution.y / 4, DXGI_FORMAT_R16G16B16A16_FLOAT, NULL);

	delete TempBufferDS4_2;
	TempBufferDS4_2 = new RenderToTextureBuffer(engine->GetDevice(), newResolution.x / 4, newResolution.y / 4, DXGI_FORMAT_R16G16B16A16_FLOAT, NULL);
	
	FX_SMAA->OnResize(newResolution);

	return XR_SUCCESS;
}
コード例 #15
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;
}
コード例 #16
0
ファイル: SV_GMeshInfoView.cpp プロジェクト: DennisGT/GD3D11
/** Sets the position and size of this sub-view */
void SV_GMeshInfoView::SetRect(const D2D1_RECT_F& rect)
{
	D3D11GraphicsEngine* g = (D3D11GraphicsEngine *)Engine::GraphicsEngine;

	D2DSubView::SetRect(rect);

	Panel->SetRect(D2D1::RectF(0, 0, GetSize().width, GetSize().height));

	// Create new RT
	delete RT;
	RT = new RenderToTextureBuffer(g->GetDevice(), 
		(UINT)std::max(8.0f, GetSize().width), 
		(UINT)std::max(8.0f, GetSize().height), 
		DXGI_FORMAT_R8G8B8A8_UNORM);

	delete DS;
	DS = new RenderToDepthStencilBuffer(g->GetDevice(), 
		(UINT)std::max(8.0f, GetSize().width), 
		(UINT)std::max(8.0f, GetSize().height), 
		DXGI_FORMAT_R32_TYPELESS, NULL, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_R32_FLOAT);
}
コード例 #17
0
ファイル: D3D11PfxRenderer.cpp プロジェクト: Katharsas/GD3D11
D3D11PfxRenderer::D3D11PfxRenderer(void)
{
	TempBuffer = NULL;
	TempBufferDS4_1 = NULL;
	TempBufferDS4_2 = NULL;

	FX_Blur = NULL;

	D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine;
	ScreenQuad = new D3D11FullscreenQuad;
	ScreenQuad->CreateQuad(engine->GetDevice());

	FX_Blur = new D3D11PFX_Blur(this);
	FX_HeightFog = new D3D11PFX_HeightFog(this);
	//FX_DistanceBlur = new D3D11PFX_DistanceBlur(this);
	FX_HDR = new D3D11PFX_HDR(this);
	FX_SMAA = new D3D11PFX_SMAA(this);

	FX_GodRays = new D3D11PFX_GodRays(this);

	NvHBAO = new D3D11NVHBAO;
	NvHBAO->Init();
}
コード例 #18
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);

}
コード例 #19
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;
}
コード例 #20
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()));
}
コード例 #21
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;
}
コード例 #22
0
ファイル: D3D11VShader.cpp プロジェクト: DennisGT/GD3D11
/** Loads shader */
XRESULT D3D11VShader::LoadShader(const char* vertexShader, int layout, std::vector<D3D10_SHADER_MACRO>& makros)
{
	HRESULT hr;
	D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine;

	ID3DBlob* vsBlob;

	LogInfo() << "Compilling vertex shader: " << vertexShader;
	File = vertexShader;


	// Compile shader
	if(FAILED(CompileShaderFromFile(vertexShader, "VSMain", "vs_4_0", &vsBlob, makros)))
	{
		return XR_FAILED;
	}

	// Create the shader
	LE(engine->GetDevice()->CreateVertexShader(vsBlob->GetBufferPointer(),
		vsBlob->GetBufferSize(), NULL, &VertexShader));

#ifndef PUBLIC_RELEASE
	VertexShader->SetPrivateData(WKPDID_D3DDebugObjectName, strlen(vertexShader), vertexShader);
#endif


	const D3D11_INPUT_ELEMENT_DESC layout1[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 1, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "DIFFUSE", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	};

	const D3D11_INPUT_ELEMENT_DESC layout2[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	};

	const D3D11_INPUT_ELEMENT_DESC layout3[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "POSITION", 1, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "POSITION", 2, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "POSITION", 3, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "DIFFUSE", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "BONEIDS", 0, DXGI_FORMAT_R8G8B8A8_UINT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "WEIGHTS", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	};

	const D3D11_INPUT_ELEMENT_DESC layout4[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 1, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "DIFFUSE", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "INSTANCE_WORLD_MATRIX", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1},
		{ "INSTANCE_WORLD_MATRIX", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1},
		{ "INSTANCE_WORLD_MATRIX", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1},
		{ "INSTANCE_WORLD_MATRIX", 3, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1},
		{ "INSTANCE_COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1 },
		{ "INSTANCE_SCALE", 0, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1 },
	};

	const D3D11_INPUT_ELEMENT_DESC layout5[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	};

	const D3D11_INPUT_ELEMENT_DESC layout6[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "DIFFUSE", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	};

	const D3D11_INPUT_ELEMENT_DESC layout7[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "DIFFUSE", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },

	};

	const D3D11_INPUT_ELEMENT_DESC layout8[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	};

	const D3D11_INPUT_ELEMENT_DESC layout9[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },	
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },

		{ "INSTANCE_WORLD_MATRIX", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1},
		{ "INSTANCE_WORLD_MATRIX", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1},
		{ "INSTANCE_WORLD_MATRIX", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1},
		{ "INSTANCE_WORLD_MATRIX", 3, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1},
	};

	const D3D11_INPUT_ELEMENT_DESC layout10[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 1, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "DIFFUSE", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "INSTANCE_WORLD_MATRIX", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1},
		{ "INSTANCE_WORLD_MATRIX", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1},
		{ "INSTANCE_WORLD_MATRIX", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1},
		{ "INSTANCE_WORLD_MATRIX", 3, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1},
		//{ "INSTANCE_COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1 },
	};

	switch (layout)
	{
	case 1:
		LE(engine->GetDevice()->CreateInputLayout(layout1, ARRAYSIZE(layout1), vsBlob->GetBufferPointer(),
			vsBlob->GetBufferSize(), &InputLayout));
		break;

	case 2:
		LE(engine->GetDevice()->CreateInputLayout(layout2, ARRAYSIZE(layout2), vsBlob->GetBufferPointer(),
			vsBlob->GetBufferSize(), &InputLayout));
		break;

	case 3:
		LE(engine->GetDevice()->CreateInputLayout(layout3, ARRAYSIZE(layout3), vsBlob->GetBufferPointer(),
			vsBlob->GetBufferSize(), &InputLayout));
		break;

	case 4:
		LE(engine->GetDevice()->CreateInputLayout(layout4, ARRAYSIZE(layout4), vsBlob->GetBufferPointer(),
			vsBlob->GetBufferSize(), &InputLayout));
		break;

	case 5:
		LE(engine->GetDevice()->CreateInputLayout(layout5, ARRAYSIZE(layout5), vsBlob->GetBufferPointer(),
			vsBlob->GetBufferSize(), &InputLayout));
		break;

	case 6:
		LE(engine->GetDevice()->CreateInputLayout(layout6, ARRAYSIZE(layout6), vsBlob->GetBufferPointer(),
			vsBlob->GetBufferSize(), &InputLayout));
		break;

	case 7:
		LE(engine->GetDevice()->CreateInputLayout(layout7, ARRAYSIZE(layout7), vsBlob->GetBufferPointer(),
			vsBlob->GetBufferSize(), &InputLayout));
		break;

	case 8:
		LE(engine->GetDevice()->CreateInputLayout(layout8, ARRAYSIZE(layout8), vsBlob->GetBufferPointer(),
			vsBlob->GetBufferSize(), &InputLayout));
		break;

	case 9:
		LE(engine->GetDevice()->CreateInputLayout(layout9, ARRAYSIZE(layout9), vsBlob->GetBufferPointer(),
			vsBlob->GetBufferSize(), &InputLayout));
		break;

	case 10:
		LE(engine->GetDevice()->CreateInputLayout(layout10, ARRAYSIZE(layout10), vsBlob->GetBufferPointer(),
			vsBlob->GetBufferSize(), &InputLayout));
		break;
	}

	return XR_SUCCESS;
}
コード例 #23
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;
}
コード例 #24
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() );
			}
		}


		
	}

	
}
コード例 #25
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;
}