Esempio n. 1
0
ObjectPtr<ITexture2D> DX11DeferredRenderer::Draw(const Time& time, unsigned int width, unsigned int height){
	
	graphics_.PushEvent(L"Frame");

	auto& context = DX11Graphics::GetInstance().GetContext();

	// Context setup - The depth and the blend state should be defined per render section, however we support only opaque geometry without any fancy stuffs

	context.PushPipelineState(DX11PipelineState::kDefault);
	
	// Draws only if there's a camera

	ObjectPtr<ITexture2D> output = nullptr;

	auto main_camera = GetScene().GetMainCamera();

	if (main_camera){

		FrameInfo frame_info;

		frame_info.scene = &GetScene();
		frame_info.aspect_ratio = static_cast<float>(width) / static_cast<float>(height);
		frame_info.width = width;
		frame_info.height = height;
		frame_info.view_matrix = main_camera->GetViewTransform().matrix();
		frame_info.view_proj_matrix = GetViewProjectionMatrix(frame_info.aspect_ratio);		// This matrix must be the "real" view projection matrix, regardless of whether the camera is locked or not.
		frame_info.time_delta = time.GetDeltaSeconds();
		frame_info.enable_global_illumination = enable_global_illumination_;

		if (!lock_camera_) {

			frame_info.camera = main_camera;
			
			main_camera->Clone(*locked_camera_);

		}
		else {

			frame_info.camera = locked_camera_;

		}

		DrawGBuffer(frame_info);							// Scene -> GBuffer
		
		if (enable_global_illumination_) {

			voxelization_->Update(frame_info);				// Dynamic voxelization of the scene

		}

		output = ComputeLighting(frame_info);				// Scene, GBuffer, DepthBuffer -> LightBuffer

	}

	// Cleanup

	context.PopPipelineState();

	immediate_context_->ClearState();
	
	// Done

	graphics_.PopEvent();

	return output;

}