Ejemplo n.º 1
0
        public override MyEffectBase PrepareAndBeginShader(MyRender.MyRenderSetup setup, MyLodTypeEnum lodType)
        {
            var shader = (MyEffectModelsDNS)MyRender.GetEffect(MyEffects.ModelDNS);

            SetupBaseEffect(shader, setup, lodType);

            MyEffectModelsDNS dnsShader = shader as MyEffectModelsDNS;

            dnsShader.SetHalfPixel(MyRenderCamera.Viewport.Width, MyRenderCamera.Viewport.Height);
            dnsShader.SetScale(MyRender.GetScaleForViewport(MyRender.GetRenderTarget(MyRenderTargets.Depth)));

            bool useDepth = lodType != MyLodTypeEnum.LOD_NEAR;

            if (useDepth)
            {
                // DepthStencilState.DepthRead;
                MyStateObjects.DepthStencil_TestFarObject_DepthReadOnly.Apply();
            }
            else
            {
                DepthStencilState.DepthRead.Apply();
            }
            MyStateObjects.Holo_BlendState.Apply();

            shader.ApplyHolo(!useDepth);
            shader.Begin(0, SharpDX.Direct3D9.FX.None);
            return(shader);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Only to be called with FastOcclusionBoundingBoxDraw
        /// </summary>
        public static void PrepareFastOcclusionBoundingBoxDraw()
        {
            MyEffectOcclusionQueryDraw effectOQ = MyRender.GetEffect(MyEffects.OcclusionQueryDrawMRT) as MyEffectOcclusionQueryDraw;

            effectOQ.SetTechnique(MyEffectOcclusionQueryDraw.Technique.DepthTestEnabled);

            effectOQ.SetViewMatrix(MyCamera.ViewMatrixAtZero);
            effectOQ.SetProjectionMatrix(MyCamera.ProjectionMatrix);

            if (!MyRenderConstants.RenderQualityProfile.ForwardRender)
            {
                var depthRenderTarget = MyRender.GetRenderTarget(MyRenderTargets.Depth);
                effectOQ.SetDepthRT(depthRenderTarget);
                effectOQ.SetScale(MyRender.GetScaleForViewport(depthRenderTarget));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Draw occlusion bounding box method with our premade effect and box.
        /// </summary>
        /// <param name="bbox"></param>
        /// <param name="scale"></param>
        /// <param name="enableDepthTesting"></param>
        /// <param name="billboardLike">Indicates whether the occlusion object (box) is rotated to face the camera or not.</param>
        public static void DrawOcclusionBoundingBox(BoundingBox bbox, float scale, bool enableDepthTesting, bool billboardLike = false, bool useDepthTarget = true)
        {
            useDepthTarget &= !MyRenderConstants.RenderQualityProfile.ForwardRender;

            var    cameraToBBox = bbox.GetCenter() - MyCamera.Position;
            Matrix worldMatrix  = billboardLike ? Matrix.CreateWorld(Vector3.Zero, MyMwcUtils.Normalize(cameraToBBox), MyMwcUtils.Normalize(MyCamera.UpVector + MyCamera.LeftVector)) : Matrix.Identity;

            Vector3 scaleV = (bbox.Max - bbox.Min) * scale;

            worldMatrix            *= Matrix.CreateScale(scaleV);
            worldMatrix.Translation = cameraToBBox;



            MyEffectOcclusionQueryDraw effectOQ = MyRender.GetEffect(MyEffects.OcclusionQueryDrawMRT) as MyEffectOcclusionQueryDraw;

            if (enableDepthTesting && !MyRenderConstants.RenderQualityProfile.ForwardRender)
            {
                effectOQ.SetTechnique(MyEffectOcclusionQueryDraw.Technique.DepthTestEnabled);
            }
            else
            {
                effectOQ.SetTechnique(MyEffectOcclusionQueryDraw.Technique.DepthTestDisabled);
            }


            effectOQ.SetWorldMatrix(worldMatrix);
            effectOQ.SetViewMatrix(MyCamera.ViewMatrixAtZero);
            effectOQ.SetProjectionMatrix(MyCamera.ProjectionMatrix);

            if (useDepthTarget)
            {
                var depthRenderTarget = MyRender.GetRenderTarget(MyRenderTargets.Depth);
                effectOQ.SetDepthRT(depthRenderTarget);
                effectOQ.SetScale(MyRender.GetScaleForViewport(depthRenderTarget));
            }

            effectOQ.Begin();

            //draw
            m_modelBoxLowRes.Render();

            effectOQ.End();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Reads and issues occlusions queries and draws sun glare and flare effects based on
        /// the result of the queries.
        /// </summary>
        public static void DrawGlareAndFlare()
        {
            Vector3 projectedPosition = CalculateProjectedPosition();

            m_lightPosition = new Vector2(projectedPosition.X,
                                          projectedPosition.Y);

            // determine caller index and if the caller is allowed
            Debug.Assert(MyRender.CurrentRenderSetup.CallerID != null, "MyRender.CurrentRenderSetup.CallerID cannot be null");
            int callerIndex = Array.IndexOf(m_allowedCallers, (int)MyRender.CurrentRenderSetup.CallerID);

            if (callerIndex < 0)
            {
                Debug.Assert(false, "Sun Glare is called by an unallowed caller.");
            }

            // Check whether the light is hidden behind the scenery.
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("UpdateOcclusion");
            UpdateOcclusion(callerIndex);
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();

            if (m_visibilityRatios[callerIndex] < MyMwcMathConstants.EPSILON)
            {
                return;
            }

            float sizeInv             = 1f / MathHelper.Max(m_querySize, MySunConstants.MIN_QUERY_SIZE);
            float viewportScale       = 0.5f * (MyRender.GetScaleForViewport(null).X + MyRender.GetScaleForViewport(null).Y);
            var   borderFactor        = (50f / viewportScale) * sizeInv * (float)Math.Sqrt(m_occlusionMeasurementResults[callerIndex]);
            float borderFactorClamped = MathHelper.Clamp(borderFactor, 0, 1);

            // If it is visible, draw the flare effect.
            if (m_visibilityRatios[callerIndex] > 0 && borderFactorClamped > 0)
            {
                DrawGlare(borderFactorClamped, m_visibilityRatios[callerIndex]);
                DrawFlares(borderFactorClamped, m_visibilityRatios[callerIndex]);
            }
        }
Ejemplo n.º 5
0
        // Vertices must be in triangle strip order
        // 0--1
        // | /|
        // |/ |
        // 2--3
        public static void OcclusionPlaneDraw(Vector3[] quad)
        {
            Matrix worldMatrix = Matrix.Identity;

            worldMatrix.Translation = -MyCamera.Position;

            MyEffectOcclusionQueryDraw effectOQ = MyRender.GetEffect(MyEffects.OcclusionQueryDrawMRT) as MyEffectOcclusionQueryDraw;

            effectOQ.SetWorldMatrix(worldMatrix);
            effectOQ.SetViewMatrix(MyCamera.ViewMatrixAtZero);
            effectOQ.SetProjectionMatrix(MyCamera.ProjectionMatrix);

            if (!MyRenderConstants.RenderQualityProfile.ForwardRender)
            {
                var depthRenderTarget = MyRender.GetRenderTarget(MyRenderTargets.Depth);
                effectOQ.SetDepthRT(depthRenderTarget);
                effectOQ.SetScale(MyRender.GetScaleForViewport(depthRenderTarget));
                effectOQ.SetTechnique(MyEffectOcclusionQueryDraw.Technique.DepthTestEnabledNonMRT);
            }
            else
            {
                effectOQ.SetTechnique(MyEffectOcclusionQueryDraw.Technique.DepthTestDisabledNonMRT);
            }
        }
Ejemplo n.º 6
0
        private static void DrawGlare(float occlusionFactor, float visibilityRatio)
        {
            //Dont draw glare if there are godrays, it is overexposed then
            if (MyRenderConstants.RenderQualityProfile.EnableGodRays && MySector.GodRaysProperties.Enabled)
            {
                return;
            }

            var zoom = MyRender.CurrentRenderSetup.EnableZoom ? MyCamera.Zoom.GetZoomLevel() : 1;

            zoom = MathHelper.Clamp(zoom, 0.1f, 1);

            float glowSize = 0.1f * m_querySize / zoom;

            float occlusionRatio = occlusionFactor * visibilityRatio;

            Vector2 origin = new Vector2(m_glowSprite.Width, m_glowSprite.Height) / 2;

            float viewportScale = 0.5f * (MyRender.GetScaleForViewport(null).X + MyRender.GetScaleForViewport(null).Y);
            float scale         = glowSize * 2.0f / m_glowSprite.Width * viewportScale;

            m_directionToSunNormalized = MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized();
            float dot = Vector3.Dot(m_directionToSunNormalized, MyCamera.ForwardVector);

            float glareIntensity;

            if (dot > 0.9f)
            {
                glareIntensity = dot * (1 + MySunConstants.MAX_GLARE_MULTIPLIER * (dot - 0.9f));
            }
            else
            {
                glareIntensity = .9f;
            }


            m_spriteBatch.Begin(SpriteSortMode.Deferred, MyStateObjects.Additive_NoAlphaWrite_BlendState, SharpDX.Toolkit.Graphics.SamplerState.LinearClamp, DepthStencilState.None, RasterizerState.Current);

            Matrix rot = MyCamera.ViewMatrix;

            rot.Translation = Vector3.Zero;
            float yaw, pitch, roll;

            MyUtils.RotationMatrixToYawPitchRoll(ref rot, out yaw, out pitch, out roll);

            // ----- small colored glares (bleeding, complements bloom): -----
            // this one isn't rotating with camera:
            float glare1Alpha = occlusionRatio * occlusionRatio * (1 - MySector.FogProperties.FogMultiplier);
            float glare1Size  = scale;
            Color color1      = new Color(new Vector4(MySector.SunProperties.SunDiffuse, MathHelper.Clamp(glare1Alpha, 0, 0.1f)));

            m_spriteBatch.Draw(m_glowSprite, SharpDXHelper.ToSharpDX(m_lightPosition), null, SharpDXHelper.ToSharpDX(color1), -pitch, SharpDXHelper.ToSharpDX(origin), glare1Size, SpriteEffects.None, 0);

            // rays glare - this one is rotating with camera
            float glare2Alpha = 0.6f * glareIntensity * glareIntensity * occlusionRatio * occlusionRatio * (1 - MySector.FogProperties.FogMultiplier);
            float glare2Size  = 1.5f * glareIntensity * scale;
            Color color2      = new Color(new Vector4(MySector.SunProperties.SunDiffuse, glare2Alpha));

            m_spriteBatch.Draw(m_glowSprite2, SharpDXHelper.ToSharpDX(m_lightPosition), null, SharpDXHelper.ToSharpDX(color2), 0, SharpDXHelper.ToSharpDX(origin), glare2Size, SpriteEffects.None, 0);

            // large white glare - blinding effect
            float glare3Size = 40 * scale;

            m_spriteBatch.Draw(m_glareSprite, SharpDXHelper.ToSharpDX(m_lightPosition), null, new SharpDX.Color(1, 0, 1, glareIntensity * occlusionRatio * 0.3f), 0, SharpDXHelper.ToSharpDX(origin), glare3Size, SpriteEffects.None, 0);

            m_spriteBatch.End();
        }