Пример #1
0
        private static void DrawNormalFlare(Vector3D position, ref Data flare, Vector3 L, float distance)
        {
            if (flare.Query == null)
            {
                return;
            }

            flare.Query.Position  = position;
            flare.Query.Size      = flare.Desc.QuerySize;
            flare.Query.FreqMinMs = flare.Desc.QueryFreqMinMs;
            flare.Query.FreqRndMs = flare.Desc.QueryFreqRndMs;
            flare.Query.Visible   = true;

            var intensity   = flare.Desc.Intensity;
            var maxDistance = flare.Desc.MaxDistance;

            float alpha = flare.Query.Result * flare.Query.Result * intensity;


            const float minFlareRadius = 0.2f;
            const float maxFlareRadius = 10;
            float       radius         = MathHelper.Clamp(flare.Desc.Range * 20, minFlareRadius, maxFlareRadius);

            float drawingRadius = radius * flare.Desc.Size;

            if (flare.Desc.Type == Lights.MyGlareTypeEnum.Directional)
            {
                float dot = Vector3.Dot(L, flare.DirectionWorld);
                alpha *= dot;
            }

            if (alpha <= MyMathConstants.EPSILON)
            {
                return;
            }

            if (distance > maxDistance * .5f)
            {
                // distance falloff
                float falloff = (distance - .5f * maxDistance) / (.5f * maxDistance);
                falloff        = (float)Math.Max(0, 1 - falloff);
                drawingRadius *= falloff;
                alpha         *= falloff;
            }

            if (drawingRadius <= float.Epsilon)
            {
                return;
            }

            var color = flare.Desc.Color;
            //color.A = 0;

            var material = MyTransparentMaterials.GetMaterial(flare.Desc.Material.ToString());

            MyBillboardsHelper.AddBillboardOriented(flare.Desc.Material.ToString(),
                                                    color * alpha, position, MyRender11.Environment.Matrices.InvView.Left, MyRender11.Environment.Matrices.InvView.Up, drawingRadius,
                                                    MyBillboard.BlenType.AdditiveTop);
        }
Пример #2
0
        private static void DrawDistantFlare(Vector3D position, ref Data flare, float distance)
        {
            if (flare.Query == null)
            {
                return;
            }

            flare.Query.Position  = position;
            flare.Query.Size      = flare.Desc.QuerySize;
            flare.Query.FreqMinMs = flare.Desc.QueryFreqMinMs;
            flare.Query.FreqRndMs = flare.Desc.QueryFreqRndMs;
            flare.Query.Visible   = true;

            const float RESULT_FLOOR = 0.01f;
            float       result       = (flare.Query.Result - RESULT_FLOOR) * (1 / (1 - RESULT_FLOOR));
            float       alpha        = result * result * flare.Desc.Intensity;

            if (alpha < MyMathConstants.EPSILON)
            {
                return;
            }

            /*const int minFlareRadius = 5;
             * const int maxFlareRadius = 150;
             *
             * // parent range
             * float drawingRadius = MathHelper.Clamp(flare.Desc.Range * distance / 1000.0f, minFlareRadius, maxFlareRadius);*/
            const float minFlareRadius = 0.2f;
            const float maxFlareRadius = 10;
            float       radius         = MathHelper.Clamp(flare.Desc.Range * 20, minFlareRadius, maxFlareRadius);
            float       drawingRadius  = radius * flare.Desc.Size;

            var startFadeout = flare.Desc.MaxDistance * 0.8f;
            var endFadeout   = flare.Desc.MaxDistance;

            if (distance > startFadeout)
            {
                var fade = (distance - startFadeout) / (endFadeout - startFadeout);
                alpha *= (1 - fade);
            }

            if (alpha < MyMathConstants.EPSILON)
            {
                return;
            }

            var color = flare.Desc.Color;

            //var material = (flare.Desc.Type == Lights.MyGlareTypeEnum.Distant && distance > MyRenderConstants.MAX_GPU_OCCLUSION_QUERY_DISTANCE) ?
            //  "LightGlareDistant" : "LightGlare";

            MyBillboardsHelper.AddBillboardOriented(flare.Desc.Material.ToString(),
                                                    color * alpha, position, MyRender11.Environment.Matrices.InvView.Left, MyRender11.Environment.Matrices.InvView.Up, drawingRadius,
                                                    MyBillboard.BlenType.AdditiveTop);
        }
Пример #3
0
        private static void DrawNormalFlare(Vector3D position, ref MyFlareDesc flare, Vector3 L, float distance)
        {
            //if (m_occlusionRatio <= MyMathConstants.EPSILON)
            //    return;

            var intensity   = flare.Intensity;
            var maxDistance = flare.MaxDistance;

            //float alpha = m_occlusionRatio * intensity;
            float alpha = intensity;


            const float minFlareRadius = 0.2f;
            const float maxFlareRadius = 10;
            float       radius         = MathHelper.Clamp(flare.Range * 20, minFlareRadius, maxFlareRadius);

            float drawingRadius = radius * flare.Size;

            if (flare.Type == Lights.MyGlareTypeEnum.Directional)
            {
                float dot = Vector3.Dot(L, flare.Direction);
                alpha *= dot;
            }

            if (alpha <= MyMathConstants.EPSILON)
            {
                return;
            }

            if (distance > maxDistance * .5f)
            {
                // distance falloff
                float falloff = (distance - .5f * maxDistance) / (.5f * maxDistance);
                falloff        = (float)Math.Max(0, 1 - falloff);
                drawingRadius *= falloff;
                alpha         *= falloff;
            }

            if (drawingRadius <= float.Epsilon)
            {
                return;
            }

            var color = flare.Color;
            //color.A = 0;

            var material = MyTransparentMaterials.GetMaterial(flare.Material.ToString());

            MyBillboardsHelper.AddBillboardOriented(flare.Material.ToString(),
                                                    color * alpha, position, MyRender11.Environment.Matrices.InvView.Left, MyRender11.Environment.Matrices.InvView.Up, drawingRadius);
        }
Пример #4
0
        internal static void DrawNormalGlare(LightId light, ref MyGlareDesc glare, Vector3 L, float distance)
        {
            //if (m_occlusionRatio <= MyMathConstants.EPSILON)
            //    return;

            var intensity   = glare.Intensity;
            var maxDistance = glare.MaxDistance;

            //float alpha = m_occlusionRatio * intensity;
            float alpha = intensity;


            const float minGlareRadius = 0.2f;
            const float maxGlareRadius = 10;
            float       radius         = MathHelper.Clamp(glare.Range * 20, minGlareRadius, maxGlareRadius);

            float drawingRadius = radius * glare.Size;

            if (glare.Type == MyGlareTypeEnum.Directional)
            {
                float dot = Vector3.Dot(L, glare.Direction);
                alpha *= dot;
            }

            if (alpha <= MyMathConstants.EPSILON)
            {
                return;
            }

            if (distance > maxDistance * .5f)
            {
                // distance falloff
                float falloff = (distance - .5f * maxDistance) / (.5f * maxDistance);
                falloff        = (float)Math.Max(0, 1 - falloff);
                drawingRadius *= falloff;
                alpha         *= falloff;
            }

            if (drawingRadius <= float.Epsilon)
            {
                return;
            }

            var color = glare.Color;

            color.A = 0;

            MyBillboardsHelper.AddBillboardOriented(glare.Material.ToString(),
                                                    color * alpha, light.SpotPosition, MyEnvironment.InvView.Left, MyEnvironment.InvView.Up, drawingRadius);
        }
Пример #5
0
        internal static void DrawDistantGlare(LightId light, ref MyGlareDesc glare, float distance)
        {
            //float alpha = m_occlusionRatio * intensity;

            float alpha = glare.Intensity * (glare.QuerySize / 7.5f);

            if (alpha < MyMathConstants.EPSILON)
            {
                return;
            }

            const int minGlareRadius = 5;
            const int maxGlareRadius = 150;

            //glare.QuerySize

            // parent range
            float radius = MathHelper.Clamp(glare.Range * distance / 100.0f, minGlareRadius, maxGlareRadius);

            float drawingRadius = radius;

            var startFadeout = 1000;
            var endFadeout   = 1100;

            if (distance > startFadeout)
            {
                var fade = (distance - startFadeout) / (endFadeout - startFadeout);
                alpha *= (1 - fade);
            }

            if (alpha < MyMathConstants.EPSILON)
            {
                return;
            }

            var color = glare.Color;

            color.A = 0;

            var material = (glare.Type == MyGlareTypeEnum.Distant && distance > MyRenderConstants.MAX_GPU_OCCLUSION_QUERY_DISTANCE) ? "LightGlareDistant" : "LightGlare";

            MyBillboardsHelper.AddBillboardOriented(material,
                                                    color * alpha, light.Position, MyEnvironment.InvView.Left, MyEnvironment.InvView.Up, drawingRadius);
        }