Exemplo n.º 1
0
        static void SetLightToEffect(MyEffectDynamicLightingBase effect, int index, MyLight light, bool subtractCameraPosition)
        {
            if (subtractCameraPosition == true)
            {
                effect.SetDynamicLightsPosition(index, light.Position - MyCamera.Position);
            }
            else
            {
                effect.SetDynamicLightsPosition(index, light.Position);
            }

            effect.SetDynamicLightsColor(index, light.Color * light.Intensity);
            effect.SetDynamicLightsFalloff(index, light.Falloff);
            effect.SetDynamicLightsRange(index, light.Range);
        }
Exemplo n.º 2
0
        static void SetLightToEffect(MyEffectDynamicLightingBase effect, int index, MyRenderLight light, bool subtractCameraPosition)
        {
            if (subtractCameraPosition == true)
            {
                effect.SetDynamicLightsPosition(index, (Vector3)(light.Position - MyRenderCamera.Position));
            }
            else
            {
                effect.SetDynamicLightsPosition(index, (Vector3)light.Position);
            }

            //Cannot use *light.Intensity because it makes visual artifacts
            effect.SetDynamicLightsColor(index, light.Color * MathHelper.Clamp(light.Intensity, 0, 1));
            effect.SetDynamicLightsFalloff(index, light.Falloff);
            effect.SetDynamicLightsRange(index, light.Range);
        }
Exemplo n.º 3
0
        //  This method adds lights information into specified effect.
        //  Method gets lights that could have influence on bounding sphere (it is assumed this will be bounding sphere of a phys object or voxel render cell).
        //  Lights that are far from bounding sphere are ignored. But near lights are taken to second step, where we sort them by distance and priority
        //  and set them to the effect.
        //  We assume RemoveKilled() was called before this method, so here we don't check if light isn't killed.
        public static void UpdateEffect(MyEffectDynamicLightingBase effect, ref BoundingSphere boundingSphere, bool subtractCameraPosition)
        {
            MyUtils.AssertIsValid(boundingSphere.Center);
            MyUtils.AssertIsValid(boundingSphere.Radius);

            // Reason to remove this condition: when updating effect with same bounding sphere, it could return different result when some light died (effect ended) before second request
            //if (m_lastBoundingSphere != boundingSphere)
            {
                UpdateSortedLights(ref boundingSphere, true);
                m_lastBoundingSphere = boundingSphere;

                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //  Now in 'm_sortedLights' we have only lights that intersects bounding sphere in SAP list
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                m_lightsCount = m_sortedLights.Count;
                int maxLightsForEffect = MyLightsConstants.MAX_LIGHTS_FOR_EFFECT;

                //  If number of lights with influence is more than max number of lights allowed in the effect, we sort them by distance (or we can do it by some priority)
                if (m_sortedLights.Count > maxLightsForEffect)
                {
                    m_sortLightsComparer.BoundingSphere = boundingSphere;
                    m_sortedLights.Sort(m_sortLightsComparer);
                    m_lightsCount = maxLightsForEffect;
                }
            }

            //  Set lights to effect, but not more than effect can handle
            for (int i = 0; i < m_lightsCount; i++)
            {
                SetLightToEffect(effect, i, m_sortedLights[i], subtractCameraPosition);
            }

            effect.SetDynamicLightsCount(m_lightsCount);


            Vector4 sunColor = MySunWind.GetSunColor();

            effect.SetSunColor(new Vector3(sunColor.X, sunColor.Y, sunColor.Z));
            effect.SetDirectionToSun(MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized());
            effect.SetSunIntensity(MySector.SunProperties.SunIntensity);

            Vector3 ambientColor = MyRender.AmbientColor * MyRender.AmbientMultiplier;

            effect.SetAmbientColor(ambientColor * (MyRenderConstants.RenderQualityProfile.ForwardRender ? 6.5f : 1.0f));
        }
Exemplo n.º 4
0
        //  This method adds lights information into specified effect.
        //  Method gets lights that could have influence on bounding sphere (it is assumed this will be bounding sphere of a phys object or voxel render cell).
        //  Lights that are far from bounding sphere are ignored. But near lights are taken to second step, where we sort them by distance and priority
        //  and set them to the effect.
        //  We assume RemoveKilled() was called before this method, so here we don't check if light isn't killed.
        public static void UpdateEffect(MyEffectDynamicLightingBase effect, bool subtractCameraPosition)
        {
            //  Set lights to effect, but not more than effect can handle
            for (int i = 0; i < m_renderLights.Count; i++)
            {
                SetLightToEffect(effect, i, m_renderLights[i], subtractCameraPosition);
            }

            effect.SetDynamicLightsCount(m_renderLights.Count);

            Vector4 sunColor = MyRender.Sun.Color;

            effect.SetSunColor(new Vector3(sunColor.X, sunColor.Y, sunColor.Z));
            effect.SetDirectionToSun(-MyRender.Sun.Direction);
            effect.SetSunIntensity(MyRender.Sun.Intensity);

            Vector3 ambientColor = MyRender.AmbientColor * MyRender.AmbientMultiplier;

            effect.SetAmbientColor(ambientColor);
        }