Beispiel #1
0
        public void Dispose()
        {
            CloudsPlane?.MarkForDisposal();
            SkyPlane?.MarkForDisposal();
            CelestialPlane?.MarkForDisposal();
            MoonPlane?.MarkForDisposal();
            SunTexture?.MarkForDisposal();
            MoonTexture?.MarkForDisposal();
            CloudTexture?.MarkForDisposal();

            SkyPlaneEffect?.Dispose();
            CelestialPlaneEffect?.Dispose();
            CloudsPlaneEffect?.Dispose();
        }
Beispiel #2
0
        public SkyBox(IServiceProvider serviceProvider, GraphicsDevice device, World world)
        {
            World = world;
            //Game = alex;
            var alex = serviceProvider.GetRequiredService <Alex>();

            OptionsProvider = serviceProvider.GetRequiredService <IOptionsProvider>();

            if (alex.Resources.ResourcePack.TryGetBitmap("environment/sun", out var sun))
            {
                SunTexture = TextureUtils.BitmapToTexture2D(device, sun);
            }
            else
            {
                CanRender = false;
                return;
            }

            if (alex.Resources.ResourcePack.TryGetBitmap("environment/moon_phases", out var moonPhases))
            {
                MoonTexture = TextureUtils.BitmapToTexture2D(device, moonPhases);
            }
            else
            {
                CanRender = false;
                return;
            }

            if (alex.Resources.ResourcePack.TryGetBitmap("environment/clouds", out var cloudTexture))
            {
                CloudTexture = TextureUtils.BitmapToTexture2D(device, cloudTexture);
                EnableClouds = false;
            }
            else
            {
                EnableClouds = false;
            }

            //var d = 144;

            CelestialPlaneEffect = new BasicEffect(device);
            CelestialPlaneEffect.VertexColorEnabled = false;
            CelestialPlaneEffect.LightingEnabled    = false;
            CelestialPlaneEffect.TextureEnabled     = true;

            SkyPlaneEffect = new BasicEffect(device);
            SkyPlaneEffect.VertexColorEnabled = false;
            SkyPlaneEffect.FogEnabled         = true;
            SkyPlaneEffect.FogStart           = 0;
            SkyPlaneEffect.FogEnd             = 64 * 0.8f;
            SkyPlaneEffect.LightingEnabled    = true;

            var planeDistance = 64;
            var plane         = new[]
            {
                new VertexPositionColor(new Vector3(-planeDistance, 0, -planeDistance), Color.White),
                new VertexPositionColor(new Vector3(planeDistance, 0, -planeDistance), Color.White),
                new VertexPositionColor(new Vector3(-planeDistance, 0, planeDistance), Color.White),

                new VertexPositionColor(new Vector3(planeDistance, 0, -planeDistance), Color.White),
                new VertexPositionColor(new Vector3(planeDistance, 0, planeDistance), Color.White),
                new VertexPositionColor(new Vector3(-planeDistance, 0, planeDistance), Color.White)
            };

            SkyPlane = GpuResourceManager.GetBuffer(this, device, VertexPositionColor.VertexDeclaration,
                                                    plane.Length, BufferUsage.WriteOnly);
            SkyPlane.SetData <VertexPositionColor>(plane);

            planeDistance = 60;
            var celestialPlane = new[]
            {
                new VertexPositionTexture(new Vector3(-planeDistance, 0, -planeDistance), new Vector2(0, 0)),
                new VertexPositionTexture(new Vector3(planeDistance, 0, -planeDistance), new Vector2(1, 0)),
                new VertexPositionTexture(new Vector3(-planeDistance, 0, planeDistance), new Vector2(0, 1)),

                new VertexPositionTexture(new Vector3(planeDistance, 0, -planeDistance), new Vector2(1, 0)),
                new VertexPositionTexture(new Vector3(planeDistance, 0, planeDistance), new Vector2(1, 1)),
                new VertexPositionTexture(new Vector3(-planeDistance, 0, planeDistance), new Vector2(0, 1))
            };

            CelestialPlane = GpuResourceManager.GetBuffer(this, device, VertexPositionTexture.VertexDeclaration,
                                                          celestialPlane.Length, BufferUsage.WriteOnly);
            CelestialPlane.SetData <VertexPositionTexture>(celestialPlane);

            _moonPlaneVertices = new[]
            {
                new VertexPositionTexture(new Vector3(-planeDistance, 0, -planeDistance), new Vector2(0, 0)),
                new VertexPositionTexture(new Vector3(planeDistance, 0, -planeDistance), new Vector2(MoonX, 0)),
                new VertexPositionTexture(new Vector3(-planeDistance, 0, planeDistance), new Vector2(0, MoonY)),

                new VertexPositionTexture(new Vector3(planeDistance, 0, -planeDistance), new Vector2(MoonX, 0)),
                new VertexPositionTexture(new Vector3(planeDistance, 0, planeDistance), new Vector2(MoonX, MoonY)),
                new VertexPositionTexture(new Vector3(-planeDistance, 0, planeDistance), new Vector2(0, MoonY)),
            };
            MoonPlane = GpuResourceManager.GetBuffer(this, device, VertexPositionTexture.VertexDeclaration,
                                                     _moonPlaneVertices.Length, BufferUsage.WriteOnly);
            MoonPlane.SetData <VertexPositionTexture>(_moonPlaneVertices);

            if (EnableClouds)
            {
                SetupClouds(device, planeDistance);
            }

            RenderSkybox = Options.VideoOptions.Skybox.Value;
            Options.VideoOptions.Skybox.Bind(SkyboxSettingUpdated);
        }
Beispiel #3
0
        public SkyBox(Alex alex, GraphicsDevice device, World world)
        {
            World           = world;
            Game            = alex;
            OptionsProvider = alex.Services.GetService <IOptionsProvider>();

            if (alex.Resources.ResourcePack.TryGetTexture("environment/sun", out Texture2D sun))
            {
                SunTexture = sun;
            }
            else
            {
                CanRender = false;
                return;
            }

            if (alex.Resources.ResourcePack.TryGetTexture("environment/moon_phases", out Texture2D moonPhases))
            {
                MoonTexture = moonPhases;
            }
            else
            {
                CanRender = false;
                return;
            }

            if (alex.Resources.ResourcePack.TryGetTexture("environment/clouds", out Texture2D cloudTexture))
            {
                CloudTexture = cloudTexture;
                EnableClouds = false;
            }
            else
            {
                EnableClouds = false;
            }

            var d = Options.VideoOptions.RenderDistance ^ 2;

            CelestialPlaneEffect = new BasicEffect(device);
            CelestialPlaneEffect.TextureEnabled = true;

            SkyPlaneEffect = new BasicEffect(device);
            SkyPlaneEffect.VertexColorEnabled = false;
            SkyPlaneEffect.FogEnabled         = true;
            SkyPlaneEffect.FogStart           = 0;
            SkyPlaneEffect.FogEnd             = d * 0.8f;
            SkyPlaneEffect.LightingEnabled    = true;

            var planeDistance = d * 3;
            var plane         = new[]
            {
                new VertexPositionColor(new Vector3(-planeDistance, 0, -planeDistance), Color.White),
                new VertexPositionColor(new Vector3(planeDistance, 0, -planeDistance), Color.White),
                new VertexPositionColor(new Vector3(-planeDistance, 0, planeDistance), Color.White),

                new VertexPositionColor(new Vector3(planeDistance, 0, -planeDistance), Color.White),
                new VertexPositionColor(new Vector3(planeDistance, 0, planeDistance), Color.White),
                new VertexPositionColor(new Vector3(-planeDistance, 0, planeDistance), Color.White)
            };

            SkyPlane = GpuResourceManager.GetBuffer(this, device, VertexPositionColor.VertexDeclaration,
                                                    plane.Length, BufferUsage.WriteOnly);
            SkyPlane.SetData <VertexPositionColor>(plane);

            var celestialPlane = new[]
            {
                new VertexPositionTexture(new Vector3(-planeDistance, 0, -planeDistance), new Vector2(0, 0)),
                new VertexPositionTexture(new Vector3(planeDistance, 0, -planeDistance), new Vector2(1, 0)),
                new VertexPositionTexture(new Vector3(-planeDistance, 0, planeDistance), new Vector2(0, 1)),

                new VertexPositionTexture(new Vector3(planeDistance, 0, -planeDistance), new Vector2(1, 0)),
                new VertexPositionTexture(new Vector3(planeDistance, 0, planeDistance), new Vector2(1, 1)),
                new VertexPositionTexture(new Vector3(-planeDistance, 0, planeDistance), new Vector2(0, 1))
            };

            CelestialPlane = GpuResourceManager.GetBuffer(this, device, VertexPositionTexture.VertexDeclaration,
                                                          celestialPlane.Length, BufferUsage.WriteOnly);
            CelestialPlane.SetData <VertexPositionTexture>(celestialPlane);

            _moonPlaneVertices = new[]
            {
                new VertexPositionTexture(new Vector3(-planeDistance, 0, -planeDistance), new Vector2(0, 0)),
                new VertexPositionTexture(new Vector3(planeDistance, 0, -planeDistance), new Vector2(MoonX, 0)),
                new VertexPositionTexture(new Vector3(-planeDistance, 0, planeDistance), new Vector2(0, MoonY)),

                new VertexPositionTexture(new Vector3(planeDistance, 0, -planeDistance), new Vector2(MoonX, 0)),
                new VertexPositionTexture(new Vector3(planeDistance, 0, planeDistance), new Vector2(MoonX, MoonY)),
                new VertexPositionTexture(new Vector3(-planeDistance, 0, planeDistance), new Vector2(0, MoonY)),
            };
            MoonPlane = GpuResourceManager.GetBuffer(this, device, VertexPositionTexture.VertexDeclaration,
                                                     _moonPlaneVertices.Length, BufferUsage.WriteOnly);
            MoonPlane.SetData <VertexPositionTexture>(_moonPlaneVertices);

            if (EnableClouds)
            {
                SetupClouds(device, planeDistance);
            }
        }