Пример #1
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));
        }
Пример #2
0
        public static void Draw()
        {
            if (!CanDrawCockpit())
            {
                return;
            }

            MyModel model = MyModels.GetModelForDraw(MySession.PlayerShip.CockpitGlassModelEnum);

            RasterizerState.CullNone.Apply();

            if (MyRenderConstants.RenderQualityProfile.ForwardRender)
            {
                DepthStencilState.DepthRead.Apply();
            }
            else
            {
                MyStateObjects.DepthStencil_StencilReadOnly.Apply();
            }

            BlendState.NonPremultiplied.Apply();

            MyEffectCockpitGlass effect = (MyEffectCockpitGlass)MyRender.GetEffect(MyEffects.CockpitGlass);

            float glassDirtAlpha = MathHelper.Lerp(MyCockpitGlassConstants.GLASS_DIRT_MIN, MyCockpitGlassConstants.GLASS_DIRT_MAX,
                                                   MySession.PlayerShip.GlassDirtLevel);

            effect.SetGlassDirtLevelAlpha(new Vector4(glassDirtAlpha, 0, 0, 0));

            effect.SetWorldMatrix(MySession.PlayerShip.PlayerHeadForCockpitInteriorWorldMatrix);
            effect.SetViewMatrix(MyCamera.ViewMatrix);

            if (!MyRenderConstants.RenderQualityProfile.ForwardRender)
            {
                Matrix projection = MyCamera.ProjectionMatrixForNearObjects;

                effect.SetWorldViewProjectionMatrix(MySession.PlayerShip.PlayerHeadForCockpitInteriorWorldMatrix * MyCamera.ViewMatrixAtZero * projection);
            }
            else
            {
                effect.SetWorldViewProjectionMatrix(MySession.PlayerShip.PlayerHeadForCockpitInteriorWorldMatrix * MyCamera.ViewProjectionMatrixAtZero);
            }

            MyMeshMaterial cockpitMaterial = model.GetMeshList()[0].Materials[0];

            cockpitMaterial.PreloadTexture();
            effect.SetCockpitGlassTexture(cockpitMaterial.DiffuseTexture);

            if (!MyRenderConstants.RenderQualityProfile.ForwardRender)
            {
                Texture depthRT = MyRender.GetRenderTarget(MyRenderTargets.Depth);
                effect.SetDepthTexture(depthRT);

                effect.SetHalfPixel(MyUtils.GetHalfPixel(depthRT.GetLevelDescription(0).Width, depthRT.GetLevelDescription(0).Height));
            }

            Vector4 sunColor = MySunWind.GetSunColor();

            effect.SetSunColor(new Vector3(sunColor.X, sunColor.Y, sunColor.Z));

            effect.SetDirectionToSun(MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized());

            effect.SetAmbientColor(Vector3.Zero);
            effect.SetReflectorPosition(MyCamera.Position - 4 * MySession.PlayerShip.WorldMatrix.Forward);

            if (MySession.PlayerShip.Light != null)
            {
                effect.SetNearLightColor(MySession.PlayerShip.Light.Color);
                effect.SetNearLightRange(MySession.PlayerShip.Light.Range);
            }

            MyRender.GetShadowRenderer().SetupShadowBaseEffect(effect);
            effect.SetShadowBias(0.001f);

            m_boundingSphereForLights.Center = MySession.PlayerShip.GetPosition();
            MyLights.UpdateEffect(effect, ref m_boundingSphereForLights, true);

            effect.Begin();
            model.Render();
            effect.End();

            MyCockpitGlassDecals.Draw(effect);
        }