void OnEnable()
        {
            // Be sure legacy HDR option is disable on camera as it cause banding in SceneView. Yes, it is a contradiction, but well, Unity...
            // When HDR option is enabled, Unity render in FP16 then convert to 8bit with a stretch copy (this cause banding as it should be convert to sRGB (or other color appropriate color space)), then do a final shader with sRGB conversion
            // When LDR, unity render in 8bitSRGB, then do a final shader with sRGB conversion
            // What should be done is just in our Post process we convert to sRGB and store in a linear 10bit, but require C++ change...
            m_camera          = GetComponent <Camera>();
            m_camera.allowHDR = false;

            m_FrameSettings.CopyTo(m_FrameSettingsRuntime);

            RegisterDebug();
        }
        // See comment in FrameSettings.UpdateDirtyFrameSettings()
        // for detail about this function
        public void UpdateDirtyFrameSettings()
        {
            if (m_frameSettingsIsDirty)
            {
                m_FrameSettings.CopyTo(m_FrameSettingsRuntime);

                m_frameSettingsIsDirty = false;

                // In Editor we can have plenty of camera that are not render at the same time as SceneView.
                // It is really tricky to keep in sync with them. To have a coherent state. When a change is done
                // on HDRenderPipelineAsset, we tag all camera as dirty so we are sure that they will get the
                // correct default FrameSettings when the camera will be in the HDRenderPipeline.Render() call
                // otherwise, as SceneView and Game camera are not in the same call Render(), Game camera that use default
                // will not be update correctly.
                #if UNITY_EDITOR
                Camera[] cameras = Camera.allCameras;
                foreach (Camera camera in cameras)
                {
                    var additionalCameraData = camera.GetComponent <HDAdditionalCameraData>();
                    if (additionalCameraData)
                    {
                        // Call OnAfterDeserialize that set dirty on FrameSettings
                        additionalCameraData.OnAfterDeserialize();
                    }
                }
                #endif
            }
        }
        // See comment in FrameSettings.UpdateDirtyFrameSettings()
        // for detail about this function
        public void UpdateDirtyFrameSettings()
        {
            if (m_frameSettingsIsDirty)
            {
                m_FrameSettings.CopyTo(m_FrameSettingsRuntime);

                m_frameSettingsIsDirty = false;
            }
        }
Example #4
0
        // This is use to copy data into camera for the Reset() workflow in camera editor
        public void CopyTo(HDAdditionalCameraData data)
        {
            data.clearColorMode          = clearColorMode;
            data.backgroundColorHDR      = backgroundColorHDR;
            data.clearDepth              = clearDepth;
            data.customRenderingSettings = customRenderingSettings;
            data.volumeLayerMask         = volumeLayerMask;
            data.volumeAnchorOverride    = volumeAnchorOverride;
            data.aperture     = aperture;
            data.shutterSpeed = shutterSpeed;
            data.iso          = iso;

            m_FrameSettings.CopyTo(data.m_FrameSettings);
            m_FrameSettingsRuntime.CopyTo(data.m_FrameSettingsRuntime);
            data.m_frameSettingsIsDirty = true; // Let's be sure it is dirty for update

            // We must not copy the following
            //data.m_IsDebugRegistered = m_IsDebugRegistered;
            //data.m_CameraRegisterName = m_CameraRegisterName;
            //data.isEditorCameraPreview = isEditorCameraPreview;
        }
Example #5
0
        // This function is call at the beginning of camera loop in HDRenderPipeline.Render()
        // It allow to correctly init the m_FrameSettingsRuntime to use.
        // If the camera use defaultFrameSettings it must be copied in m_FrameSettingsRuntime
        // otherwise it is the serialized m_FrameSettings that are used
        // This is required so each camera have its own debug settings even if they all use the RenderingPath.Default path
        // and important at Runtime as Default Camera from Scene Preview doesn't exist
        // assetFrameSettingsIsDirty is the current dirty frame settings state of HDRenderPipelineAsset
        // if it is dirty and camera use RenderingPath.Default, we need to update it
        // defaultFrameSettings are the settings store in the HDRenderPipelineAsset
        public void UpdateDirtyFrameSettings(bool assetFrameSettingsIsDirty, FrameSettings defaultFrameSettings)
        {
            if (m_frameSettingsIsDirty || assetFrameSettingsIsDirty)
            {
                // We do a copy of the settings to those effectively used
                defaultFrameSettings.CopyTo(m_FrameSettingsRuntime);

                if (!fullscreenPassthrough && customRenderingSettings)
                {
                    m_FrameSettings.ApplyOverrideOn(m_FrameSettingsRuntime);
                }

                m_frameSettingsIsDirty = false;
            }
        }
Example #6
0
        // This function is call at the beginning of camera loop in HDRenderPipeline.Render()
        // It allow to correctly init the m_FrameSettingsRuntime to use.
        // If the camera use defaultFrameSettings it must be copied in m_FrameSettingsRuntime
        // otherwise it is the serialized m_FrameSettings that are used
        // This is required so each camera have its own debug settings even if they all use the RenderingPath.Default path
        // and important at Runtime as Default Camera from Scene Preview doesn't exist
        // assetFrameSettingsIsDirty is the current dirty frame settings state of HDRenderPipelineAsset
        // if it is dirty and camera use RenderingPath.Default, we need to update it
        // defaultFrameSettings are the settings store in the HDRenderPipelineAsset
        public void UpdateDirtyFrameSettings(bool assetFrameSettingsIsDirty, FrameSettings defaultFrameSettings)
        {
            if (m_frameSettingsIsDirty || assetFrameSettingsIsDirty)
            {
                // We do a copy of the settings to those effectively used
                defaultFrameSettings.CopyTo(m_FrameSettingsRuntime);

                if (renderingPath == RenderingPath.Custom)
                {
                    m_FrameSettings.ApplyOverrideOn(m_FrameSettingsRuntime);
                }

                m_frameSettingsIsDirty = false;
            }
        }
        // This function is call at the beginning of camera loop in HDRenderPipeline.Render()
        // It allow to correctly init the m_FrameSettingsRuntime to use.
        // If the camera use defaultFrameSettings it must be copied in m_FrameSettingsRuntime
        // otherwise it is the serialized m_FrameSettings that are used
        // This is required so each camera have its own debug settings even if they all use the RenderingPath.Default path
        // and important at Runtime as Default Camera from Scene Preview doesn't exist
        // assetFrameSettingsIsDirty is the current dirty frame settings state of HDRenderPipelineAsset
        // if it is dirty and camera use RenderingPath.Default, we need to update it
        // defaultFrameSettings are the settings store in the HDRenderPipelineAsset
        public void UpdateDirtyFrameSettings(bool assetFrameSettingsIsDirty, FrameSettings defaultFrameSettings)
        {
            if (m_frameSettingsIsDirty || assetFrameSettingsIsDirty)
            {
                // We do a copy of the settings to those effectively used
                if (renderingPath == RenderingPath.Default)
                {
                    defaultFrameSettings.CopyTo(m_FrameSettingsRuntime);
                }
                else
                {
                    m_FrameSettings.CopyTo(m_FrameSettingsRuntime);
                }

                m_frameSettingsIsDirty = false;
            }
        }
Example #8
0
 public FrameSettings(FrameSettings toCopy)
 {
     toCopy.CopyTo(this);
 }
Example #9
0
        /// <summary>
        /// Apply <paramref name="settings"/> and <paramref name="probePosition"/> to
        /// <paramref name="cameraPosition"/> and <paramref name="cameraSettings"/>.
        /// </summary>
        /// <param name="settings">Settings to apply. (Read only)</param>
        /// <param name="probePosition">Position to apply. (Read only)</param>
        /// <param name="cameraSettings">Settings to update.</param>
        /// <param name="cameraPosition">Position to update.</param>
        public static void ApplySettings(
            ref ProbeSettings settings,                             // In Parameter
            ref ProbeCapturePositionSettings probePosition,         // In parameter
            ref CameraSettings cameraSettings,                      // InOut parameter
            ref CameraPositionSettings cameraPosition               // InOut parameter
            )
        {
            cameraSettings = settings.camera;
            // Compute the modes for each probe type
            PositionMode positionMode;
            bool         useReferenceTransformAsNearClipPlane;

            switch (settings.type)
            {
            case ProbeSettings.ProbeType.PlanarProbe:
                positionMode = PositionMode.MirrorReferenceTransfromWithProbePlane;
                useReferenceTransformAsNearClipPlane = true;
                break;

            case ProbeSettings.ProbeType.ReflectionProbe:
                positionMode = PositionMode.UseProbeTransform;
                useReferenceTransformAsNearClipPlane = false;
                cameraSettings.frustum.mode          = CameraSettings.Frustum.Mode.ComputeProjectionMatrix;
                cameraSettings.frustum.aspect        = 1;
                cameraSettings.frustum.fieldOfView   = 90;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            // Update the position
            switch (positionMode)
            {
            case PositionMode.UseProbeTransform:
            {
                cameraPosition.mode = CameraPositionSettings.Mode.ComputeWorldToCameraMatrix;
                var proxyMatrix = Matrix4x4.TRS(probePosition.proxyPosition, probePosition.proxyRotation, Vector3.one);
                cameraPosition.position = proxyMatrix.MultiplyPoint(settings.proxySettings.capturePositionProxySpace);
                cameraPosition.rotation = proxyMatrix.rotation * settings.proxySettings.captureRotationProxySpace;
                break;
            }

            case PositionMode.MirrorReferenceTransfromWithProbePlane:
            {
                cameraPosition.mode = CameraPositionSettings.Mode.UseWorldToCameraMatrixField;
                ApplyMirroredReferenceTransform(
                    ref settings, ref probePosition,
                    ref cameraSettings, ref cameraPosition
                    );
                break;
            }
            }

            // Update the clip plane
            if (useReferenceTransformAsNearClipPlane)
            {
                ApplyObliqueNearClipPlane(
                    ref settings, ref probePosition,
                    ref cameraSettings, ref cameraPosition
                    );
            }

            // Frame Settings Overrides
            var hd = (HDRenderPipeline)RenderPipelineManager.currentPipeline;

            switch (settings.mode)
            {
            default:
            case ProbeSettings.Mode.Realtime:
                hd.asset.GetRealtimeReflectionFrameSettings().CopyTo(s_ApplySettings_TMP);
                break;

            case ProbeSettings.Mode.Baked:
            case ProbeSettings.Mode.Custom:
                hd.asset.GetBakedOrCustomReflectionFrameSettings().CopyTo(s_ApplySettings_TMP);
                break;
            }
            cameraSettings.frameSettings.ApplyOverrideOn(s_ApplySettings_TMP);
            s_ApplySettings_TMP.CopyTo(cameraSettings.frameSettings);
        }
Example #10
0
 void ISerializationCallbackReceiver.OnAfterDeserialize()
 {
     // Modification of defaultFrameSettings in the inspector will call OnValidate().
     // We do a copy of the settings to those effectively used
     m_FrameSettings.CopyTo(m_FrameSettingsRuntime);
 }