예제 #1
0
파일: SkyBox.cs 프로젝트: j717273419/Alex
        public void Update(IUpdateArgs args)
        {
            var moonPhase = (int)(World.WorldInfo.Time / 24000L % 8L + 8L) % 8;

            if (CurrentMoonPhase != moonPhase)
            {
                CurrentMoonPhase = moonPhase;

                var w = (1f / MoonTexture.Width) * (MoonTexture.Width / 4f);
                var h = (1f / MoonTexture.Height) * (MoonTexture.Height / 2f);

                int x = moonPhase % 4;
                int y = moonPhase % 2;

                float textureX = (w * x);
                float textureY = (h * y);

                float textureXMax = (w * x) + w;
                float textureYMax = (h * y) + h;

                _moonPlaneVertices[0].TextureCoordinate = new Vector2(textureX, textureY);
                _moonPlaneVertices[1].TextureCoordinate = new Vector2(textureXMax, textureY);
                _moonPlaneVertices[2].TextureCoordinate = new Vector2(textureX, textureYMax);

                _moonPlaneVertices[3].TextureCoordinate = new Vector2(textureXMax, textureY);
                _moonPlaneVertices[4].TextureCoordinate = new Vector2(textureXMax, textureYMax);
                _moonPlaneVertices[5].TextureCoordinate = new Vector2(textureX, textureYMax);

                var modified = _moonPlaneVertices.Select(x => x.TextureCoordinate).ToArray();
                MoonPlane.SetData(12, modified, 0, modified.Length, MoonPlane.VertexDeclaration.VertexStride);
            }
        }
예제 #2
0
        public void Update(IUpdateArgs args)
        {
            if (!RenderSkybox)
            {
                return;
            }

            var moonPhase = (int)(World.Time / 24000L % 8L + 8L) % 8;

            if (CurrentMoonPhase != moonPhase)
            {
                CurrentMoonPhase = moonPhase;

                var w = (1f / MoonTexture.Width) * (MoonTexture.Width / 4f);
                var h = (1f / MoonTexture.Height) * (MoonTexture.Height / 2f);

                int x = moonPhase % 4;
                int y = moonPhase % 2;

                float textureX = (w * x);
                float textureY = (h * y);

                float textureXMax = (w * x) + w;
                float textureYMax = (h * y) + h;

                _moonPlaneVertices[0].TextureCoordinate = new Vector2(textureX, textureY);
                _moonPlaneVertices[1].TextureCoordinate = new Vector2(textureXMax, textureY);
                _moonPlaneVertices[2].TextureCoordinate = new Vector2(textureX, textureYMax);

                _moonPlaneVertices[3].TextureCoordinate = new Vector2(textureXMax, textureY);
                _moonPlaneVertices[4].TextureCoordinate = new Vector2(textureXMax, textureYMax);
                _moonPlaneVertices[5].TextureCoordinate = new Vector2(textureX, textureYMax);

                var modified = _moonPlaneVertices.Select(xx => xx.TextureCoordinate).ToArray();
                MoonPlane.SetData(12, modified, 0, modified.Length, MoonPlane.VertexDeclaration.VertexStride);
            }

            var camera = args.Camera;

            SkyPlaneEffect.View       = camera.ViewMatrix;
            SkyPlaneEffect.Projection = camera.ProjectionMatrix;

            CelestialPlaneEffect.View       = camera.ViewMatrix;
            CelestialPlaneEffect.Projection = camera.ProjectionMatrix;

            var position = camera.Position;

            if (EnableClouds)
            {
                CloudsPlaneEffect.View       = camera.ViewMatrix;
                CloudsPlaneEffect.Projection = camera.ProjectionMatrix;

                CloudsPlaneEffect.World = Matrix.CreateTranslation(position.X, 127, position.Z);
            }
        }
예제 #3
0
        public void Dispose()
        {
            CloudsPlane?.MarkForDisposal();
            SkyPlane?.MarkForDisposal();
            CelestialPlane?.MarkForDisposal();
            MoonPlane?.MarkForDisposal();
            SunTexture?.MarkForDisposal();
            MoonTexture?.MarkForDisposal();
            CloudTexture?.MarkForDisposal();

            SkyPlaneEffect?.Dispose();
            CelestialPlaneEffect?.Dispose();
            CloudsPlaneEffect?.Dispose();
        }
예제 #4
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);
        }
예제 #5
0
파일: SkyBox.cs 프로젝트: wqd1019dqw/Alex
        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);
            }
        }