コード例 #1
0
        // Override the volume blending function.
        public override void Override(VolumeComponent state, float interpFactor)
        {
            VolumetricFog other = state as VolumetricFog;

            float   thisExtinction = VolumeRenderingUtils.ExtinctionFromMeanFreePath(meanFreePath);
            Vector3 thisScattering = VolumeRenderingUtils.ScatteringFromExtinctionAndAlbedo(thisExtinction, (Vector3)(Vector4)albedo.value);

            float   otherExtinction = VolumeRenderingUtils.ExtinctionFromMeanFreePath(other.meanFreePath);
            Vector3 otherScattering = VolumeRenderingUtils.ScatteringFromExtinctionAndAlbedo(otherExtinction, (Vector3)(Vector4)other.albedo.value);

            float   blendExtinction = Mathf.Lerp(otherExtinction, thisExtinction, interpFactor);
            Vector3 blendScattering = Vector3.Lerp(otherScattering, thisScattering, interpFactor);
            float   blendAsymmetry  = Mathf.Lerp(other.asymmetry, asymmetry, interpFactor);

            float blendMeanFreePath = VolumeRenderingUtils.MeanFreePathFromExtinction(blendExtinction);
            Color blendAlbedo       = (Color)(Vector4)VolumeRenderingUtils.AlbedoFromMeanFreePathAndScattering(blendMeanFreePath, blendScattering);

            blendAlbedo.a = 1.0f;

            if (meanFreePath.overrideState)
            {
                other.meanFreePath.value = blendMeanFreePath;
            }

            if (albedo.overrideState)
            {
                other.albedo.value = blendAlbedo;
            }

            if (asymmetry.overrideState)
            {
                other.asymmetry.value = blendAsymmetry;
            }
        }
コード例 #2
0
        public void PushFogShaderParameters(HDCamera hdCamera, CommandBuffer cmd)
        {
            if ((fogType.value != FogType.Volumetric) || (!hdCamera.frameSettings.IsEnabled(FrameSettingsField.Volumetrics)))
            {
                // If the volumetric fog is not used, we need to make sure that all rendering passes
                // (not just the atmospheric scattering one) receive neutral parameters.
                VolumetricFog.PushNeutralShaderParameters(cmd);
            }

            if (!hdCamera.frameSettings.IsEnabled(FrameSettingsField.AtmosphericScattering))
            {
                cmd.SetGlobalInt(HDShaderIDs._AtmosphericScatteringType, (int)FogType.None);
                return;
            }

            // The PBR sky contributes to atmospheric scattering.
            int pbrSkyAtmosphereFlag = skyType.value == (int)SkyType.PhysicallyBased ? 128 : 0;

            switch (fogType.value)
            {
            case FogType.None:
            {
                cmd.SetGlobalInt(HDShaderIDs._AtmosphericScatteringType, pbrSkyAtmosphereFlag | (int)FogType.None);
                break;
            }

            case FogType.Linear:
            {
                var fogSettings = VolumeManager.instance.stack.GetComponent <LinearFog>();
                fogSettings.PushShaderParameters(hdCamera, cmd);
                break;
            }

            case FogType.Exponential:
            {
                var fogSettings = VolumeManager.instance.stack.GetComponent <ExponentialFog>();
                fogSettings.PushShaderParameters(hdCamera, cmd);
                break;
            }

            case FogType.Volumetric:
            {
                if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.Volumetrics))
                {
                    var fogSettings = VolumeManager.instance.stack.GetComponent <VolumetricFog>();
                    fogSettings.PushShaderParameters(hdCamera, cmd);
                }
                break;
            }
            }
        }
コード例 #3
0
        public void PushFogShaderParameters(HDCamera hdCamera, CommandBuffer cmd)
        {
            if ((fogType.value != FogType.Volumetric) || (!hdCamera.frameSettings.enableVolumetrics))
            {
                // If the volumetric fog is not used, we need to make sure that all rendering passes
                // (not just the atmospheric scattering one) receive neutral parameters.
                VolumetricFog.PushNeutralShaderParameters(cmd);
            }

            if (!hdCamera.frameSettings.enableAtmosphericScattering)
            {
                cmd.SetGlobalInt(HDShaderIDs._AtmosphericScatteringType, (int)FogType.None);
                return;
            }

            switch (fogType.value)
            {
            case FogType.None:
            {
                cmd.SetGlobalInt(HDShaderIDs._AtmosphericScatteringType, (int)FogType.None);
                break;
            }

            case FogType.Linear:
            {
                var fogSettings = VolumeManager.instance.stack.GetComponent <LinearFog>();
                fogSettings.PushShaderParameters(hdCamera, cmd);
                break;
            }

            case FogType.Exponential:
            {
                var fogSettings = VolumeManager.instance.stack.GetComponent <ExponentialFog>();
                fogSettings.PushShaderParameters(hdCamera, cmd);
                break;
            }

            case FogType.Volumetric:
            {
                if (hdCamera.frameSettings.enableVolumetrics)
                {
                    var fogSettings = VolumeManager.instance.stack.GetComponent <VolumetricFog>();
                    fogSettings.PushShaderParameters(hdCamera, cmd);
                }
                break;
            }
            }
        }