Exemple #1
0
        unsafe void UpdateShaderVariablesGlobalProbeVolumes(ref ShaderVariablesGlobal cb, HDCamera hdCamera)
        {
            if (ShaderConfig.s_ProbeVolumesEvaluationMode == ProbeVolumesEvaluationModes.Disabled)
            {
                return;
            }

            if (!m_SupportProbeVolume)
            {
                UpdateShaderVariablesGlobalProbeVolumesDefault(ref cb, hdCamera);
                return;
            }

            cb._EnableProbeVolumes = hdCamera.frameSettings.IsEnabled(FrameSettingsField.ProbeVolume) ? 1u : 0u;
            cb._ProbeVolumeCount   = (uint)m_VisibleProbeVolumeBounds.Count;
            cb._ProbeVolumeAtlasResolutionAndSliceCount = new Vector4(
                s_ProbeVolumeAtlasWidth,
                s_ProbeVolumeAtlasHeight,
                s_ProbeVolumeAtlasDepth,
                m_ProbeVolumeAtlasSHRTDepthSliceCount
                );
            cb._ProbeVolumeAtlasResolutionAndSliceCountInverse = new Vector4(
                1.0f / (float)s_ProbeVolumeAtlasWidth,
                1.0f / (float)s_ProbeVolumeAtlasHeight,
                1.0f / (float)s_ProbeVolumeAtlasDepth,
                1.0f / (float)m_ProbeVolumeAtlasSHRTDepthSliceCount
                );
            cb._ProbeVolumeAtlasOctahedralDepthResolutionAndInverse = new Vector4(
                m_ProbeVolumeAtlasOctahedralDepthRTHandle.rt.width,
                m_ProbeVolumeAtlasOctahedralDepthRTHandle.rt.height,
                1.0f / (float)m_ProbeVolumeAtlasOctahedralDepthRTHandle.rt.width,
                1.0f / (float)m_ProbeVolumeAtlasOctahedralDepthRTHandle.rt.height
                );

            var settings = hdCamera.volumeStack.GetComponent <ProbeVolumeController>();
            LeakMitigationMode leakMitigationMode = (settings == null)
                ? LeakMitigationMode.NormalBias
                : settings.leakMitigationMode.value;
            float normalBiasWS          = (settings == null) ? 0.0f : settings.normalBiasWS.value;
            float bilateralFilterWeight = (settings == null) ? 0.0f : settings.bilateralFilterWeight.value;

            if (leakMitigationMode != LeakMitigationMode.NormalBias)
            {
                if (leakMitigationMode != LeakMitigationMode.OctahedralDepthOcclusionFilter)
                {
                    normalBiasWS = 0.0f;
                }

                if (bilateralFilterWeight < 1e-5f)
                {
                    // If bilateralFilterWeight is effectively zero, then we are simply doing trilinear filtering.
                    // In this case we can avoid the performance cost of computing our bilateral filter entirely.
                    leakMitigationMode = LeakMitigationMode.NormalBias;
                }
            }

            cb._ProbeVolumeLeakMitigationMode       = (int)leakMitigationMode;
            cb._ProbeVolumeNormalBiasWS             = normalBiasWS;
            cb._ProbeVolumeBilateralFilterWeightMin = 1e-5f;
            cb._ProbeVolumeBilateralFilterWeight    = bilateralFilterWeight;

            SphericalHarmonicsL2 ambientProbeFallbackSH = m_SkyManager.GetAmbientProbe(hdCamera);

            SphericalHarmonicMath.PackCoefficients(s_AmbientProbeFallbackPackedCoeffs, ambientProbeFallbackSH);
            for (int i = 0; i < 7; ++i)
            {
                for (int j = 0; j < 4; ++j)
                {
                    cb._ProbeVolumeAmbientProbeFallbackPackedCoeffs[i * 4 + j] = s_AmbientProbeFallbackPackedCoeffs[i][j];
                }
            }
        }
Exemple #2
0
        void PushProbeVolumesGlobalParams(HDCamera hdCamera, CommandBuffer cmd, int frameIndex)
        {
            if (ShaderConfig.s_ProbeVolumesEvaluationMode == ProbeVolumesEvaluationModes.Disabled)
            {
                return;
            }

            if (!m_SupportProbeVolume)
            {
                PushProbeVolumesGlobalParamsDefault(hdCamera, cmd, frameIndex);
                return;
            }

            cmd.SetGlobalInt(HDShaderIDs._EnableProbeVolumes, hdCamera.frameSettings.IsEnabled(FrameSettingsField.ProbeVolume) ? 1 : 0);
            cmd.SetGlobalBuffer(HDShaderIDs._ProbeVolumeBounds, s_VisibleProbeVolumeBoundsBuffer);
            cmd.SetGlobalBuffer(HDShaderIDs._ProbeVolumeDatas, s_VisibleProbeVolumeDataBuffer);
            cmd.SetGlobalInt(HDShaderIDs._ProbeVolumeCount, m_VisibleProbeVolumeBounds.Count);
            cmd.SetGlobalTexture(HDShaderIDs._ProbeVolumeAtlasSH, m_ProbeVolumeAtlasSHRTHandle);
            cmd.SetGlobalVector(HDShaderIDs._ProbeVolumeAtlasResolutionAndSliceCount, new Vector4(
                                    s_ProbeVolumeAtlasWidth,
                                    s_ProbeVolumeAtlasHeight,
                                    s_ProbeVolumeAtlasDepth,
                                    m_ProbeVolumeAtlasSHRTDepthSliceCount
                                    ));
            cmd.SetGlobalVector(HDShaderIDs._ProbeVolumeAtlasResolutionAndSliceCountInverse, new Vector4(
                                    1.0f / (float)s_ProbeVolumeAtlasWidth,
                                    1.0f / (float)s_ProbeVolumeAtlasHeight,
                                    1.0f / (float)s_ProbeVolumeAtlasDepth,
                                    1.0f / (float)m_ProbeVolumeAtlasSHRTDepthSliceCount
                                    ));
            cmd.SetGlobalTexture(HDShaderIDs._ProbeVolumeAtlasOctahedralDepth, m_ProbeVolumeAtlasOctahedralDepthRTHandle);
            cmd.SetGlobalVector(HDShaderIDs._ProbeVolumeAtlasOctahedralDepthResolutionAndInverse, new Vector4(
                                    m_ProbeVolumeAtlasOctahedralDepthRTHandle.rt.width,
                                    m_ProbeVolumeAtlasOctahedralDepthRTHandle.rt.height,
                                    1.0f / (float)m_ProbeVolumeAtlasOctahedralDepthRTHandle.rt.width,
                                    1.0f / (float)m_ProbeVolumeAtlasOctahedralDepthRTHandle.rt.height
                                    ));

            var settings = hdCamera.volumeStack.GetComponent <ProbeVolumeController>();
            LeakMitigationMode leakMitigationMode = (settings == null)
                ? LeakMitigationMode.NormalBias
                : settings.leakMitigationMode.value;
            float normalBiasWS          = (settings == null) ? 0.0f : settings.normalBiasWS.value;
            float bilateralFilterWeight = (settings == null) ? 0.0f : settings.bilateralFilterWeight.value;

            if (leakMitigationMode != LeakMitigationMode.NormalBias)
            {
                if (leakMitigationMode != LeakMitigationMode.OctahedralDepthOcclusionFilter)
                {
                    normalBiasWS = 0.0f;
                }

                if (bilateralFilterWeight < 1e-5f)
                {
                    // If bilateralFilterWeight is effectively zero, then we are simply doing trilinear filtering.
                    // In this case we can avoid the performance cost of computing our bilateral filter entirely.
                    leakMitigationMode = LeakMitigationMode.NormalBias;
                }
            }

            cmd.SetGlobalInt(HDShaderIDs._ProbeVolumeLeakMitigationMode, (int)leakMitigationMode);
            cmd.SetGlobalFloat(HDShaderIDs._ProbeVolumeNormalBiasWS, normalBiasWS);
            cmd.SetGlobalFloat(HDShaderIDs._ProbeVolumeBilateralFilterWeightMin, 1e-5f);
            cmd.SetGlobalFloat(HDShaderIDs._ProbeVolumeBilateralFilterWeight, bilateralFilterWeight);

            {
                SphericalHarmonicsL2 ambientProbeFallbackSH = m_SkyManager.GetAmbientProbe(hdCamera);
                SphericalHarmonicMath.PackCoefficients(s_AmbientProbeFallbackPackedCoeffs, ambientProbeFallbackSH);
                cmd.SetGlobalVectorArray(HDShaderIDs._ProbeVolumeAmbientProbeFallbackPackedCoeffs, s_AmbientProbeFallbackPackedCoeffs);
            }
        }