Example #1
0
    void Start()
    {
        instance = this;
        GameObject playerGo = Instantiate(Resources.Load <GameObject>("Player"));

        playerCombat      = playerGo.GetComponent <PlayerCombat>();
        playerControl     = playerGo.GetComponent <PlayerControl>();
        uiManager         = GetComponent <UIManager>();
        postEffectManager = playerGo.transform.Find("Camera").GetComponent <PostEffects>();

        bool saveExists = Save.Init();

        if (saveExists)
        {
            ChangeLevel(Save.current.mapName, false);
        }
        else
        {
            ChangeLevel(firstLevel, true);
        }

        playerControl.Init();
        playerCombat.Init();
        uiManager.Init();
        postEffectManager.Init();
        gameMixer.SetFloat("Volume", Save.current.settings.soundLevel);
        if (Save.current.combatData.currentHealth <= 0)
        {
            isPaused = true;
        }
    }
Example #2
0
        /// <inheritdoc />
        protected override void OnChildRemoved(Instance child)
        {
            base.OnChildRemoved(child);
            PostEffect  effect;
            ICameraUser cameraUser;

            if ((effect = child as PostEffect) != null)
            {
                lock (PostEffectsLocker)
                {
                    PostEffects.Remove(effect);
                    effect.SetCamera(null);

                    // replace user effect with default effect
                    if (effect is BloomEffect)
                    {
                        PostEffects.Add(_bloomEffect);
                    }
                    else if (effect is ColourCorrectionEffect)
                    {
                        PostEffects.Add(_colourCorrection);
                    }
                }
            }
            else if ((cameraUser = child as ICameraUser) != null)
            {
                cameraUser.Camera = null;
            }
        }
Example #3
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            // TODO: Add your update logic here
            var keystate = Keyboard.GetState();

            if (keystate.IsKeyDown(Keys.A))
            {
                z += 0.1f;
            }
            if (keystate.IsKeyDown(Keys.Z))
            {
                z -= 0.1f;
            }
            if (keystate.IsKeyDown(Keys.D1))
            {
                CurrentPostEffect = PostEffects.None;
            }
            if (keystate.IsKeyDown(Keys.D2))
            {
                CurrentPostEffect = PostEffects.BlackAndWhite;
            }
        }
Example #4
0
 //------------------------------------------------------------------------------------------
 // アラートエフェクトを開始する
 //------------------------------------------------------------------------------------------
 public void StartAlert()
 {
     timer         = 0;
     fadeIn        = false;
     fadeOut       = false;
     alert         = true;
     currentEffect = PostEffects.Alert;
 }
Example #5
0
    void Start()
    {
        cam    = GetComponent <Camera>();
        ssaa   = GetComponent <SSAA>();
        postfx = GetComponent <PostEffects>();

        targssaa   = targetCamera.GetComponent <SSAA>();
        targpostfx = targetCamera.GetComponent <PostEffects>();
    }
Example #6
0
        internal static void Terminate()
        {
            for (int loop = 0; loop < 3; loop++)
            {
                SoundSources.DestroyAll();

                Cursors.DestroyAll();

                Texture2Ds.DestroyAll();
                CubemapTextures.DestroyAll();
                Fonts.DestroyAll();
                Chip2Ds.DestroyAll();

                Shader2Ds.DestroyAll();
                Shader3Ds.DestroyAll();
                Material2Ds.DestroyAll();
                Material3Ds.DestroyAll();
                MaterialPropertyBlocks.DestroyAll();

                ImagePackages.DestroyAll();

                Effects.DestroyAll();

                Meshs.DestroyAll();
                Deformers.DestroyAll();
                Models.DestroyAll();
                MassModels.DestroyAll();
                Terrain3Ds.DestroyAll();

                KeyframeAnimations.DestroyAll();
                AnimationSources.DestroyAll();

                Scenes.DestroyAll();

                Layer2Ds.DestroyAll();
                Object2Ds.DestroyAll();

                Layer3Ds.DestroyAll();
                Object3Ds.DestroyAll();

                PostEffects.DestroyAll();
                Transitions.DestroyAll();

                StaticFiles.DestroyAll();
                StreamFiles.DestroyAll();

                Shapes.DestroyAll();

                //Profilers.DestroyAll();

                Collector.Collect();
                System.GC.Collect();
                System.GC.WaitForPendingFinalizers();
                System.GC.Collect();
                Collector.Collect();
            }
        }
Example #7
0
 //------------------------------------------------------------------------------------------
 // ワイプエフェクトでフェードアウトする
 //------------------------------------------------------------------------------------------
 public void StartFadeOut(Vector3 pos, float time)
 {
     targetPos     = pos;
     fadeTime      = time;
     timer         = 0;
     fadeIn        = false;
     fadeOut       = true;
     alert         = false;
     currentEffect = PostEffects.Wipe;
 }
Example #8
0
 private void CreateMaterials()
 {
     if (!dofBlurMaterial)
     {
         dofBlurMaterial = PostEffects.CheckShaderAndCreateMaterial(dofBlurShader, dofBlurMaterial);
     }
     if (!dofMaterial)
     {
     }
     dofMaterial = this.PostEffects.CheckShaderAndCreateMaterial(dofShader, dofMaterial);
 }
Example #9
0
        internal static void Update()
        {
            if (Collector.Collect())
            {
                SoundSources.Collect();

                Cursors.Collect();

                Texture2Ds.Collect();
                CubemapTextures.Collect();
                Fonts.Collect();
                Chip2Ds.Collect();

                Shader2Ds.Collect();
                Shader3Ds.Collect();
                Material2Ds.Collect();
                Material3Ds.Collect();
                MaterialPropertyBlocks.Collect();

                ImagePackages.Collect();
                MediaPlayers.Collect();

                Effects.Collect();

                Meshs.Collect();
                Deformers.Collect();
                Models.Collect();
                MassModels.Collect();
                Terrain3Ds.Collect();

                KeyframeAnimations.Collect();
                AnimationSources.Collect();
                AnimationClips.Collect();

                Scenes.Collect();

                Layer2Ds.Collect();
                Object2Ds.Collect();

                Layer3Ds.Collect();
                Object3Ds.Collect();

                PostEffects.Collect();

                Transitions.Collect();

                StaticFiles.Collect();
                StreamFiles.Collect();

                Shapes.Collect();
                Collider2Ds.Collect();
            }
        }
Example #10
0
        internal override void AfterDeserialization(Inst.Context context)
        {
            base.AfterDeserialization(context);

            lock (PostEffectsLocker)
            {
                foreach (var child in Children)
                {
                    var effect = child as PostEffect;
                    if (effect != null)
                    {
                        PostEffects.Add(effect);
                        effect.SetCamera(this);
                    }
                }
            }
        }
Example #11
0
        protected override unsafe void CollectCore(RenderContext context)
        {
            var camera = context.GetCurrentCamera();

            if (context.RenderView is null)
            {
                throw new NullReferenceException(nameof(context.RenderView) + " is null. Please make sure you have your camera correctly set.");
            }

            // Setup pixel formats for RenderStage
            using (context.SaveRenderOutputAndRestore())
            {
                // Mark this view as requiring shadows
                shadowMapRenderer?.RenderViewsWithShadows.Add(context.RenderView);

                context.RenderOutput = new RenderOutputDescription(PostEffects != null ? PixelFormat.R16G16B16A16_Float : context.RenderOutput.RenderTargetFormat0, DepthBufferFormat, MSAALevel);

                CollectStages(context);

                // Write params to view
                SceneCameraRenderer.UpdateCameraToRenderView(context, context.RenderView, camera);

                CollectView(context);

                LightShafts?.Collect(context);

                PostEffects?.Collect(context);

                // Set depth format for shadow map render stages
                foreach (var shadowMapRenderStage in ShadowMapRenderStages)
                {
                    // TODO: This format should be acquired from the ShadowMapRenderer instead of being fixed here
                    if (shadowMapRenderStage != null)
                    {
                        shadowMapRenderStage.Output = new RenderOutputDescription(PixelFormat.None, PixelFormat.D32_Float);
                    }
                }
            }

            PostEffects?.Collect(context);
        }
Example #12
0
        public bool Equals(SaveFileSA other)
        {
            if (other == null)
            {
                return(false);
            }

            return(SimpleVars.Equals(other.SimpleVars) &&
                   Scripts.Equals(other.Scripts) &&
                   Pools.Equals(other.Pools) &&
                   Garages.Equals(other.Garages) &&
                   GameLogic.Equals(other.GameLogic) &&
                   Paths.Equals(other.Paths) &&
                   Pickups.Equals(other.Pickups) &&
                   PhoneInfo.Equals(other.PhoneInfo) &&
                   RestartPoints.Equals(other.RestartPoints) &&
                   RadarBlips.Equals(other.RadarBlips) &&
                   Zones.Equals(other.Zones) &&
                   GangData.Equals(other.GangData) &&
                   CarGenerators.Equals(other.CarGenerators) &&
                   PedGenerators.Equals(other.PedGenerators) &&
                   AudioScriptObjects.Equals(other.AudioScriptObjects) &&
                   PlayerInfo.Equals(other.PlayerInfo) &&
                   Stats.Equals(other.Stats) &&
                   SetPieces.Equals(other.SetPieces) &&
                   Streaming.Equals(other.Streaming) &&
                   PedTypeInfo.Equals(other.PedTypeInfo) &&
                   Tags.Equals(other.Tags) &&
                   IplStore.Equals(other.IplStore) &&
                   Shopping.Equals(other.Shopping) &&
                   GangWars.Equals(other.GangWars) &&
                   StuntJumps.Equals(other.StuntJumps) &&
                   EntryExits.Equals(other.EntryExits) &&
                   Radio.Equals(other.Radio) &&
                   User3dMarkers.Equals(other.User3dMarkers) &&
                   PostEffects.Equals(other.PostEffects));
        }
Example #13
0
 protected override void Destroy()
 {
     PostEffects?.Dispose();
 }
Example #14
0
        protected virtual void DrawView(RenderContext context, RenderDrawContext drawContext)
        {
            var renderSystem = context.RenderSystem;

            // Z Prepass
            var lightProbes = LightProbes && GBufferRenderStage != null;

            if (lightProbes)
            {
                // Note: Baking lightprobe before GBuffer prepass because we are updating some cbuffer parameters needed by Opaque pass that GBuffer pass might upload early
                PrepareLightprobeConstantBuffer(context);

                // TODO: Temporarily using ShadowMap shader
                using (drawContext.QueryManager.BeginProfile(Color.Green, CompositingProfilingKeys.GBuffer))
                    using (drawContext.PushRenderTargetsAndRestore())
                    {
                        drawContext.CommandList.Clear(drawContext.CommandList.DepthStencilBuffer, DepthStencilClearOptions.DepthBuffer);
                        drawContext.CommandList.SetRenderTarget(drawContext.CommandList.DepthStencilBuffer, null);

                        // Draw [main view | z-prepass stage]
                        renderSystem.Draw(drawContext, context.RenderView, GBufferRenderStage);
                    }

                // Bake lightprobes against Z-buffer
                BakeLightProbes(context, drawContext);
            }

            using (drawContext.PushRenderTargetsAndRestore())
            {
                // Draw [main view | main stage]
                if (OpaqueRenderStage != null)
                {
                    using (drawContext.QueryManager.BeginProfile(Color.Green, CompositingProfilingKeys.Opaque))
                    {
                        renderSystem.Draw(drawContext, context.RenderView, OpaqueRenderStage);
                    }
                }

                // Draw [main view | transparent stage]
                Texture depthStencilSRV = null;
                if (TransparentRenderStage != null)
                {
                    // Some transparent shaders will require the depth as a shader resource - resolve it only once and set it here
                    using (drawContext.QueryManager.BeginProfile(Color.Green, CompositingProfilingKeys.Transparent))
                        using (drawContext.PushRenderTargetsAndRestore())
                        {
                            depthStencilSRV = ResolveDepthAsSRV(drawContext);

                            renderSystem.Draw(drawContext, context.RenderView, TransparentRenderStage);
                        }
                }

                var colorTargetIndex = OpaqueRenderStage?.OutputValidator.Find(typeof(ColorTargetSemantic)) ?? -1;
                if (colorTargetIndex == -1)
                {
                    return;
                }

                // Resolve MSAA targets
                var renderTargets = currentRenderTargets;
                var depthStencil  = currentDepthStencil;
                if (actualMultisampleCount != MultisampleCount.None)
                {
                    using (drawContext.QueryManager.BeginProfile(Color.Green, CompositingProfilingKeys.MsaaResolve))
                    {
                        ResolveMSAA(drawContext);
                    }

                    renderTargets = currentRenderTargetsNonMSAA;
                    depthStencil  = currentDepthStencilNonMSAA;
                }

                // Shafts if we have them
                if (LightShafts != null)
                {
                    using (drawContext.QueryManager.BeginProfile(Color.Green, CompositingProfilingKeys.LightShafts))
                    {
                        LightShafts.Draw(drawContext, depthStencil, renderTargets[colorTargetIndex]);
                    }
                }

                if (PostEffects != null)
                {
                    // Run post effects
                    // Note: OpaqueRenderStage can't be null otherwise colorTargetIndex would be -1
                    PostEffects.Draw(drawContext, OpaqueRenderStage.OutputValidator, renderTargets.Items, depthStencil, ViewOutputTarget);
                }
                else
                {
                    if (actualMultisampleCount != MultisampleCount.None)
                    {
                        using (drawContext.QueryManager.BeginProfile(Color.Green, CompositingProfilingKeys.MsaaResolve))
                        {
                            drawContext.CommandList.Copy(renderTargets[colorTargetIndex], ViewOutputTarget);
                        }
                    }
                }

                // Free the depth texture since we won't need it anymore
                if (depthStencilSRV != null)
                {
                    drawContext.Resolver.ReleaseDepthStenctilAsShaderResource(depthStencilSRV);
                }
            }
        }
Example #15
0
        protected override unsafe void CollectCore(RenderContext context)
        {
            var camera = context.GetCurrentCamera();

            if (context.RenderView == null)
            {
                throw new NullReferenceException(nameof(context.RenderView) + " is null. Please make sure you have your camera correctly set.");
            }

            // Setup pixel formats for RenderStage
            using (context.SaveRenderOutputAndRestore())
            {
                // Mark this view as requiring shadows
                shadowMapRenderer?.RenderViewsWithShadows.Add(context.RenderView);

                context.RenderOutput = new RenderOutputDescription(PostEffects != null ? PixelFormat.R16G16B16A16_Float : context.RenderOutput.RenderTargetFormat0, DepthBufferFormat, MSAALevel);

                CollectStages(context);

                if (VRSettings.Enabled && VRSettings.VRDevice != null)
                {
                    Vector3 cameraPos, cameraScale;
                    Matrix  cameraRot;

                    if (!vrSystem.PreviousUseCustomViewMatrix)
                    {
                        camera.Entity.Transform.WorldMatrix.Decompose(out cameraScale, out cameraRot, out cameraPos);
                    }
                    else
                    {
                        camera.ViewMatrix.Decompose(out cameraScale, out cameraRot, out cameraPos);
                        cameraRot.Transpose();
                        Vector3.Negate(ref cameraPos, out cameraPos);
                        Vector3.TransformCoordinate(ref cameraPos, ref cameraRot, out cameraPos);
                    }

                    if (VRSettings.IgnoreCameraRotation)
                    {
                        cameraRot = Matrix.Identity;
                    }

                    // Compute both view and projection matrices
                    Matrix *viewMatrices       = stackalloc Matrix[2];
                    Matrix *projectionMatrices = stackalloc Matrix[2];
                    for (var i = 0; i < 2; ++i)
                    {
                        VRSettings.VRDevice.ReadEyeParameters(i == 0 ? Eyes.Left : Eyes.Right, camera.NearClipPlane, camera.FarClipPlane, ref cameraPos, ref cameraRot, out viewMatrices[i], out projectionMatrices[i]);
                    }

                    // if the VRDevice disagreed with the near and far plane, we must re-discover them and follow:
                    var near = projectionMatrices[0].M43 / projectionMatrices[0].M33;
                    var far  = near * (-projectionMatrices[0].M33 / (-projectionMatrices[0].M33 - 1));
                    if (Math.Abs(near - camera.NearClipPlane) > 1e-8f)
                    {
                        camera.NearClipPlane = near;
                    }
                    if (Math.Abs(near - camera.FarClipPlane) > 1e-8f)
                    {
                        camera.FarClipPlane = far;
                    }

                    // Compute a view matrix and projection matrix that cover both eyes for shadow map and culling
                    ComputeCommonViewMatrices(context, viewMatrices, projectionMatrices);
                    var commonView = context.RenderView;

                    // Notify lighting system this view only purpose is for shared lighting, it is not being drawn directly.
                    commonView.Flags |= RenderViewFlags.NotDrawn;

                    // Collect now, and use result for both eyes
                    CollectView(context);
                    context.VisibilityGroup.TryCollect(commonView);

                    for (var i = 0; i < 2; i++)
                    {
                        using (context.PushRenderViewAndRestore(VRSettings.RenderViews[i]))
                            using (context.SaveViewportAndRestore())
                            {
                                context.RenderSystem.Views.Add(context.RenderView);
                                context.RenderView.SceneInstance = commonView.SceneInstance;
                                context.RenderView.LightingView  = commonView;
                                context.ViewportState.Viewport0  = new Viewport(0, 0, VRSettings.VRDevice.ActualRenderFrameSize.Width / 2.0f, VRSettings.VRDevice.ActualRenderFrameSize.Height);

                                //change camera params for eye
                                camera.ViewMatrix                = viewMatrices[i];
                                camera.ProjectionMatrix          = projectionMatrices[i];
                                camera.UseCustomProjectionMatrix = true;
                                camera.UseCustomViewMatrix       = true;
                                camera.Update();

                                //write params to view
                                SceneCameraRenderer.UpdateCameraToRenderView(context, context.RenderView, camera);

                                // Copy culling results
                                context.VisibilityGroup.Copy(commonView, context.RenderView);

                                CollectView(context);

                                LightShafts?.Collect(context);

                                PostEffects?.Collect(context);
                            }
                    }

                    if (VRSettings.VRDevice.SupportsOverlays)
                    {
                        foreach (var overlay in VRSettings.Overlays)
                        {
                            if (overlay != null && overlay.Texture != null)
                            {
                                overlay.Overlay.Position           = overlay.LocalPosition;
                                overlay.Overlay.Rotation           = overlay.LocalRotation;
                                overlay.Overlay.SurfaceSize        = overlay.SurfaceSize;
                                overlay.Overlay.FollowHeadRotation = overlay.FollowsHeadRotation;
                            }
                        }
                    }
                }
                else
                {
                    //write params to view
                    SceneCameraRenderer.UpdateCameraToRenderView(context, context.RenderView, camera);

                    CollectView(context);

                    LightShafts?.Collect(context);

                    PostEffects?.Collect(context);
                }

                // Set depth format for shadow map render stages
                // TODO: This format should be acquired from the ShadowMapRenderer instead of being fixed here
                foreach (var shadowMapRenderStage in ShadowMapRenderStages)
                {
                    shadowMapRenderStage.Output = new RenderOutputDescription(PixelFormat.None, PixelFormat.D32_Float);
                }
            }

            PostEffects?.Collect(context);
        }
Example #16
0
        protected override unsafe void CollectCore(RenderContext context)
        {
            var camera = context.GetCurrentCamera();

            if (context.RenderView == null)
            {
                throw new NullReferenceException(nameof(context.RenderView) + " is null. Please make sure you have your camera correctly set.");
            }

            // Setup pixel formats for RenderStage
            using (context.SaveRenderOutputAndRestore())
            {
                // Mark this view as requiring shadows
                shadowMapRenderer?.RenderViewsWithShadows.Add(context.RenderView);

                context.RenderOutput = new RenderOutputDescription(context.RenderOutput.RenderTargetFormat0, DepthBufferFormat, MSAALevel);

                CollectStages(context);

                if (VRSettings.Enabled && VRSettings.VRDevice != null)
                {
                    Matrix *viewMatrices       = stackalloc Matrix[2];
                    Matrix *projectionMatrices = stackalloc Matrix[2];

                    // only update the camera once, if we have multiple forward renderers on the same camera
                    ulong poseCount = VRSettings.VRDevice.PoseCount;
                    if (poseCount == 0 || poseCount != camera.VRProjectionPose)
                    {
                        camera.VRProjectionPose = poseCount;

                        Vector3 cameraPos, cameraScale;
                        Matrix  cameraRot;

                        VRSettings.VRDevice.UpdatePositions(context.Time);

                        if (camera.VRHeadSetsTransform)
                        {
                            if (camera.Entity.Transform.Parent != null)
                            {
                                camera.Entity.Transform.Parent.WorldMatrix.Decompose(out cameraScale, out cameraRot, out cameraPos);
                            }
                            else
                            {
                                cameraPos   = Vector3.Zero;
                                cameraScale = Vector3.One;
                                cameraRot   = Matrix.Identity;
                            }

                            // make sure camera position gets body scale
                            camera.Entity.Transform.Position = VRSettings.VRDevice.HeadPosition * VRSettings.VRDevice.BodyScaling;
                            camera.Entity.Transform.Rotation = VRSettings.VRDevice.HeadRotation;
                        }
                        else
                        {
                            if (!vrSystem.PreviousUseCustomViewMatrix)
                            {
                                camera.Entity.Transform.WorldMatrix.Decompose(out cameraScale, out cameraRot, out cameraPos);
                            }
                            else
                            {
                                camera.ViewMatrix.Decompose(out cameraScale, out cameraRot, out cameraPos);
                                cameraRot.Transpose();
                                Vector3.Negate(ref cameraPos, out cameraPos);
                                Vector3.TransformCoordinate(ref cameraPos, ref cameraRot, out cameraPos);
                            }

                            if (VRSettings.IgnoreCameraRotation)
                            {
                                // only remove the local rotation of the camera
                                cameraRot *= Matrix.RotationQuaternion(Quaternion.Invert(camera.Entity.Transform.Rotation));
                            }
                        }

                        // Compute both view and projection matrices
                        for (var i = 0; i < 2; ++i)
                        {
                            VRSettings.VRDevice.ReadEyeParameters(i == 0 ? Eyes.Left : Eyes.Right, camera.NearClipPlane, camera.FarClipPlane, ref cameraPos, ref cameraRot, VRSettings.IgnoreDeviceRotation, VRSettings.IgnoreDevicePosition, out viewMatrices[i], out projectionMatrices[i]);
                        }

                        // cache these projection values
                        if (camera.cachedVRProjections == null)
                        {
                            camera.cachedVRProjections = new Matrix[4];
                        }
                        camera.cachedVRProjections[0] = viewMatrices[0];
                        camera.cachedVRProjections[1] = viewMatrices[1];
                        camera.cachedVRProjections[2] = projectionMatrices[0];
                        camera.cachedVRProjections[3] = projectionMatrices[1];

                        // if the VRDevice disagreed with the near and far plane, we must re-discover them and follow:
                        var near = projectionMatrices[0].M43 / projectionMatrices[0].M33;
                        var far  = near * (-projectionMatrices[0].M33 / (-projectionMatrices[0].M33 - 1));
                        if (Math.Abs(near - camera.NearClipPlane) > 1e-8f)
                        {
                            camera.NearClipPlane = near;
                        }
                        if (Math.Abs(near - camera.FarClipPlane) > 1e-8f)
                        {
                            camera.FarClipPlane = far;
                        }
                    }
                    else
                    {
                        // already calculated this camera, use the cached information
                        viewMatrices[0]       = camera.cachedVRProjections[0];
                        viewMatrices[1]       = camera.cachedVRProjections[1];
                        projectionMatrices[0] = camera.cachedVRProjections[2];
                        projectionMatrices[1] = camera.cachedVRProjections[3];
                    }

                    // Compute a view matrix and projection matrix that cover both eyes for shadow map and culling
                    ComputeCommonViewMatrices(context, viewMatrices, projectionMatrices);
                    var commonView = context.RenderView;

                    // Notify lighting system this view only purpose is for shared lighting, it is not being drawn directly.
                    commonView.Flags |= RenderViewFlags.NotDrawn;

                    // Collect now, and use result for both eyes
                    CollectView(context);
                    context.VisibilityGroup.TryCollect(commonView);

                    for (var i = 0; i < 2; i++)
                    {
                        using (context.PushRenderViewAndRestore(VRSettings.RenderViews[i]))
                            using (context.SaveViewportAndRestore())
                            {
                                context.RenderSystem.Views.Add(context.RenderView);
                                context.RenderView.LightingView = commonView;
                                context.ViewportState.Viewport0 = new Viewport(0, 0, VRSettings.VRDevice.ActualRenderFrameSize.Width / 2.0f, VRSettings.VRDevice.ActualRenderFrameSize.Height);

                                //change camera params for eye
                                camera.ViewMatrix                = viewMatrices[i];
                                camera.ProjectionMatrix          = projectionMatrices[i];
                                camera.UseCustomProjectionMatrix = true;
                                camera.UseCustomViewMatrix       = true;
                                camera.Update();

                                //write params to view
                                SceneCameraRenderer.UpdateCameraToRenderView(context, context.RenderView, camera);

                                // Copy culling results
                                context.VisibilityGroup.Copy(commonView, context.RenderView);

                                CollectView(context);

                                LightShafts?.Collect(context);

                                PostEffects?.Collect(context);
                            }
                    }
                }
                else
                {
                    //write params to view
                    SceneCameraRenderer.UpdateCameraToRenderView(context, context.RenderView, camera);

                    CollectView(context);

                    LightShafts?.Collect(context);

                    PostEffects?.Collect(context);
                }

                // Set depth format for shadow map render stages
                // TODO: This format should be acquired from the ShadowMapRenderer instead of being fixed here
                foreach (var shadowMapRenderStage in ShadowMapRenderStages)
                {
                    if (shadowMapRenderStage != null)
                    {
                        shadowMapRenderStage.Output = new RenderOutputDescription(PixelFormat.None, PixelFormat.D32_Float);
                    }
                }
            }

            PostEffects?.Collect(context);
        }
 bool Supported()
 {
     return(PostEffects.CheckSupport(true) && dofBlurShader.isSupported && dofShader.isSupported);
 }
Example #18
0
        protected override void DrawCore(RenderContext context, RenderDrawContext drawContext)
        {
            var viewport = drawContext.CommandList.Viewport;

            using (drawContext.PushRenderTargetsAndRestore())
            {
                // Render Shadow maps
                shadowMapRenderer?.Draw(drawContext);

                if (VRSettings.Enabled && VRSettings.VRDevice != null)
                {
                    var isFullViewport = (int)viewport.X == 0 && (int)viewport.Y == 0 &&
                                         (int)viewport.Width == drawContext.CommandList.RenderTarget.ViewWidth &&
                                         (int)viewport.Height == drawContext.CommandList.RenderTarget.ViewHeight;
                    if (!isFullViewport)
                    {
                        return;
                    }

                    bool hasPostEffects = PostEffects != null, presentingVR = this == VRRenderers[VRRenderers.Count - 1];

                    Texture vrFullSurface;
                    using (drawContext.PushRenderTargetsAndRestore())
                    {
                        var currentRenderTarget     = drawContext.CommandList.RenderTarget;
                        var desiredRenderTargetSize = VRSettings.VRDevice.ActualRenderFrameSize;

                        if (desiredRenderTargetSize.Width != currentRenderTarget.Width || desiredRenderTargetSize.Height != currentRenderTarget.Height)
                        {
                            drawContext.CommandList.SetRenderTargets(null, null); // force to create and bind a new render target
                        }
                        PrepareRenderTargets(drawContext, desiredRenderTargetSize);

                        vrFullSurface = viewOutputTarget;

                        //draw per eye
                        using (context.SaveViewportAndRestore())
                            using (drawContext.PushRenderTargetsAndRestore())
                            {
                                ViewCount = 2;

                                for (var i = 0; i < 2; i++)
                                {
                                    drawContext.CommandList.SetRenderTargets(currentDepthStencil, currentRenderTargets.Count, currentRenderTargets.Items);

                                    var frameSize = VRSettings.VRDevice.ActualRenderFrameSize;
                                    drawContext.CommandList.SetViewport(new Viewport(i * frameSize.Width / 2, 0, frameSize.Width / 2, frameSize.Height));

                                    using (context.PushRenderViewAndRestore(VRSettings.RenderViews[i]))
                                    {
                                        // Clear render target and depth stencil
                                        if (i == 0)
                                        {
                                            Clear?.Draw(drawContext);
                                        }

                                        ViewIndex = i;

                                        // draw view, but skip post processing (it will not do it, since eye count > 1)
                                        DrawView(context, drawContext, i, 2);

                                        // last eye, draw post effects over both eyes if we have some
                                        if (hasPostEffects && i == 1)
                                        {
                                            if (presentingVR)
                                            {
                                                var renderTargetDescription = TextureDescription.New2D(frameSize.Width, frameSize.Height, 1, PixelFormat.R8G8B8A8_UNorm_SRgb, TextureFlags.ShaderResource | TextureFlags.RenderTarget);
                                                vrFullSurface = PushScopedResource(drawContext.GraphicsContext.Allocator.GetTemporaryTexture2D(renderTargetDescription));
                                            }

                                            PostEffects.Draw(drawContext, OpaqueRenderStage.OutputValidator, currentRenderTargets.Items, currentDepthStencil, vrFullSurface);
                                        }
                                    }
                                }

                                if (VRSettings.VRDevice.SupportsOverlays)
                                {
                                    foreach (var overlay in VRSettings.Overlays)
                                    {
                                        if (overlay != null && overlay.Texture != null)
                                        {
                                            overlay.Overlay.UpdateSurface(drawContext.CommandList, overlay.Texture);
                                        }
                                    }
                                }

                                // if we are on our last forward renderer and our scene is ready for submission
                                if (presentingVR)
                                {
                                    VRSettings.VRDevice.Commit(drawContext.CommandList, vrFullSurface);
                                }
                            }
                    }

                    //draw mirror if desired
                    if (VRSettings.CopyMirror)
                    {
                        CopyOrScaleTexture(drawContext, vrFullSurface, drawContext.CommandList.RenderTarget);
                    }
                }
                else
                {
                    PrepareRenderTargets(drawContext, new Size2((int)viewport.Width, (int)viewport.Height));

                    ViewCount = 1;
                    ViewIndex = 0;

                    //var sssMaterialIndexRenderTarget = GenerateSSSMaterialIndexRenderTarget(context, viewport);

                    using (drawContext.PushRenderTargetsAndRestore())
                    {
                        drawContext.CommandList.SetRenderTargets(currentDepthStencil, currentRenderTargets.Count, currentRenderTargets.Items);

                        // Clear render target and depth stencil
                        Clear?.Draw(drawContext);

                        DrawView(context, drawContext, 0, 1);
                    }
                }
            }

            // Clear intermediate results
            currentRenderTargets.Clear();
            currentRenderTargetsNonMSAA.Clear();
            currentDepthStencil        = null;
            currentDepthStencilNonMSAA = null;
        }
Example #19
0
 //------------------------------------------------------------------------------------------
 // アラートエフェクトを終了する
 //------------------------------------------------------------------------------------------
 public void EndAlert()
 {
     alert         = false;
     currentEffect = PostEffects.Alert;
 }
Example #20
0
 /// <summary>
 /// Recycles the <see cref="Entity"/> so it may be re-used.
 /// </summary>
 /// <param name="isReleasing">Indicates whether the <see cref="Entity"/> is being released back to the <see cref="Pool"/>.</param>
 protected override void Recycle(bool isReleasing)
 {
     if (isReleasing)
         if (ParentCollection != null)
             ParentCollection.UnsafeRemove(this);
     ParentCollection = null;
     _flaggedForRemoval = false;
     _isEnabled = true;
     _isVisible = true;
     _depth = 0;
     _postEffects = PostEffects.None;
     Name = string.Empty;
     HasInitialized = false;
     HasLoadedContent = false;
     NeedsHeavyUpdate = false;
     base.Recycle(isReleasing);
 }
Example #21
0
 protected internal virtual bool SetValue(string name, string value)
 {
     //System.Diagnostics.Debugger.Launch();
     switch (name)
     {
         case "name":
             Name = value;
             return true;
         case "visible":
         case "isvisible":
             IsVisible = bool.Parse(value);
             return true;
         case "enabled":
         case "isenabled":
             IsEnabled = bool.Parse(value);
             return true;
         case "depth":
         case "layer":
         case "order":
         case "draworder":
         case "updateorder":
             Depth = float.Parse(value, CultureInfo.InvariantCulture);
             return true;
         case "overlay":
         case "isoverlay":
             PostEffects |= PostEffects.Overlay;
             return true;
      }
     return false;
 }
 protected override void Destroy()
 {
     PostEffects?.Dispose();
     depthStencilROCached?.Dispose();
 }