コード例 #1
0
void ParticleEffects::Render( CommandContext& Context, const Camera& Camera, ColorBuffer& ColorTarget, DepthBuffer& DepthTarget, ColorBuffer& LinearDepth)
{
	if (!Enable || !s_InitComplete || ParticleEffectsActive.size() == 0)
		return;

	ScopedTimer _prof(L"Particle Render", Context);

	uint32_t Width = (uint32_t)ColorTarget.GetWidth();
	uint32_t Height = (uint32_t)ColorTarget.GetHeight();
	uint32_t BinsPerRow = 4 * DivideByMultiple(Width, 4 * BIN_SIZE_X);

	s_ChangesPerView.gViewProj = Camera.GetViewProjMatrix();  
	s_ChangesPerView.gInvView = Invert(Camera.GetViewMatrix());
	float HCot = Camera.GetProjMatrix().GetX().GetX();
	float VCot = Camera.GetProjMatrix().GetY().GetY();
	s_ChangesPerView.gVertCotangent = VCot;
	s_ChangesPerView.gAspectRatio = HCot / VCot;
	s_ChangesPerView.gRcpFarZ = 1.0f / Camera.GetFarClip();
	s_ChangesPerView.gInvertZ = Camera.GetNearClip() / (Camera.GetFarClip() - Camera.GetNearClip());
	s_ChangesPerView.gBufferWidth = (float)ColorTarget.GetWidth();
	s_ChangesPerView.gBufferHeight = (float)ColorTarget.GetHeight();
	s_ChangesPerView.gRcpBufferWidth = 1.0f / ColorTarget.GetWidth();
	s_ChangesPerView.gRcpBufferHeight = 1.0f / ColorTarget.GetHeight();
	s_ChangesPerView.gBinsPerRow = BinsPerRow;
	s_ChangesPerView.gTileRowPitch = BinsPerRow * TILES_PER_BIN_X;
	s_ChangesPerView.gTilesPerRow = DivideByMultiple(Width, TILE_SIZE);
	s_ChangesPerView.gTilesPerCol = DivideByMultiple(Height, TILE_SIZE);


	if (EnableTiledRendering)
	{
		ComputeContext& CompContext = Context.GetComputeContext();
		CompContext.ClearUAV(BinCounters[0]);
		CompContext.ClearUAV(BinCounters[1]);
		CompContext.SetRootSignature(RootSig);
		CompContext.SetDynamicConstantBufferView(1, sizeof(CBChangesPerView), &s_ChangesPerView);	
		RenderTiles(CompContext, ColorTarget, LinearDepth);
	}
	else
	{
		GraphicsContext& GrContext = Context.GetGraphicsContext();
		GrContext.SetRootSignature(RootSig);
		GrContext.SetDynamicConstantBufferView(1, sizeof(CBChangesPerView), &s_ChangesPerView);	
		RenderSprites(GrContext, ColorTarget, DepthTarget, LinearDepth);
	}

}
コード例 #2
0
void ParticleEffects::Render( CommandContext& Context, const Camera& Camera, ColorBuffer& ColorTarget, DepthBuffer& DepthTarget, ColorBuffer& LinearDepth)
{
	if (!Enable || !s_InitComplete || ParticleEffectsActive.size() == 0)
		return;

	uint32_t Width = (uint32_t)ColorTarget.GetWidth();
	uint32_t Height = (uint32_t)ColorTarget.GetHeight();

	ASSERT(
		Width == DepthTarget.GetWidth() &&
		Height == DepthTarget.GetHeight() &&
		Width == LinearDepth.GetWidth() &&
		Height == LinearDepth.GetHeight(),
		"There is a mismatch in buffer dimensions for rendering particles"
	);

	ScopedTimer _prof(L"Particle Render", Context);

	uint32_t BinsPerRow = 4 * DivideByMultiple(Width, 4 * BIN_SIZE_X);

	s_ChangesPerView.gViewProj = Camera.GetViewProjMatrix();  
	s_ChangesPerView.gInvView = Invert(Camera.GetViewMatrix());
	float HCot = Camera.GetProjMatrix().GetX().GetX();
	float VCot = Camera.GetProjMatrix().GetY().GetY();
	s_ChangesPerView.gVertCotangent = VCot;
	s_ChangesPerView.gAspectRatio = HCot / VCot;
	s_ChangesPerView.gRcpFarZ = 1.0f / Camera.GetFarClip();
	s_ChangesPerView.gInvertZ = Camera.GetNearClip() / (Camera.GetFarClip() - Camera.GetNearClip());
	s_ChangesPerView.gBufferWidth = (float)Width;
	s_ChangesPerView.gBufferHeight = (float)Height;
	s_ChangesPerView.gRcpBufferWidth = 1.0f / Width;
	s_ChangesPerView.gRcpBufferHeight = 1.0f / Height;
	s_ChangesPerView.gBinsPerRow = BinsPerRow;
	s_ChangesPerView.gTileRowPitch = BinsPerRow * TILES_PER_BIN_X;
	s_ChangesPerView.gTilesPerRow = DivideByMultiple(Width, TILE_SIZE);
	s_ChangesPerView.gTilesPerCol = DivideByMultiple(Height, TILE_SIZE);

	// For now, UAV load support for R11G11B10 is required to read-modify-write the color buffer, but
	// the compositing could be deferred.
	WARN_ONCE_IF(EnableTiledRendering && !g_bTypedUAVLoadSupport_R11G11B10_FLOAT,
		"Unable to composite tiled particles without support for R11G11B10F UAV loads");
	EnableTiledRendering = EnableTiledRendering && g_bTypedUAVLoadSupport_R11G11B10_FLOAT;

	if (EnableTiledRendering)
	{
		ComputeContext& CompContext = Context.GetComputeContext();
		CompContext.TransitionResource(ColorTarget, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
		CompContext.TransitionResource(BinCounters[0], D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
		CompContext.TransitionResource(BinCounters[1], D3D12_RESOURCE_STATE_UNORDERED_ACCESS, true);

		CompContext.ClearUAV(BinCounters[0]);
		CompContext.ClearUAV(BinCounters[1]);
		CompContext.SetRootSignature(RootSig);
		CompContext.SetDynamicConstantBufferView(1, sizeof(CBChangesPerView), &s_ChangesPerView);

		RenderTiles(CompContext, ColorTarget, LinearDepth);

		CompContext.InsertUAVBarrier(ColorTarget);
	}
	else
	{
		GraphicsContext& GrContext = Context.GetGraphicsContext();
		GrContext.SetRootSignature(RootSig);
		GrContext.SetDynamicConstantBufferView(1, sizeof(CBChangesPerView), &s_ChangesPerView);	
		RenderSprites(GrContext, ColorTarget, DepthTarget, LinearDepth);
	}

}