/// <summary>
        /// Called when thumbnail rendering begins.
        /// </summary>
        /// <param name="task">The scene rendering task to customize.</param>
        /// <param name="context">The GPU rendering context.</param>
        /// <param name="req">The request data.</param>
        public void OnThumbnailRenderingBegin(SceneRenderTask task, GPUContext context, ref CameraCutThumbnailRenderer.Request req)
        {
            var view        = new RenderView();
            var track       = (CameraCutTrack)Track;
            var cam         = track.Camera;
            var viewport    = new FlaxEngine.Viewport(Vector2.Zero, task.Buffers.Size);
            var orientation = Quaternion.Identity;

            view.Near = 10.0f;
            view.Far  = 20000.0f;
            var usePerspective    = true;
            var orthoScale        = 1.0f;
            var fov               = 60.0f;
            var customAspectRatio = 0.0f;

            // Try to evaluate camera properties based on the initial camera state
            if (cam)
            {
                view.Position     = cam.Position;
                orientation       = cam.Orientation;
                view.Near         = cam.NearPlane;
                view.Far          = cam.FarPlane;
                usePerspective    = cam.UsePerspective;
                orthoScale        = cam.OrthographicScale;
                fov               = cam.FieldOfView;
                customAspectRatio = cam.CustomAspectRatio;
            }

            // Try to evaluate camera properties based on the animated tracks
            var time = req.ThumbnailIndex == 0 ? Start : Start + Duration;

            foreach (var subTrack in track.SubTracks)
            {
                if (subTrack is MemberTrack memberTrack)
                {
                    object value = memberTrack.Evaluate(time);
                    if (value != null)
                    {
                        // TODO: try to make it better
                        if (memberTrack.MemberName == "Position" && value is Vector3 asPosition)
                        {
                            view.Position = asPosition;
                        }
                        else if (memberTrack.MemberName == "Orientation" && value is Quaternion asRotation)
                        {
                            orientation = asRotation;
                        }
                        else if (memberTrack.MemberName == "NearPlane" && value is float asNearPlane)
                        {
                            view.Near = asNearPlane;
                        }
                        else if (memberTrack.MemberName == "FarPlane" && value is float asFarPlane)
                        {
                            view.Far = asFarPlane;
                        }
                        else if (memberTrack.MemberName == "UsePerspective" && value is bool asUsePerspective)
                        {
                            usePerspective = asUsePerspective;
                        }
                        else if (memberTrack.MemberName == "FieldOfView" && value is float asFieldOfView)
                        {
                            fov = asFieldOfView;
                        }
                        else if (memberTrack.MemberName == "CustomAspectRatio" && value is float asCustomAspectRatio)
                        {
                            customAspectRatio = asCustomAspectRatio;
                        }
                        else if (memberTrack.MemberName == "OrthographicScale" && value is float asOrthographicScale)
                        {
                            orthoScale = asOrthographicScale;
                        }
                    }
                }
            }

            // Build view
            view.Direction = Vector3.Forward * orientation;
            if (usePerspective)
            {
                float aspect = customAspectRatio <= 0.0f ? viewport.AspectRatio : customAspectRatio;
                view.Projection = Matrix.PerspectiveFov(fov * Mathf.DegreesToRadians, aspect, view.Near, view.Far);
            }
            else
            {
                view.Projection = Matrix.Ortho(viewport.Width * orthoScale, viewport.Height * orthoScale, view.Near, view.Far);
            }
            Vector3 target = view.Position + view.Direction;
            var     up     = Vector3.Transform(Vector3.Up, orientation);

            view.View = Matrix.LookAt(view.Position, target, up);
            view.NonJitteredProjection  = view.Projection;
            view.TemporalAAJitter       = Vector4.Zero;
            view.ModelLODDistanceFactor = 100.0f;
            view.Flags = ViewFlags.Reflections | ViewFlags.SSR | ViewFlags.AO | ViewFlags.GI |
                         ViewFlags.DirectionalLights | ViewFlags.PointLights | ViewFlags.SpotLights | ViewFlags.SkyLights |
                         ViewFlags.Shadows | ViewFlags.SpecularLight | ViewFlags.AntiAliasing | ViewFlags.CustomPostProcess |
                         ViewFlags.Bloom | ViewFlags.ToneMapping | ViewFlags.CameraArtifacts | ViewFlags.LensFlares | ViewFlags.Decals |
                         ViewFlags.DepthOfField | ViewFlags.Fog;
            view.UpdateCachedData();
            task.View = view;
        }
Esempio n. 2
0
        /// <summary>
        /// Called when thumbnail rendering begins.
        /// </summary>
        /// <param name="task">The scene rendering task to customize.</param>
        /// <param name="context">The GPU rendering context.</param>
        /// <param name="req">The request data.</param>
        public void OnThumbnailRenderingBegin(SceneRenderTask task, GPUContext context, ref CameraCutThumbnailRenderer.Request req)
        {
            RenderView view        = new RenderView();
            var        track       = (CameraCutTrack)Track;
            Camera     cam         = track.Camera;
            var        viewport    = new FlaxEngine.Viewport(Vector2.Zero, task.Buffers.Size);
            Quaternion orientation = Quaternion.Identity;

            view.Near = 10.0f;
            view.Far  = 20000.0f;
            bool  usePerspective    = true;
            float orthoScale        = 1.0f;
            float fov               = 60.0f;
            float customAspectRatio = 0.0f;

            view.RenderLayersMask = new LayersMask(uint.MaxValue);

            // Try to evaluate camera properties based on the initial camera state
            if (cam)
            {
                view.Position         = cam.Position;
                orientation           = cam.Orientation;
                view.Near             = cam.NearPlane;
                view.Far              = cam.FarPlane;
                usePerspective        = cam.UsePerspective;
                orthoScale            = cam.OrthographicScale;
                fov                   = cam.FieldOfView;
                customAspectRatio     = cam.CustomAspectRatio;
                view.RenderLayersMask = cam.RenderLayersMask;
            }

            // Try to evaluate camera properties based on the animated tracks
            float time = Start;

            if (req.ThumbnailIndex == 1)
            {
                time += Duration;
            }
            else if (req.ThumbnailIndex == 2)
            {
                time += Duration * 0.5f;
            }
            foreach (var subTrack in track.SubTracks)
            {
                if (subTrack is MemberTrack memberTrack)
                {
                    object value = memberTrack.Evaluate(time);
                    if (value != null)
                    {
                        // TODO: try to make it better
                        if (memberTrack.MemberName == "Position" && value is Vector3 asPosition)
                        {
                            view.Position = asPosition;
                        }

                        else if (memberTrack.MemberName == "Orientation" && value is Quaternion asRotation)
                        {
                            orientation = asRotation;
                        }

                        else if (memberTrack.MemberName == "NearPlane" && value is float asNearPlane)
                        {
                            view.Near = asNearPlane;
                        }

                        else if (memberTrack.MemberName == "FarPlane" && value is float asFarPlane)
                        {
                            view.Far = asFarPlane;
                        }

                        else if (memberTrack.MemberName == "UsePerspective" && value is bool asUsePerspective)
                        {
                            usePerspective = asUsePerspective;
                        }

                        else if (memberTrack.MemberName == "FieldOfView" && value is float asFieldOfView)
                        {
                            fov = asFieldOfView;
                        }

                        else if (memberTrack.MemberName == "CustomAspectRatio" && value is float asCustomAspectRatio)
                        {
                            customAspectRatio = asCustomAspectRatio;
                        }

                        else if (memberTrack.MemberName == "OrthographicScale" && value is float asOrthographicScale)
                        {
                            orthoScale = asOrthographicScale;
                        }
                    }
                }
            }

            // Build view
            view.Direction = Vector3.Forward * orientation;
            if (usePerspective)
            {
                float aspect = customAspectRatio <= 0.0f ? viewport.AspectRatio : customAspectRatio;
                view.Projection = Matrix.PerspectiveFov(fov * Mathf.DegreesToRadians, aspect, view.Near, view.Far);
            }
            else
            {
                view.Projection = Matrix.Ortho(viewport.Width * orthoScale, viewport.Height * orthoScale, view.Near, view.Far);
            }

            Vector3 target = view.Position + view.Direction;
            var     up     = Vector3.Transform(Vector3.Up, orientation);

            view.View = Matrix.LookAt(view.Position, target, up);
            view.NonJitteredProjection  = view.Projection;
            view.TemporalAAJitter       = Vector4.Zero;
            view.ModelLODDistanceFactor = 100.0f;
            view.Flags = ViewFlags.DefaultGame & ~(ViewFlags.MotionBlur);
            view.UpdateCachedData();
            task.View = view;
        }
Esempio n. 3
0
 internal static extern bool Internal_GetMatrices(IntPtr obj, out Matrix view, out Matrix projection, ref Viewport customViewport);
Esempio n. 4
0
 /// <summary>
 /// Calculates the view and the projection matrices for the camera. Support using custom viewport.
 /// </summary>
 /// <param name="view">The result camera view matrix.</param>
 /// <param name="projection">The result camera projection matrix.</param>
 /// <param name="customViewport">The custom output viewport.</param>
 public void GetMatrices(out Matrix view, out Matrix projection, ref Viewport customViewport)
 {
     Internal_GetMatrices(unmanagedPtr, out view, out projection, ref customViewport);
 }
Esempio n. 5
0
        /// <summary>
        /// Calculates the view and the projection matrices for the camera. Support using custom viewport.
        /// </summary>
        /// <param name="view">The result camera view matrix.</param>
        /// <param name="projection">The result camera projection matrix.</param>
        public void GetMatrices(out Matrix view, out Matrix projection)
        {
            Viewport emptyViewport = new Viewport(0, 0, 0, 0);

            Internal_GetMatrices(unmanagedPtr, out view, out projection, ref emptyViewport);
        }
Esempio n. 6
0
 internal static extern void Internal_SetViewport1(IntPtr obj, ref Viewport viewport);
Esempio n. 7
0
 /// <summary>
 /// Sets the rendering viewport.
 /// </summary>
 /// <param name="viewport">The viewport.</param>
 public void SetViewport(ref Viewport viewport)
 {
     Internal_SetViewport1(unmanagedPtr, ref viewport);
 }