コード例 #1
0
        void UpdateShaderVariablesGlobalVolumetrics(ref ShaderVariablesGlobal cb, HDCamera hdCamera)
        {
            if (!Fog.IsVolumetricFogEnabled(hdCamera))
            {
                return;
            }

            // Get the interpolated anisotropy value.
            var fog        = hdCamera.volumeStack.GetComponent <Fog>();
            int frameIndex = m_FrameCount;
            int currIdx    = (frameIndex + 0) & 1;

            var currParams = hdCamera.vBufferParams[currIdx];

            // The lighting & density buffers are shared by all cameras.
            // The history & feedback buffers are specific to the camera.
            // These 2 types of buffers can have different sizes.
            // Additionally, history buffers can have different sizes, since they are not resized at the same time.
            var cvp = currParams.viewportSize;

            // Adjust slices for XR rendering: VBuffer is shared for all single-pass views
            uint sliceCount = (uint)(cvp.z / hdCamera.viewCount);

            cb._VBufferViewportSize           = new Vector4(cvp.x, cvp.y, 1.0f / cvp.x, 1.0f / cvp.y);
            cb._VBufferSliceCount             = sliceCount;
            cb._VBufferRcpSliceCount          = 1.0f / sliceCount;
            cb._VBufferLightingViewportScale  = currParams.ComputeViewportScale(m_CurrentVolumetricBufferSize);
            cb._VBufferLightingViewportLimit  = currParams.ComputeViewportLimit(m_CurrentVolumetricBufferSize);
            cb._VBufferDistanceEncodingParams = currParams.depthEncodingParams;
            cb._VBufferDistanceDecodingParams = currParams.depthDecodingParams;
            cb._VBufferLastSliceDist          = currParams.ComputeLastSliceDistance(sliceCount);
            cb._VBufferRcpInstancedViewCount  = 1.0f / hdCamera.viewCount;
        }
コード例 #2
0
ファイル: Fog.cs プロジェクト: stramit/Graphics
        void UpdateShaderVariablesGlobalCBFogParameters(ref ShaderVariablesGlobal cb, HDCamera hdCamera)
        {
            bool enableVolumetrics = enableVolumetricFog.value && hdCamera.frameSettings.IsEnabled(FrameSettingsField.Volumetrics);

            cb._FogEnabled          = 1;
            cb._PBRFogEnabled       = IsPBRFogEnabled(hdCamera) ? 1 : 0;
            cb._EnableVolumetricFog = enableVolumetrics ? 1 : 0;
            cb._MaxFogDistance      = maxFogDistance.value;

            Color fogColor = (colorMode.value == FogColorMode.ConstantColor) ? color.value : tint.value;

            cb._FogColorMode     = (float)colorMode.value;
            cb._FogColor         = new Color(fogColor.r, fogColor.g, fogColor.b, 0.0f);
            cb._MipFogParameters = new Vector4(mipFogNear.value, mipFogFar.value, mipFogMaxMip.value, 0.0f);

            DensityVolumeArtistParameters param = new DensityVolumeArtistParameters(albedo.value, meanFreePath.value, anisotropy.value);
            DensityVolumeEngineData       data  = param.ConvertToEngineData();

            cb._HeightFogBaseScattering = data.scattering;
            cb._HeightFogBaseExtinction = data.extinction;

            float crBaseHeight = baseHeight.value;

            if (ShaderConfig.s_CameraRelativeRendering != 0)
            {
                crBaseHeight -= hdCamera.camera.transform.position.y;
            }

            float layerDepth = Mathf.Max(0.01f, maximumHeight.value - baseHeight.value);
            float H          = ScaleHeightFromLayerDepth(layerDepth);

            cb._HeightFogExponents  = new Vector2(1.0f / H, H);
            cb._HeightFogBaseHeight = crBaseHeight;
            cb._GlobalFogAnisotropy = anisotropy.value;
        }
コード例 #3
0
ファイル: HDShadowManager.cs プロジェクト: Si1ver/Graphics
 public void UpdateShaderVariablesGlobalCB(ref ShaderVariablesGlobal cb)
 {
     cb._CascadeShadowCount     = (uint)(m_CascadeCount + 1);
     cb._ShadowAtlasSize        = new Vector4(m_Atlas.width, m_Atlas.height, 1.0f / m_Atlas.width, 1.0f / m_Atlas.height);
     cb._CascadeShadowAtlasSize = new Vector4(m_CascadeAtlas.width, m_CascadeAtlas.height, 1.0f / m_CascadeAtlas.width, 1.0f / m_CascadeAtlas.height);
     if (ShaderConfig.s_AreaLights == 1)
     {
         cb._AreaShadowAtlasSize = new Vector4(m_AreaLightShadowAtlas.width, m_AreaLightShadowAtlas.height, 1.0f / m_AreaLightShadowAtlas.width, 1.0f / m_AreaLightShadowAtlas.height);
     }
 }
コード例 #4
0
ファイル: Fog.cs プロジェクト: JohnyMcDoe/Assignment-2-455
 static void UpdateShaderVariablesGlobalCBNeutralParameters(ref ShaderVariablesGlobal cb)
 {
     cb._FogEnabled              = 0;
     cb._EnableVolumetricFog     = 0;
     cb._HeightFogBaseScattering = Vector3.zero;
     cb._HeightFogBaseExtinction = 0.0f;
     cb._HeightFogExponents      = Vector2.one;
     cb._HeightFogBaseHeight     = 0.0f;
     cb._GlobalFogAnisotropy     = 0.0f;
 }
コード例 #5
0
        private void UpdateShaderVariablesProbeVolumes(ref ShaderVariablesGlobal cb, HDCamera hdCamera, CommandBuffer cmd)
        {
            bool loadedData = ProbeReferenceVolume.instance.DataHasBeenLoaded();

            cb._EnableProbeVolumes = (hdCamera.frameSettings.IsEnabled(FrameSettingsField.ProbeVolume) && loadedData) ? 1u : 0u;

            var probeVolumeOptions = hdCamera.volumeStack.GetComponent <ProbeVolumesOptions>();
            var normalBias         = probeVolumeOptions.normalBias.value;

            if (cb._EnableProbeVolumes > 0)
            {
                ProbeReferenceVolume.instance.UpdateConstantBuffer(cmd, normalBias);
            }
        }
コード例 #6
0
ファイル: Fog.cs プロジェクト: JohnyMcDoe/Assignment-2-455
        internal static void UpdateShaderVariablesGlobalCB(ref ShaderVariablesGlobal cb, HDCamera hdCamera)
        {
            // TODO Handle user override
            var fogSettings = hdCamera.volumeStack.GetComponent <Fog>();

            if (!hdCamera.frameSettings.IsEnabled(FrameSettingsField.AtmosphericScattering) || !fogSettings.enabled.value)
            {
                UpdateShaderVariablesGlobalCBNeutralParameters(ref cb);
            }
            else
            {
                fogSettings.UpdateShaderVariablesGlobalCBFogParameters(ref cb, hdCamera);
            }
        }
コード例 #7
0
        public void UpdateShaderVariablesGlobalCB(ref ShaderVariablesGlobal cb)
        {
            if (m_MaxShadowRequests == 0)
            {
                return;
            }

            cb._CascadeShadowCount     = (uint)(m_CascadeCount + 1);
            cb._ShadowAtlasSize        = new Vector4(m_Atlas.width, m_Atlas.height, 1.0f / m_Atlas.width, 1.0f / m_Atlas.height);
            cb._CascadeShadowAtlasSize = new Vector4(m_CascadeAtlas.width, m_CascadeAtlas.height, 1.0f / m_CascadeAtlas.width, 1.0f / m_CascadeAtlas.height);
            cb._CachedShadowAtlasSize  = new Vector4(cachedShadowManager.punctualShadowAtlas.width, cachedShadowManager.punctualShadowAtlas.height, 1.0f / cachedShadowManager.punctualShadowAtlas.width, 1.0f / cachedShadowManager.punctualShadowAtlas.height);
            if (ShaderConfig.s_AreaLights == 1)
            {
                cb._AreaShadowAtlasSize       = new Vector4(m_AreaLightShadowAtlas.width, m_AreaLightShadowAtlas.height, 1.0f / m_AreaLightShadowAtlas.width, 1.0f / m_AreaLightShadowAtlas.height);
                cb._CachedAreaShadowAtlasSize = new Vector4(cachedShadowManager.areaShadowAtlas.width, cachedShadowManager.areaShadowAtlas.height, 1.0f / cachedShadowManager.areaShadowAtlas.width, 1.0f / cachedShadowManager.areaShadowAtlas.height);
            }
        }
コード例 #8
0
        private void UpdateShaderVariablesProbeVolumes(ref ShaderVariablesGlobal cb, HDCamera hdCamera, CommandBuffer cmd)
        {
            bool loadedData = ProbeReferenceVolume.instance.DataHasBeenLoaded();

            cb._EnableProbeVolumes = (hdCamera.frameSettings.IsEnabled(FrameSettingsField.ProbeVolume) && loadedData) ? 1u : 0u;

            var probeVolumeOptions = hdCamera.volumeStack.GetComponent <ProbeVolumesOptions>();

            if (cb._EnableProbeVolumes > 0)
            {
                ProbeVolumeShadingParameters parameters;
                parameters.normalBias = probeVolumeOptions.normalBias.value;
                parameters.viewBias   = probeVolumeOptions.viewBias.value;
                parameters.scaleBiasByMinDistanceBetweenProbes = probeVolumeOptions.scaleBiasWithMinProbeDistance.value;
                parameters.samplingNoise = probeVolumeOptions.samplingNoise.value;
                ProbeReferenceVolume.instance.UpdateConstantBuffer(cmd, parameters);
            }
        }
コード例 #9
0
        unsafe void UpdateShaderVariablesGlobalSubsurface(ref ShaderVariablesGlobal cb, HDCamera hdCamera)
        {
            UpdateCurrentDiffusionProfileSettings(hdCamera);

            cb._DiffusionProfileCount      = (uint)m_SSSActiveDiffusionProfileCount;
            cb._EnableSubsurfaceScattering = hdCamera.frameSettings.IsEnabled(FrameSettingsField.SubsurfaceScattering) ? 1u : 0u;
            cb._TexturingModeFlags         = m_SSSTexturingModeFlags;
            cb._TransmissionFlags          = m_SSSTransmissionFlags;

            for (int i = 0; i < m_SSSActiveDiffusionProfileCount; ++i)
            {
                for (int c = 0; c < 4; ++c) // Vector4 component
                {
                    cb._ShapeParamsAndMaxScatterDists[i * 4 + c] = m_SSSShapeParamsAndMaxScatterDists[i][c];
                    // To disable transmission, we simply nullify the transmissionTint
                    cb._TransmissionTintsAndFresnel0[i * 4 + c] = hdCamera.frameSettings.IsEnabled(FrameSettingsField.Transmission) ? m_SSSTransmissionTintsAndFresnel0[i][c] : m_SSSDisabledTransmissionTintsAndFresnel0[i][c];
                    cb._WorldScalesAndFilterRadiiAndThicknessRemaps[i * 4 + c] = m_SSSWorldScalesAndFilterRadiiAndThicknessRemaps[i][c];
                }

                cb._DiffusionProfileHashTable[i * 4] = m_SSSDiffusionProfileHashes[i];
            }
        }
コード例 #10
0
        unsafe void UpdateShaderVariablesGlobalProbeVolumesDefault(ref ShaderVariablesGlobal cb, HDCamera hdCamera)
        {
            cb._EnableProbeVolumes                  = 0;
            cb._ProbeVolumeCount                    = 0;
            cb._ProbeVolumeLeakMitigationMode       = (int)LeakMitigationMode.NormalBias;
            cb._ProbeVolumeNormalBiasWS             = 0.0f;
            cb._ProbeVolumeBilateralFilterWeightMin = 0.0f;
            cb._ProbeVolumeBilateralFilterWeight    = 0.0f;

            // Need to populate ambient probe fallback even in the default case,
            // As if the feature is enabled in the ShaderConfig, but disabled in the HDRenderPipelineAsset, we need to fallback to ambient probe only.
            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];
                }
            }
        }
コード例 #11
0
        private void UpdateShaderVariablesProbeVolumes(ref ShaderVariablesGlobal cb, HDCamera hdCamera, CommandBuffer cmd)
        {
            bool loadedData         = ProbeReferenceVolume.instance.DataHasBeenLoaded();
            var  weight             = ProbeReferenceVolume.instance.probeVolumesWeight;
            var  probeVolumeOptions = hdCamera.volumeStack.GetComponent <ProbeVolumesOptions>();

            cb._EnableProbeVolumes = (hdCamera.frameSettings.IsEnabled(FrameSettingsField.ProbeVolume) && loadedData && weight > 0f) ? 1u : 0u;

            if (cb._EnableProbeVolumes > 0)
            {
                ProbeVolumeShadingParameters parameters;
                parameters.normalBias = probeVolumeOptions.normalBias.value;
                parameters.viewBias   = probeVolumeOptions.viewBias.value;
                parameters.scaleBiasByMinDistanceBetweenProbes = probeVolumeOptions.scaleBiasWithMinProbeDistance.value;
                parameters.samplingNoise               = probeVolumeOptions.samplingNoise.value;
                parameters.weight                      = weight;
                parameters.leakReductionMode           = hdCamera.camera.cameraType == CameraType.Reflection ? APVLeakReductionMode.None : probeVolumeOptions.leakReductionMode.value;
                parameters.occlusionWeightContribution = 1.0f;

                parameters.minValidNormalWeight = probeVolumeOptions.minValidDotProductValue.value;
                ProbeReferenceVolume.instance.UpdateConstantBuffer(cmd, parameters);
            }
        }
コード例 #12
0
        private void SetupGlobalParamsForCubemapInternal(CommandBuffer cmd, HDCamera hdCamera, int cubemapSize, ref ShaderVariablesGlobal cb, out Matrix4x4 proj)
        {
            var gpuView = hdCamera.camera.worldToCameraMatrix;

            if (ShaderConfig.s_CameraRelativeRendering != 0)
            {
                gpuView.SetColumn(3, new Vector4(0, 0, 0, 1));
            }
            var cubeProj = Matrix4x4.Perspective(90.0f, 1.0f, hdCamera.camera.nearClipPlane, hdCamera.camera.farClipPlane);

            proj = cubeProj;
            var gpuProj = GL.GetGPUProjectionMatrix(cubeProj, false);
            var vp      = gpuProj * gpuView;

            cb._ViewMatrix           = gpuView;
            cb._InvViewMatrix        = gpuView.inverse;
            cb._ProjMatrix           = gpuProj;
            cb._InvProjMatrix        = gpuProj.inverse;
            cb._ViewProjMatrix       = vp;
            cb._InvViewProjMatrix    = vp.inverse;
            cb._CameraViewProjMatrix = vp;
            cb._ScreenSize           = new Vector4(cubemapSize, cubemapSize, 1f / cubemapSize, 1f / cubemapSize);

            ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesGlobalCB, HDShaderIDs._ShaderVariablesGlobal);
        }
コード例 #13
0
ファイル: VolumetricLighting.cs プロジェクト: Si1ver/Graphics
 void UpdateShaderVariablesGlobalVolumetrics(ref ShaderVariablesGlobal cb, in RTHandleProperties sharedRTHandleProperties, HDCamera hdCamera)
コード例 #14
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];
                }
            }
        }
コード例 #15
0
        private void SetupGlobalParamsForCubemapInternal(CommandBuffer cmd, Matrix4x4 view, int cubemapSize, ref ShaderVariablesGlobal cb)
        {
            var gpuView = view;

            if (ShaderConfig.s_CameraRelativeRendering != 0)
            {
                gpuView.SetColumn(3, new Vector4(0, 0, 0, 1));
            }
            var gpuProj = GL.GetGPUProjectionMatrix(CubeProj, false);
            var vp      = gpuProj * gpuView;

            cb._ViewMatrix           = gpuView;
            cb._InvViewMatrix        = gpuView.inverse;
            cb._ProjMatrix           = gpuProj;
            cb._InvProjMatrix        = gpuProj.inverse;
            cb._ViewProjMatrix       = vp;
            cb._InvViewProjMatrix    = vp.inverse;
            cb._CameraViewProjMatrix = vp;
            cb._ScreenSize           = new Vector4(cubemapSize, cubemapSize, 1f / cubemapSize, 1f / cubemapSize);

            ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesGlobalCB, HDShaderIDs._ShaderVariablesGlobal);
        }