Exemple #1
0
        public void UpdateLight()
        {
            UpdateSpotParams();

            if (m_propertiesDirty || m_positionDirty)
            {
                ProfilerShort.Begin("UpdateRenderLight");

                m_propertiesDirty = m_positionDirty = false;

                MyLightLayout pointLight = new MyLightLayout()
                {
                    Range         = Range,
                    Color         = Color,
                    Falloff       = Falloff,
                    GlossFactor   = GlossFactor,
                    DiffuseFactor = DiffuseFactor,
                };

                MySpotLightLayout spotLight = new MySpotLightLayout()
                {
                    Light = new MyLightLayout()
                    {
                        Range         = ReflectorRange,
                        Color         = ReflectorColor,
                        Falloff       = ReflectorFalloff,
                        GlossFactor   = ReflectorGlossFactor,
                        DiffuseFactor = ReflectorDiffuseFactor,
                    },
                    Up        = ReflectorUp,
                    Direction = ReflectorDirection,
                };

                MyFlareDesc glare = new MyFlareDesc()
                {
                    Enabled        = GlareOn,
                    Direction      = ReflectorDirection,
                    Range          = Range,
                    Color          = Color,
                    Type           = GlareType,
                    Size           = GlareSize,
                    QuerySize      = GlareQuerySize,
                    QueryFreqMinMs = GlareQueryFreqMinMs,
                    QueryFreqRndMs = GlareQueryFreqRndMs,
                    Intensity      = GlareIntensity,
                    Material       = MyStringId.GetOrCompute(GlareMaterial),
                    MaxDistance    = GlareMaxDistance,
                    ParentGID      = ParentID,
                };

                UpdateRenderLightData renderLightData = new UpdateRenderLightData()
                {
                    ID                       = RenderObjectID,
                    Position                 = Position,
                    Type                     = (VRageRender.LightTypeEnum)(int) LightType,
                    ParentID                 = ParentID,
                    PointPositionOffset      = PointLightOffset,
                    SpecularColor            = SpecularColor,
                    UseInForwardRender       = UseInForwardRender,
                    ReflectorConeMaxAngleCos = ReflectorConeMaxAngleCos,
                    ShadowDistance           = ShadowDistance,
                    CastShadows              = CastShadows,
                    PointLightOn             = LightOn,
                    PointLightIntensity      = Intensity,
                    PointLight               = pointLight,
                    SpotLightOn              = ReflectorOn,
                    SpotLightIntensity       = ReflectorIntensity,
                    SpotLight                = spotLight,
                    ReflectorTexture         = ReflectorTexture,
                    Glare                    = glare,
                };

                MyRenderProxy.UpdateRenderLight(ref renderLightData);

                ProfilerShort.End();
            }
        }
Exemple #2
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);
            }
        }
        internal static void UpdateSpotlight(LightId light, bool enabled, float intensity, float reflectorConeMaxAnglecos, MySpotLightLayout data, ISrvBindable reflectorTexture)
        {
            float coneMaxAngleCos = 1 - reflectorConeMaxAnglecos;

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

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

            var info = m_spotlights[light.Index];

            m_spotlights[light.Index].Spotlight        = data;
            m_spotlights[light.Index].ReflectorTexture = reflectorTexture;

            if (m_spotlights[light.Index].Enabled != enabled ||
                enabled && (Math.Abs(info.Spotlight.Light.Range - data.Light.Range) > 0.1f ||
                            Math.Abs(info.Spotlight.ApertureCos - data.ApertureCos) > 0.01f ||
                            m_spotlights[light.Index].BvhProxyId == -1))
            {
                m_spotlights[light.Index].Enabled = enabled;
                m_dirtySpotlights.Add(light);
                m_spotlights[light.Index].ViewProjectionDirty = true;
            }
        }