/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #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::BuildAttachmentsInternal() { 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