Exemple #1
0
        public override void AddRenderObjects()
        {
            base.AddRenderObjects();
            base.ResizeRenderObjectArray(0x10);
            int      length = base.RenderObjectIDs.Length;
            Vector3D positionLeftBottomCorner = this.m_planet.PositionLeftBottomCorner;
            Vector3  atmosphereWavelengths    = new Vector3 {
                X = 1f / ((float)Math.Pow((double)this.m_planet.AtmosphereWavelengths.X, 4.0)),
                Y = 1f / ((float)Math.Pow((double)this.m_planet.AtmosphereWavelengths.Y, 4.0)),
                Z = 1f / ((float)Math.Pow((double)this.m_planet.AtmosphereWavelengths.Z, 4.0))
            };
            IMyEntity entity = base.Entity;

            if (this.m_planet.HasAtmosphere)
            {
                MatrixD xd2 = MatrixD.Identity * this.m_planet.AtmosphereRadius;
                xd2.M44         = 1.0;
                xd2.Translation = base.Entity.PositionComp.GetPosition();
                this.m_atmosphereRenderIndex = length;
                length++;
                long entityId = base.Entity.EntityId;
                this.SetRenderObjectID(length, MyRenderProxy.CreateRenderEntityAtmosphere(base.Entity.GetFriendlyName() + " " + entityId.ToString(), @"Models\Environment\Atmosphere_sphere.mwm", xd2, MyMeshDrawTechnique.ATMOSPHERE, RenderFlags.DrawOutsideViewDistance | RenderFlags.Visible, this.GetRenderCullingOptions(), this.m_planet.AtmosphereRadius, this.m_planet.AverageRadius, atmosphereWavelengths, 0f, float.MaxValue, base.FadeIn));
                this.UpdateAtmosphereSettings(this.m_planet.AtmosphereSettings);
            }
            this.m_shadowHelperRenderObjectIndex = length;
            MatrixD worldMatrix = MatrixD.CreateScale((double)this.m_planet.MinimumRadius);

            worldMatrix.Translation = this.m_planet.WorldMatrix.Translation;
            length++;
            this.SetRenderObjectID(length, MyRenderProxy.CreateRenderEntity("Shadow helper", @"Models\Environment\Sky\ShadowHelperSphere.mwm", worldMatrix, MyMeshDrawTechnique.MESH, RenderFlags.CastShadowsOnLow | RenderFlags.SkipInMainView | RenderFlags.NoBackFaceCulling | RenderFlags.DrawOutsideViewDistance | RenderFlags.Visible | RenderFlags.CastShadows, CullingOptions.Default, Color.White, new Vector3(1f, 1f, 1f), 0f, float.MaxValue, 0, 1f, base.FadeIn));
            MyPlanetGeneratorDefinition generator = this.m_planet.Generator;

            if ((MyFakes.ENABLE_PLANETARY_CLOUDS && (generator != null)) && (generator.CloudLayers != null))
            {
                foreach (MyCloudLayerSettings settings in generator.CloudLayers)
                {
                    double   minScaledAltitude = ((double)(this.m_planet.AverageRadius + this.m_planet.MaximumRadius)) / 2.0;
                    double   altitude          = minScaledAltitude + ((this.m_planet.MaximumRadius - minScaledAltitude) * settings.RelativeAltitude);
                    Vector3D rotationAxis      = Vector3D.Normalize((settings.RotationAxis == Vector3D.Zero) ? Vector3D.Up : settings.RotationAxis);
                    int      index             = length + this.m_cloudLayerRenderObjectIndexList.Count;
                    this.SetRenderObjectID(index, MyRenderProxy.CreateRenderEntityCloudLayer((this.m_atmosphereRenderIndex != -1) ? base.m_renderObjectIDs[this.m_atmosphereRenderIndex] : uint.MaxValue, base.Entity.GetFriendlyName() + " " + base.Entity.EntityId.ToString(), settings.Model, settings.Textures, base.Entity.PositionComp.GetPosition(), altitude, minScaledAltitude, settings.ScalingEnabled, (double)settings.FadeOutRelativeAltitudeStart, (double)settings.FadeOutRelativeAltitudeEnd, settings.ApplyFogRelativeDistance, (double)this.m_planet.MaximumRadius, rotationAxis, settings.AngularVelocity, settings.InitialRotation, settings.Color.ToLinearRGB(), base.FadeIn));
                    this.m_cloudLayerRenderObjectIndexList.Add(index);
                }
                length += generator.CloudLayers.Count;
            }
        }
Exemple #2
0
        public override void AddRenderObjects()
        {
            var minCorner = m_planet.PositionLeftBottomCorner;

            m_renderObjectIDs = new uint[16];

            for (int index = 0; index < 16; ++index)
            {
                m_renderObjectIDs[index] = MyRenderProxy.RENDER_ID_UNASSIGNED;
            }

            int runningRenderObjectIndex = 0;

            Debug.Assert((m_planet.Size % MyVoxelCoordSystems.RenderCellSizeInLodVoxels(0)) == Vector3I.Zero);
            var clipmapSizeLod0 = m_planet.Size / MyVoxelCoordSystems.RenderCellSizeInLodVoxels(0);

            Vector3 atmosphereWavelengths = new Vector3();

            atmosphereWavelengths.X = 1.0f / (float)Math.Pow(m_planet.AtmosphereWavelengths.X, 4.0);
            atmosphereWavelengths.Y = 1.0f / (float)Math.Pow(m_planet.AtmosphereWavelengths.Y, 4.0);
            atmosphereWavelengths.Z = 1.0f / (float)Math.Pow(m_planet.AtmosphereWavelengths.Z, 4.0);

            var voxel = (Entity as MyVoxelBase);

            SetRenderObjectID(runningRenderObjectIndex++,
                              MyRenderProxy.CreateClipmap(
                                  MatrixD.CreateTranslation(minCorner),
                                  clipmapSizeLod0,
                                  m_planet.ScaleGroup,
                                  m_planet.PositionComp.GetPosition(),
                                  m_planet.AtmosphereRadius,
                                  m_planet.AverageRadius,
                                  m_planet.HasAtmosphere,
                                  atmosphereWavelengths,
                                  m_planet.SpherizeWithDistance,
                                  RenderFlags.Visible | RenderFlags.DrawOutsideViewDistance | RenderFlags.CastShadows,
                                  IntersectStorage));

            if (m_planet.HasAtmosphere)
            {
                MatrixD matrix = MatrixD.Identity * m_planet.AtmosphereRadius;
                matrix.M44         = 1;
                matrix.Translation = Entity.PositionComp.GetPosition();

                SetRenderObjectID(runningRenderObjectIndex++, MyRenderProxy.CreateRenderEntityAtmosphere(this.Entity.GetFriendlyName() + " " + this.Entity.EntityId.ToString(),
                                                                                                         "Models\\Environment\\Atmosphere_sphere.mwm",
                                                                                                         matrix,
                                                                                                         MyMeshDrawTechnique.ATMOSPHERE,
                                                                                                         RenderFlags.Visible | RenderFlags.DrawOutsideViewDistance,
                                                                                                         GetRenderCullingOptions(),
                                                                                                         m_planet.AtmosphereRadius,
                                                                                                         m_planet.AverageRadius,
                                                                                                         atmosphereWavelengths));

                SetRenderObjectID(runningRenderObjectIndex++, MyRenderProxy.CreateRenderEntityAtmosphere(this.Entity.GetFriendlyName() + " " + this.Entity.EntityId.ToString(),
                                                                                                         "Models\\Environment\\Atmosphere_sphere.mwm",
                                                                                                         matrix,
                                                                                                         MyMeshDrawTechnique.PLANET_SURFACE,
                                                                                                         RenderFlags.Visible | RenderFlags.DrawOutsideViewDistance,
                                                                                                         GetRenderCullingOptions(),
                                                                                                         m_planet.AtmosphereRadius,
                                                                                                         m_planet.AverageRadius,
                                                                                                         atmosphereWavelengths));

                UpdateAtmosphereSettings(m_planet.AtmosphereSettings);
            }

            if (m_renderEnabled == false)
            {
                MyRenderProxy.EnableRenderModule((uint)MyRenderModuleEnum.Atmosphere, true);
                m_renderEnabled = true;
            }

            m_shadowHelperRenderObjectIndex = runningRenderObjectIndex;
            MatrixD shadowHelperWorldMatrix = MatrixD.CreateScale(m_planet.MinimumRadius);

            shadowHelperWorldMatrix.Translation = m_planet.WorldMatrix.Translation;
            SetRenderObjectID(runningRenderObjectIndex++, MyRenderProxy.CreateRenderEntity("Shadow helper", "Models\\Environment\\Sky\\ShadowHelperSphere.mwm",
                                                                                           shadowHelperWorldMatrix,
                                                                                           MyMeshDrawTechnique.MESH,
                                                                                           RenderFlags.Visible | RenderFlags.CastShadows | RenderFlags.DrawOutsideViewDistance | RenderFlags.NoBackFaceCulling | RenderFlags.SkipInMainView,
                                                                                           CullingOptions.Default,
                                                                                           Color.White, new Vector3(1, 1, 1)));

            MyPlanetGeneratorDefinition definition = m_planet.Generator;

            if (!MyFakes.ENABLE_PLANETARY_CLOUDS || definition == null || definition.CloudLayers == null)
            {
                return;
            }

            foreach (var cloudLayer in definition.CloudLayers)
            {
                double   minScaledAltitude = (m_planet.AverageRadius + m_planet.MaximumRadius) / 2.0;
                double   layerAltitude     = minScaledAltitude + (m_planet.MaximumRadius - minScaledAltitude) * cloudLayer.RelativeAltitude;
                Vector3D rotationAxis      = Vector3D.Normalize(cloudLayer.RotationAxis == Vector3D.Zero ? Vector3D.Up : cloudLayer.RotationAxis);

                int index = runningRenderObjectIndex + m_cloudLayerRenderObjectIndexList.Count;
                SetRenderObjectID(index,
                                  MyRenderProxy.CreateRenderEntityCloudLayer(this.Entity.GetFriendlyName() + " " + this.Entity.EntityId.ToString(),
                                                                             cloudLayer.Model,
                                                                             cloudLayer.Textures,
                                                                             Entity.PositionComp.GetPosition(),
                                                                             layerAltitude,
                                                                             minScaledAltitude,
                                                                             cloudLayer.ScalingEnabled,
                                                                             cloudLayer.FadeOutRelativeAltitudeStart,
                                                                             cloudLayer.FadeOutRelativeAltitudeEnd,
                                                                             cloudLayer.ApplyFogRelativeDistance,
                                                                             m_planet.MaximumRadius,
                                                                             MyMeshDrawTechnique.CLOUD_LAYER,
                                                                             RenderFlags.Visible | RenderFlags.DrawOutsideViewDistance,
                                                                             GetRenderCullingOptions(),
                                                                             rotationAxis,
                                                                             cloudLayer.AngularVelocity,
                                                                             cloudLayer.InitialRotation));
                m_cloudLayerRenderObjectIndexList.Add(index);
            }
            runningRenderObjectIndex += definition.CloudLayers.Count;
        }