/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace AZ { namespace Render { static const char* const EyeAdaptationBufferName = "EyeAdaptationBuffer"; RPI::Ptr EyeAdaptationPass::Create(const RPI::PassDescriptor& descriptor) { RPI::Ptr pass = aznew EyeAdaptationPass(descriptor); return pass; } EyeAdaptationPass::EyeAdaptationPass(const RPI::PassDescriptor& descriptor) : RPI::ComputePass(descriptor) { } void EyeAdaptationPass::InitBuffer() { ExposureCalculationData defaultData; RPI::CommonBufferDescriptor desc; desc.m_poolType = RPI::CommonBufferPoolType::ReadWrite; desc.m_bufferName = EyeAdaptationBufferName; desc.m_byteCount = sizeof(ExposureCalculationData); desc.m_elementSize = aznumeric_cast(desc.m_byteCount); desc.m_bufferData = &defaultData; m_buffer = RPI::BufferSystemInterface::Get()->CreateBufferFromCommonPool(desc); } void EyeAdaptationPass::BuildInternal() { if (!m_buffer) { InitBuffer(); } AttachBufferToSlot(EyeAdaptationDataInputOutputSlotName, m_buffer); } bool EyeAdaptationPass::IsEnabled() const { if (!ComputePass::IsEnabled() || m_pipeline == nullptr) { return false; } AZ_Assert(m_pipeline->GetScene(), "EyeAdaptationPass's Pipeline does not have a valid scene pointer"); AZ::RPI::Scene* scene = GetScene(); bool enabled = false; if (scene) { PostProcessFeatureProcessor* fp = scene->GetFeatureProcessor(); AZ::RPI::ViewPtr view = GetView(); if (fp) { PostProcessSettings* postProcessSettings = fp->GetLevelSettingsFromView(view); if (postProcessSettings) { ExposureControlSettings* settings = postProcessSettings->GetExposureControlSettings(); if (settings) { enabled = true; } } } } return enabled; } void EyeAdaptationPass::FrameBeginInternal(FramePrepareParams params) { AZ::RPI::ComputePass::FrameBeginInternal(params); AZ::RPI::Scene* scene = GetScene(); if (scene) { PostProcessFeatureProcessor* fp = scene->GetFeatureProcessor(); if (fp) { AZ::RPI::ViewPtr view = GetView(); PostProcessSettings* postProcessSettings = fp->GetLevelSettingsFromView(view); if (postProcessSettings) { ExposureControlSettings* settings = postProcessSettings->GetExposureControlSettings(); if (settings) { settings->UpdateBuffer(); view->GetShaderResourceGroup()->SetBufferView(m_exposureControlBufferInputIndex, settings->GetBufferView()); } } } } } } // namespace Render } // namespace AZ