예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
0
        internal static void UpdateGlare(LightId light, MyGlareDesc desc)
        {
            if (desc.Enabled)
            {
                var gid = light.ParentGID;
                if (gid != -1 && MyIDTracker <MyActor> .FindByID((uint)gid) != null)
                {
                    var matrix = MyIDTracker <MyActor> .FindByID((uint)gid).WorldMatrix;

                    Vector3.TransformNormal(ref desc.Direction, ref matrix, out desc.Direction);
                }

                desc.MaxDistance = (desc.MaxDistance > 0)
                    ? (float)Math.Min(MyRenderConstants.MAX_GPU_OCCLUSION_QUERY_DISTANCE, desc.MaxDistance)
                    : MyRenderConstants.MAX_GPU_OCCLUSION_QUERY_DISTANCE;

                Glares[light] = desc;
            }
            else
            {
                Glares.Remove(light);
            }
        }
예제 #4
0
        internal static void UpdateGlare(LightId light, MyGlareDesc desc)
        {
            if(desc.Enabled)
            {
                var gid = light.ParentGID;
                if (gid != -1 && MyIDTracker<MyActor>.FindByID((uint)gid) != null)
                {
                    var matrix = MyIDTracker<MyActor>.FindByID((uint)gid).WorldMatrix;
                    Vector3.TransformNormal(ref desc.Direction, ref matrix, out desc.Direction);
                }

                desc.MaxDistance = (desc.MaxDistance > 0) 
                    ? (float)Math.Min(MyRenderConstants.MAX_GPU_OCCLUSION_QUERY_DISTANCE, desc.MaxDistance)
                    : MyRenderConstants.MAX_GPU_OCCLUSION_QUERY_DISTANCE;

                Glares[light] = desc;
            }
            else
            {
                Glares.Remove(light);
            }
        }
예제 #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);
        }
예제 #6
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.Position, MyEnvironment.InvView.Left, MyEnvironment.InvView.Up, drawingRadius);
        }