Esempio n. 1
0
        private void InitLight()
        {
            Vector3 localPosition;

            Position.GetInterpolatedValue(0, out localPosition);

            Vector4 color;

            Color.GetInterpolatedValue(0, out color);

            float range;

            Range.GetInterpolatedValue(0, out range);

            float intensity;

            Intensity.GetInterpolatedValue(0, out intensity);

            m_renderObjectID = VRageRender.MyRenderProxy.CreateRenderLight(
                VRageRender.LightTypeEnum.PointLight,
                Vector3D.Transform(localPosition * m_effect.GetEmitterScale(), m_effect.WorldMatrix),
                -1,
                0,
                color,
                color,
                1,
                0.75f,
                range * m_effect.GetEmitterScale(),
                intensity,
                true,
                false,
                0,
                false,
                Vector3.Zero,
                Vector3.Zero,
                0,
                Vector4.Zero,
                0,
                0,
                0,
                null,
                0,
                false,
                false,
                VRageRender.Lights.MyGlareTypeEnum.Normal,
                0,
                0,
                0,
                null,
                0);
        }
        private MatrixD CalculateWorldMatrix()
        {
            Vector3 pos = Offset;

            return(MatrixD.CreateTranslation(pos * m_effect.GetEmitterScale()) * GetEffect().WorldMatrix);
        }
Esempio n. 3
0
        public void Update()
        {
            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("ParticleLight-Update");

            bool created = false;

            if (Enabled)
            {
                if (m_renderObjectID == MyRenderProxy.RENDER_ID_UNASSIGNED)
                {
                    InitLight();
                    created = true;
                }
            }
            else
            {
                if (m_renderObjectID != MyRenderProxy.RENDER_ID_UNASSIGNED)
                {
                    CloseLight();
                }
                VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
                return;
            }

            Vector3 localPosition;

            Position.GetInterpolatedValue(m_effect.GetElapsedTime(), out localPosition);
            Vector3 localPositionVar;

            PositionVar.GetInterpolatedValue(m_effect.GetElapsedTime(), out localPositionVar);
            Vector3 localPositionVarRnd = new Vector3(
                MyUtils.GetRandomFloat(-localPositionVar.X, localPositionVar.X),
                MyUtils.GetRandomFloat(-localPositionVar.Y, localPositionVar.Y),
                MyUtils.GetRandomFloat(-localPositionVar.Z, localPositionVar.Z));

            localPosition += localPositionVarRnd;


            Vector4 color;

            Color.GetInterpolatedValue(m_effect.GetElapsedTime(), out color);
            float colorVar;

            ColorVar.GetInterpolatedValue(m_effect.GetElapsedTime(), out colorVar);
            float colorVarRnd = MyUtils.GetRandomFloat(1 - colorVar, 1 + colorVar);

            color.X = MathHelper.Clamp(color.X * colorVarRnd, 0, 1);
            color.Y = MathHelper.Clamp(color.Y * colorVarRnd, 0, 1);
            color.Z = MathHelper.Clamp(color.Z * colorVarRnd, 0, 1);

            float range;

            Range.GetInterpolatedValue(m_effect.GetElapsedTime(), out range);
            float rangeVar;

            RangeVar.GetInterpolatedValue(m_effect.GetElapsedTime(), out rangeVar);
            float rangeVarRnd = MyUtils.GetRandomFloat(-rangeVar, rangeVar);

            range += rangeVarRnd;

            float intensity;

            Intensity.GetInterpolatedValue(m_effect.GetElapsedTime(), out intensity);
            float intensityVar;

            IntensityVar.GetInterpolatedValue(m_effect.GetElapsedTime(), out intensityVar);
            float intensityRnd = MyUtils.GetRandomFloat(-intensityVar, intensityVar);

            intensity += intensityRnd;
            if (m_effect.IsStopped)
            {
                intensity = 0;
            }

            Vector3D position = Vector3D.Transform(localPosition * m_effect.GetEmitterScale(), m_effect.WorldMatrix);

            if ((m_position != position) ||
                (m_color != color) ||
                (m_range != range) ||
                (m_intensity != intensity) ||
                created)
            {
                m_color     = color;
                m_intensity = intensity;
                m_range     = range;
                m_position  = position;

                MyLightLayout light = new MyLightLayout()
                {
                    Range         = m_range * m_effect.GetEmitterScale(),
                    Color         = new Vector3(m_color),
                    Falloff       = 1,
                    GlossFactor   = 1,
                    DiffuseFactor = 1,
                };

                UpdateRenderLightData renderLightData = new UpdateRenderLightData()
                {
                    ID                  = m_renderObjectID,
                    Position            = m_position,
                    Type                = LightTypeEnum.PointLight,
                    ParentID            = -1,
                    UseInForwardRender  = true,
                    SpecularColor       = new Vector3(m_color),
                    PointLightOn        = true,
                    PointLightIntensity = m_intensity,
                    PointLight          = light,
                };
                MyRenderProxy.UpdateRenderLight(ref renderLightData);
            }

            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
        }