コード例 #1
0
 internal static void WritePointlightConstants(LightId lid, ref MyPointlightConstants data)
 {
     data.VsPosition = Vector3.Transform(Lights.Data[lid.Index].Position - MyEnvironment.CameraPosition, ref MyEnvironment.ViewAt0);
     data.Range      = Pointlights[lid.Index].Range;
     data.Color      = Pointlights[lid.Index].Color;
     data.Falloff    = Pointlights[lid.Index].Falloff;
 }
コード例 #2
0
        internal static void WriteSpotlightConstants(LightId lid, ref SpotlightConstants data)
        {
            data.Spotlight = Spotlights[lid.Index].Spotlight;
            data.Spotlight.ShadowsRange   = Lights.Data[lid.Index].CastsShadowsThisFrame ? Lights.Data[lid.Index].ShadowsDistance : 0;
            data.Spotlight.Light.Position = Lights.Data[lid.Index].SpotPosition - MyRender11.Environment.Matrices.CameraPosition;

            float ratio = (float)Math.Sqrt(1 - data.Spotlight.ApertureCos * data.Spotlight.ApertureCos) / data.Spotlight.ApertureCos;
            float h     = ratio * data.Spotlight.Light.Range;

            Matrix viewProjAt0 = MyRender11.Environment.Matrices.ViewProjectionAt0;

            if (MyStereoRender.Enable)
            {
                if (MyStereoRender.RenderRegion == MyStereoRegion.LEFT)
                {
                    viewProjAt0 = MyStereoRender.EnvMatricesLeftEye.ViewProjectionAt0;
                }
                if (MyStereoRender.RenderRegion == MyStereoRegion.RIGHT)
                {
                    viewProjAt0 = MyStereoRender.EnvMatricesRightEye.ViewProjectionAt0;
                }
            }
            data.ProxyWorldViewProj = Matrix.Transpose(Matrix.CreateScale(2 * h, 2 * h, data.Spotlight.Light.Range) *
                                                       Matrix.CreateWorld(data.Spotlight.Light.Position, data.Spotlight.Direction, data.Spotlight.Up) *
                                                       viewProjAt0);

            data.ShadowMatrix = CreateShadowMatrix(lid);
        }
コード例 #3
0
        internal static LightId Create(uint GID)
        {
            var id = new LightId {
                Index = Lights.Allocate()
            };

            Lights.Data[id.Index] = new MyLightInfo
            {
            };

            MyArrayHelpers.Reserve(ref Pointlights, id.Index + 1);
            MyArrayHelpers.Reserve(ref Spotlights, id.Index + 1);

            Pointlights[id.Index] = new MyPointlightInfo
            {
                LastBvhUpdatePosition = Vector3.PositiveInfinity,
                BvhProxyId            = -1
            };

            Spotlights[id.Index] = new MySpotlightInfo
            {
                LastBvhUpdatePosition = Vector3.PositiveInfinity,
                BvhProxyId            = -1
            };

            IdIndex[GID] = id;

            return(id);
        }
コード例 #4
0
 internal static void DrawFlare(LightId id)
 {
     if (id.FlareId != FlareId.NULL)
     {
         MyFlareRenderer.Draw(id.FlareId, id.SpotPosition);
     }
 }
コード例 #5
0
        internal static void DrawGlare(LightId light)
        {
            var L        = MyEnvironment.CameraPosition - light.SpotPosition;
            var distance = (float)L.Length();

            if (!MyLights.Glares.ContainsKey(light))
            {
                return;
            }
            var desc = MyLights.Glares[light];

            switch (desc.Type)
            {
            case MyGlareTypeEnum.Distant:
                DrawDistantGlare(light, ref desc, distance);
                break;

            case MyGlareTypeEnum.Normal:
            case MyGlareTypeEnum.Directional:
                DrawNormalGlare(light, ref desc, L, distance);
                break;

            default:
                break;
            }
        }
コード例 #6
0
        internal static Matrix CreateShadowMatrix(LightId id)
        {
            var     worldMatrix         = MatrixD.CreateTranslation(MyRender11.Environment.Matrices.CameraPosition);
            MatrixD worldViewProjection = worldMatrix * GetSpotlightViewProjection(id);

            return(Matrix.Transpose(worldViewProjection * MyMatrixHelpers.ClipspaceToTexture));
        }
コード例 #7
0
ファイル: MyLight.cs プロジェクト: jdepablos/SpaceEngineers
        internal static void WritePointlightConstants(LightId lid, ref MyPointlightConstants data)
        {
            if (lid == LightId.NULL)
            {
                data = default(MyPointlightConstants);
                return;
            }

            data.VsPosition = Vector3.Transform(Lights.Data[lid.Index].PointPosition - MyRender11.Environment.CameraPosition, ref MyRender11.Environment.ViewAt0);
            if (MyStereoRender.Enable)
            {
                if (MyStereoRender.RenderRegion == MyStereoRegion.LEFT)
                {
                    data.VsPosition = Vector3.Transform(Lights.Data[lid.Index].PointPosition - MyStereoRender.EnvMatricesLeftEye.CameraPosition, ref MyStereoRender.EnvMatricesLeftEye.ViewAt0);
                }
                else if (MyStereoRender.RenderRegion == MyStereoRegion.RIGHT)
                {
                    data.VsPosition = Vector3.Transform(Lights.Data[lid.Index].PointPosition - MyStereoRender.EnvMatricesRightEye.CameraPosition, ref MyStereoRender.EnvMatricesRightEye.ViewAt0);
                }
            }
            data.Range       = Pointlights[lid.Index].Range;
            data.Color       = Pointlights[lid.Index].Color;
            data.Falloff     = Pointlights[lid.Index].Falloff;
            data.GlossFactor = Pointlights[lid.Index].GlossFactor;
        }
コード例 #8
0
 private static uint FindGID(LightId id)
 {
     foreach (var item in IdIndex)
     {
         if (item.Value.Index == id.Index)
         {
             return(item.Key);
         }
     }
     return(MyRenderProxy.RENDER_ID_UNASSIGNED);
 }
コード例 #9
0
        internal static MatrixD GetSpotlightViewProjection(LightId id)
        {
            if (Spotlights[id.Index].ViewProjectionDirty)
            {
                Spotlights[id.Index].ViewProjectionDirty = false;

                var nearPlaneDistance = 0.5f;
                var viewMatrix        = MatrixD.CreateLookAt(Lights.Data[id.Index].SpotPosition, Lights.Data[id.Index].SpotPosition + Spotlights[id.Index].Spotlight.Direction, Spotlights[id.Index].Spotlight.Up);
                var projectionMatrix  = MatrixD.CreatePerspectiveFieldOfView((float)(Math.Acos(Spotlights[id.Index].Spotlight.ApertureCos) * 2), 1.0f, nearPlaneDistance, Math.Max(id.ShadowDistance, nearPlaneDistance));
                Spotlights[id.Index].ViewProjection = viewMatrix * projectionMatrix;
            }
            return(Spotlights[id.Index].ViewProjection);
        }
コード例 #10
0
        internal static void WritePointlightConstants(LightId lid, ref MyPointlightConstants data)
        {
            if (lid == LightId.NULL)
            {
                data = default(MyPointlightConstants);
                return;
            }

            data.VsPosition = Vector3.Transform(Lights.Data[lid.Index].PositionWithOffset - MyEnvironment.CameraPosition, ref MyEnvironment.ViewAt0);
            data.Range      = Pointlights[lid.Index].Range;
            data.Color      = Pointlights[lid.Index].Color;
            data.Falloff    = Pointlights[lid.Index].Falloff;
        }
コード例 #11
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);
        }
コード例 #12
0
ファイル: MyLight.cs プロジェクト: caomw/SpaceEngineers
        internal static void UpdateEntity(LightId light, ref MyLightInfo info)
        {
            Lights.Data[light.Index] = info;

            var position = info.Position;
            var gid      = info.ParentGID;

            if (gid != -1 && MyIDTracker <MyActor> .FindByID((uint)gid) != null)
            {
                var matrix = MyIDTracker <MyActor> .FindByID((uint)gid).WorldMatrix;

                Vector3.Transform(ref position, ref matrix, out position);
            }

            Lights.Data[light.Index].Position = position;
        }
コード例 #13
0
ファイル: MyLight.cs プロジェクト: caomw/SpaceEngineers
        internal static void WriteSpotlightConstants(LightId lid, ref SpotlightConstants data)
        {
            data.ApertureCos  = Spotlights[lid.Index].ApertureCos;
            data.Range        = Spotlights[lid.Index].Range;
            data.Color        = Spotlights[lid.Index].Color;
            data.Direction    = Spotlights[lid.Index].Direction;
            data.Up           = Spotlights[lid.Index].Up;
            data.ShadowsRange = Lights.Data[lid.Index].CastsShadows ? Lights.Data[lid.Index].ShadowsDistance : 0;
            data.Position     = Lights.Data[lid.Index].Position - MyEnvironment.CameraPosition;

            float ratio = (float)Math.Sqrt(1 - data.ApertureCos * data.ApertureCos) / data.ApertureCos;
            float h     = ratio * data.Range;

            data.ProxyWorldViewProj = Matrix.Transpose(Matrix.CreateScale(2 * h, 2 * h, data.Range) *
                                                       Matrix.CreateWorld(data.Position, data.Direction, data.Up) *
                                                       MyEnvironment.ViewProjectionAt0);
        }
コード例 #14
0
        internal static int UpdateBvh(MyDynamicAABBTreeD bvh, LightId lid, bool enabled, int proxy, ref BoundingBoxD aabb)
        {
            if (enabled && proxy == -1)
            {
                return(bvh.AddProxy(ref aabb, lid, 0));
            }
            else if (enabled && proxy != -1)
            {
                bvh.MoveProxy(proxy, ref aabb, Vector3.Zero);
                return(proxy);
            }
            else
            {
                bvh.RemoveProxy(proxy);
            }

            return(-1);
        }
コード例 #15
0
        internal static void Remove(uint GID, LightId light)
        {
            IdIndex.Remove(GID);

            if (Pointlights[light.Index].BvhProxyId != -1)
            {
                PointlightsBvh.RemoveProxy(Pointlights[light.Index].BvhProxyId);
            }

            if (Spotlights[light.Index].BvhProxyId != -1)
            {
                SpotlightsBvh.RemoveProxy(Spotlights[light.Index].BvhProxyId);
            }

            DirtyPointlights.Remove(light);
            DirtySpotlights.Remove(light);
            Lights.Free(light.Index);
        }
コード例 #16
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);
        }
コード例 #17
0
        internal static void UpdateSpotlight(LightId light, bool enabled,
                                             Vector3 direction, float range, float apertureCos, Vector3 up,
                                             Vector3 color, float falloff, float glossFactor, TexId reflectorTexture)
        {
            var info = Spotlights[light.Index];

            var gid = light.ParentGID;

            if (gid != -1 && MyIDTracker <MyActor> .FindByID((uint)gid) != null)
            {
                var matrix = MyIDTracker <MyActor> .FindByID((uint)gid).WorldMatrix;

                Vector3.TransformNormal(ref direction, ref matrix, out direction);
                Vector3.TransformNormal(ref up, ref matrix, out up);
            }

            bool aabbChanged = info.Direction != direction || info.Range != range || info.ApertureCos != apertureCos || info.Up != up;

            Spotlights[light.Index].Enabled          = enabled;
            Spotlights[light.Index].Direction        = direction;
            Spotlights[light.Index].Range            = range;
            Spotlights[light.Index].ApertureCos      = apertureCos;
            Spotlights[light.Index].Up               = up;
            Spotlights[light.Index].Falloff          = falloff;
            Spotlights[light.Index].GlossFactor      = glossFactor;
            Spotlights[light.Index].Color            = color;
            Spotlights[light.Index].ReflectorTexture = reflectorTexture;

            var proxy = Spotlights[light.Index].BvhProxyId;
            var positionDifference = Vector3D.RectangularDistance(ref Spotlights[light.Index].LastBvhUpdatePosition, ref Lights.Data[light.Index].SpotPosition);

            bool dirty = (enabled && ((proxy == -1) || (positionDifference > MOVE_TOLERANCE || aabbChanged))) || (!enabled && proxy != -1);

            if (dirty)
            {
                DirtySpotlights.Add(light);
            }
            else
            {
                DirtySpotlights.Remove(light);
            }
        }
コード例 #18
0
        internal static void UpdateSpotlight(LightId light, bool enabled, float intensity, float reflectorConeMaxAnglecos, MySpotLightLayout data, ISrvBindable reflectorTexture)
        {
            // Convert as in dx9
            float coneMaxAngleCos = 1 - reflectorConeMaxAnglecos;

            coneMaxAngleCos = (float)Math.Min(Math.Max(coneMaxAngleCos, 0.01), 0.99f);

            data.Light.Color *= intensity;
            data.ApertureCos  = coneMaxAngleCos;

            var info = Spotlights[light.Index];

            var gid = light.ParentGID;

            if (gid != -1 && MyIDTracker <MyActor> .FindByID((uint)gid) != null)
            {
                var matrix = MyIDTracker <MyActor> .FindByID((uint)gid).WorldMatrix;

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

            bool aabbChanged = info.Spotlight.Direction != data.Direction || info.Spotlight.Light.Range != data.Light.Range || info.Spotlight.ApertureCos != data.ApertureCos || info.Spotlight.Up != data.Up;

            Spotlights[light.Index].Enabled          = enabled;
            Spotlights[light.Index].Spotlight        = data;
            Spotlights[light.Index].ReflectorTexture = reflectorTexture;

            var proxy = Spotlights[light.Index].BvhProxyId;
            var positionDifference = Vector3D.RectangularDistance(ref Spotlights[light.Index].LastBvhUpdatePosition, ref Lights.Data[light.Index].SpotPosition);

            bool dirty = (enabled && ((proxy == -1) || (positionDifference > MOVE_TOLERANCE || aabbChanged))) || (!enabled && proxy != -1);

            if (dirty)
            {
                DirtySpotlights.Add(light);
            }
            else
            {
                DirtySpotlights.Remove(light);
            }
        }
コード例 #19
0
        internal static void UpdatePointlight(LightId light, bool enabled, float intensity, MyLightLayout data)
        {
            data.Color *= intensity;

            Pointlights[light.Index].Enabled = enabled;
            Pointlights[light.Index].Light   = data;

            var proxy      = Pointlights[light.Index].BvhProxyId;
            var difference = Vector3D.RectangularDistance(ref Pointlights[light.Index].LastBvhUpdatePosition, ref Lights.Data[light.Index].PointPosition);

            bool dirty = (enabled && ((proxy == -1) || (difference > MOVE_TOLERANCE))) || (!enabled && proxy != -1);

            if (dirty)
            {
                DirtyPointlights.Add(light);
            }
            else
            {
                DirtyPointlights.Remove(light);
            }
        }
コード例 #20
0
        internal static void UpdatePointlight(LightId light, bool enabled, float range, Vector3 color, float falloff)
        {
            Pointlights[light.Index].Range   = range;
            Pointlights[light.Index].Color   = color;
            Pointlights[light.Index].Falloff = falloff;
            Pointlights[light.Index].Enabled = enabled;


            var proxy      = Pointlights[light.Index].BvhProxyId;
            var difference = Vector3D.RectangularDistance(ref Pointlights[light.Index].LastBvhUpdatePosition, ref Lights.Data[light.Index].PositionWithOffset);

            bool dirty = (enabled && ((proxy == -1) || (difference > MOVE_TOLERANCE))) || (!enabled && proxy != -1);

            if (dirty)
            {
                DirtyPointlights.Add(light);
            }
            else
            {
                DirtyPointlights.Remove(light);
            }
        }
コード例 #21
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);
            }
        }
コード例 #22
0
ファイル: MyLight.cs プロジェクト: fluxit/SpaceEngineers
        internal static LightId Create(uint GID)
        {
            var id = new LightId { Index = Lights.Allocate() };

            Lights.Data[id.Index] = new MyLightInfo
            {

            };

            MyArrayHelpers.Reserve(ref Pointlights, id.Index + 1);
            MyArrayHelpers.Reserve(ref Spotlights, id.Index + 1);

            Pointlights[id.Index] = new MyPointlightInfo
            {
                LastBvhUpdatePosition = Vector3.PositiveInfinity,
                BvhProxyId = -1
            };

            Spotlights[id.Index] = new MySpotlightInfo
            {
                LastBvhUpdatePosition = Vector3.PositiveInfinity,
                BvhProxyId = -1
            };

            IdIndex[GID] = id;

            return id;
        }
コード例 #23
0
        internal static void DrawGlare(LightId light)
        {
            var L = MyEnvironment.CameraPosition - light.Position;
            var distance = (float) L.Length();

            if(!MyLights.Glares.ContainsKey(light))
            {
                return;
            }
            var desc = MyLights.Glares[light];

            switch(desc.Type)
            {
                case MyGlareTypeEnum.Distant:
                    DrawDistantGlare(light, ref desc, distance);
                    break;
                case MyGlareTypeEnum.Normal:
                case MyGlareTypeEnum.Directional:
                    DrawNormalGlare(light, ref desc, L, distance);
                    break;
                default:
                    break;
            }

        }
コード例 #24
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);
        }
コード例 #25
0
ファイル: MyLight.cs プロジェクト: fluxit/SpaceEngineers
        internal static void WriteSpotlightConstants(LightId lid, ref SpotlightConstants data)
        {
            data.ApertureCos = Spotlights[lid.Index].ApertureCos;
            data.Range = Spotlights[lid.Index].Range;
            data.Color = Spotlights[lid.Index].Color;
            data.Direction = Spotlights[lid.Index].Direction;
            data.Up = Spotlights[lid.Index].Up;
            data.ShadowsRange = Lights.Data[lid.Index].CastsShadowsThisFrame ? Lights.Data[lid.Index].ShadowsDistance : 0;
            data.Position = Lights.Data[lid.Index].PositionWithOffset - MyEnvironment.CameraPosition;


            float ratio = (float)Math.Sqrt(1 - data.ApertureCos * data.ApertureCos) / data.ApertureCos;
            float h = ratio * data.Range;
            
            data.ProxyWorldViewProj = Matrix.Transpose(Matrix.CreateScale(2 * h, 2 * h, data.Range) *
                Matrix.CreateWorld(data.Position, data.Direction, data.Up) *
                MyEnvironment.ViewProjectionAt0);
        }
コード例 #26
0
ファイル: MyLight.cs プロジェクト: fluxit/SpaceEngineers
 internal static void WritePointlightConstants(LightId lid, ref MyPointlightConstants data)
 {
     data.VsPosition = Vector3.Transform(Lights.Data[lid.Index].PositionWithOffset - MyEnvironment.CameraPosition, ref MyEnvironment.ViewAt0);
     data.Range = Pointlights[lid.Index].Range;
     data.Color = Pointlights[lid.Index].Color;
     data.Falloff = Pointlights[lid.Index].Falloff;
 }
コード例 #27
0
ファイル: MyLight.cs プロジェクト: fluxit/SpaceEngineers
        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);
            }
        }
コード例 #28
0
ファイル: MyLight.cs プロジェクト: fluxit/SpaceEngineers
        internal static void UpdateSpotlight(LightId light, bool enabled, 
            Vector3 direction, float range, float apertureCos, Vector3 up,
            Vector3 color, float falloff, TexId reflectorTexture)
        {
            var info = Spotlights[light.Index];

            var gid = light.ParentGID;
            if (gid != -1 && MyIDTracker<MyActor>.FindByID((uint)gid) != null)
            {
                var matrix = MyIDTracker<MyActor>.FindByID((uint)gid).WorldMatrix;
                Vector3.TransformNormal(ref direction, ref matrix, out direction);
                Vector3.TransformNormal(ref up, ref matrix, out up);
            }

            bool aabbChanged = info.Direction != direction || info.Range != range || info.ApertureCos != apertureCos || info.Up != up;

            Spotlights[light.Index].Enabled = enabled;
            Spotlights[light.Index].Direction = direction;
            Spotlights[light.Index].Range = range;
            Spotlights[light.Index].ApertureCos = apertureCos;
            Spotlights[light.Index].Up = up;
            Spotlights[light.Index].Falloff = falloff;
            Spotlights[light.Index].Color = color;
            Spotlights[light.Index].ReflectorTexture = reflectorTexture;

            var proxy = Spotlights[light.Index].BvhProxyId;
            var positionDifference = Vector3D.RectangularDistance(ref Spotlights[light.Index].LastBvhUpdatePosition, ref Lights.Data[light.Index].PositionWithOffset);

            bool dirty = (enabled && ((proxy == -1) || (positionDifference > MOVE_TOLERANCE || aabbChanged))) || (!enabled && proxy != -1);

            if (dirty)
            {
                DirtySpotlights.Add(light);
            }
            else
            {
                DirtySpotlights.Remove(light);
            }
        }
コード例 #29
0
ファイル: MyLight.cs プロジェクト: fluxit/SpaceEngineers
        internal static void UpdatePointlight(LightId light, bool enabled, float range, Vector3 color, float falloff)
        {
            Pointlights[light.Index].Range = range;
            Pointlights[light.Index].Color = color;
            Pointlights[light.Index].Falloff = falloff;
            Pointlights[light.Index].Enabled = enabled;

            
            var proxy = Pointlights[light.Index].BvhProxyId;
            var difference = Vector3D.RectangularDistance(ref Pointlights[light.Index].LastBvhUpdatePosition, ref Lights.Data[light.Index].PositionWithOffset);

            bool dirty = (enabled && ((proxy == -1) || (difference > MOVE_TOLERANCE))) || (!enabled && proxy != -1);

            if(dirty)
            {
                DirtyPointlights.Add(light);
            }
            else
            {
                DirtyPointlights.Remove(light);
            }
        }
コード例 #30
0
ファイル: MyLight.cs プロジェクト: fluxit/SpaceEngineers
        internal static void UpdateEntity(LightId light, ref MyLightInfo info)
        {
            Lights.Data[light.Index] = info;

            Lights.Data[light.Index].LocalPosition = info.Position;
            Lights.Data[light.Index].LocalPositionWithOffset = info.PositionWithOffset;
            var position = info.Position;
            var positionWithOffset = info.PositionWithOffset;
            var gid = info.ParentGID;
            if (gid != -1 && MyIDTracker<MyActor>.FindByID((uint)gid) != null)
            {
                var matrix = MyIDTracker<MyActor>.FindByID((uint)gid).WorldMatrix;
                Vector3D.Transform(ref position, ref matrix, out position);
                Vector3D.Transform(ref positionWithOffset, ref matrix, out positionWithOffset);
            }

            Lights.Data[light.Index].Position = position;
            Lights.Data[light.Index].PositionWithOffset = positionWithOffset;
        }
コード例 #31
0
ファイル: MyLight.cs プロジェクト: fluxit/SpaceEngineers
        internal static int UpdateBvh(MyDynamicAABBTreeD bvh, LightId lid, bool enabled, int proxy, ref BoundingBoxD aabb)
        {
            if(enabled && proxy == -1)
            {
                return bvh.AddProxy(ref aabb, lid, 0);
            }
            else if(enabled && proxy != -1)
            {
                bvh.MoveProxy(proxy, ref aabb, Vector3.Zero);
                return proxy;
            }
            else
            {
                bvh.RemoveProxy(proxy);
            }

            return -1;
        }
コード例 #32
0
ファイル: MyLight.cs プロジェクト: fluxit/SpaceEngineers
        internal static void Remove(uint GID, LightId light)
        {
            IdIndex.Remove(GID);

            if (Pointlights[light.Index].BvhProxyId != -1)
            {
                PointlightsBvh.RemoveProxy(Pointlights[light.Index].BvhProxyId);
            }

            if (Spotlights[light.Index].BvhProxyId != -1)
            {
                SpotlightsBvh.RemoveProxy(Spotlights[light.Index].BvhProxyId);
            }

            DirtyPointlights.Remove(light);
            DirtySpotlights.Remove(light);
            Lights.Free(light.Index);
        }
コード例 #33
0
 internal static void DrawFlare(LightId id)
 {
     if (id.FlareId != FlareId.NULL)
         MyFlareRenderer.Draw(id.FlareId, id.SpotPosition);
 }
コード例 #34
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);
        }