예제 #1
0
        protected BlockID BlockOn(out float fogDensity, out FastColour fogCol)
        {
            BlockInfo info   = game.BlockInfo;
            Vector3   pos    = game.CurrentCameraPos;
            Vector3I  coords = Vector3I.Floor(pos);

            BlockID block   = game.World.SafeGetBlock(coords);
            AABB    blockBB = new AABB(
                (Vector3)coords + info.MinBB[block],
                (Vector3)coords + info.MaxBB[block]);

            if (blockBB.Contains(pos) && info.FogDensity[block] != 0)
            {
                fogDensity = info.FogDensity[block];
                fogCol     = info.FogColour[block];
            }
            else
            {
                fogDensity = 0;
                // Blend fog and sky together
                float blend = (float)BlendFactor(game.ViewDistance);
                fogCol = FastColour.Lerp(map.Env.FogCol, map.Env.SkyCol, blend);
            }
            return(block);
        }
예제 #2
0
        void UpdateFog()
        {
            if (map.IsNotLoaded)
            {
                return;
            }
            FastColour adjFogCol = FastColour.White;
            BlockInfo  info      = game.BlockInfo;

            Vector3  pos     = game.CurrentCameraPos;
            Vector3I coords  = Vector3I.Floor(pos);
            byte     block   = game.World.SafeGetBlock(coords);
            AABB     blockBB = new AABB(
                (Vector3)coords + info.MinBB[block],
                (Vector3)coords + info.MaxBB[block]);

            if (blockBB.Contains(pos) && info.FogDensity[block] != 0)
            {
                graphics.SetFogMode(Fog.Exp);
                graphics.SetFogDensity(info.FogDensity[block]);
                adjFogCol = info.FogColour[block];
            }
            else
            {
                // Blend fog and sky together
                float blend = (float)BlendFactor(game.ViewDistance);
                adjFogCol = FastColour.Lerp(map.Env.FogCol, map.Env.SkyCol, blend);
                graphics.SetFogMode(Fog.Linear);
                graphics.SetFogEnd(game.ViewDistance);
            }
            graphics.ClearColour(adjFogCol);
            graphics.SetFogColour(adjFogCol);
        }
예제 #3
0
        void UpdateLightmap()
        {
            FastColour sun = game.World.Env.Sunlight, shadow = game.World.Env.Shadowlight;

            FastColour darkShadow = shadow;
            FastColour torchLight = new FastColour(249, 218, 185, 255);

            darkShadow.R >>= 3; darkShadow.G >>= 3; darkShadow.B >>= 3;

            FastColour halfSun  = FastColour.Lerp(shadow, sun, 0.5f);
            FastColour torchSun = new FastColour(Math.Max(torchLight.R, sun.R), Math.Max(torchLight.G, sun.G), Math.Max(torchLight.B, sun.B));

            for (int y = 0; y < lightExtent; y++)
            {
                float lerpY = y / (float)(lightExtent - 1);
                lerpY = 1.0f - (float)Math.Cos(lerpY * Math.PI * 0.5f);

                FastColour lerpShadow    = FastColour.Lerp(darkShadow, torchLight, lerpY);
                FastColour lerpHalfLight = FastColour.Lerp(halfSun, torchLight, lerpY);
                FastColour lerpLight     = FastColour.Lerp(sun, torchLight, lerpY);

                for (int x = 0; x < lightExtent; x++)
                {
                    //1 -cos
                    float lerpX = x / (float)(lightExtent - 1);
                    lerpX = 1.0f - (float)Math.Cos(lerpX * Math.PI * 0.5f);
                    FastColour col = FastColour.Lerp(lerpShadow, lerpHalfLight, lerpX);
                    SetLightmap(x, y, col);
                }
                SetLightmap(15, y, lerpLight);
            }

            Outside        = lightmap[maxLight * lightExtent];
            OutsideXSide   = lightmapXSide[maxLight * lightExtent];
            OutsideZSide   = lightmapZSide[maxLight * lightExtent];
            OutsideYBottom = lightmapYBottom[maxLight * lightExtent];
        }
예제 #4
0
        void ResetFog()
        {
            if (map.IsNotLoaded)
            {
                return;
            }
            FastColour  adjFogCol = FastColour.White;
            BlockInfo   info      = game.BlockInfo;
            BoundingBox pBounds   = game.LocalPlayer.CollisionBounds;

            Vector3I    headCoords = Vector3I.Floor(game.LocalPlayer.EyePosition);
            Vector3     pos        = (Vector3)headCoords;
            byte        headBlock  = game.Map.SafeGetBlock(headCoords);
            BoundingBox blockBB    = new BoundingBox(pos + game.BlockInfo.MinBB[headBlock],
                                                     pos + game.BlockInfo.MaxBB[headBlock]);
            BoundingBox localBB      = game.LocalPlayer.CollisionBounds;
            bool        intersecting = blockBB.Intersects(localBB);

            if (intersecting && info.FogDensity[headBlock] != 0)
            {
                graphics.SetFogMode(Fog.Exp);
                graphics.SetFogDensity(info.FogDensity[headBlock]);
                adjFogCol = info.FogColour[headBlock];
            }
            else
            {
                // Blend fog and sky together
                float blend = (float)BlendFactor(game.ViewDistance);
                adjFogCol = FastColour.Lerp(map.FogCol, map.SkyCol, blend);
                graphics.SetFogMode(Fog.Linear);
                graphics.SetFogStart(0);
                graphics.SetFogEnd(game.ViewDistance);
            }
            graphics.ClearColour(adjFogCol);
            graphics.SetFogColour(adjFogCol);
        }
예제 #5
0
        public void Render(double deltaTime)
        {
            if (vb == -1)
            {
                return;
            }
            LastCelestialAngle = CelestialAngle;
            double x = ((game.Server.Ticks * 1) / 24000.0) - 0.25;

            if (x < 0)
            {
                x += 1;
            }
            CelestialAngle              = x + ((1.0 - (Math.Cos(x * Math.PI) + 1.0) / 2.0) - x) / 3.0;
            game.Graphics.DepthWrite    = false;
            game.Graphics.Texturing     = true;
            game.Graphics.AlphaBlending = true;
            game.Graphics.DisableMipmaps();
            game.Graphics.Fog = false;
            game.Graphics.AlphaBlendFunc(BlendFunc.SourceAlpha, BlendFunc.One);
            game.Graphics.BindTexture(SunTex);
            game.Graphics.SetBatchFormat(VertexFormat.P3fT2fC4b);

            Matrix4 m = Matrix4.Identity, rotY, rotX;

            if (game.Server.DoDayNightCycle)
            {
                float skyMul = (float)(Math.Cos(CelestialAngle * (2 * Math.PI)) * 2 + 0.5);
                Utils.Clamp(ref skyMul, 0, 1);
                FastColour newSkyCol = FastColour.Lerp(nightSkyCol, WorldEnv.DefaultSkyColour, skyMul);
                if (newSkyCol != game.World.Env.SkyCol)
                {
                    game.World.Env.SetSkyColour(newSkyCol);
                }
                FastColour newFogCol = FastColour.Lerp(nightFogCol, WorldEnv.DefaultFogColour, skyMul);
                if (newFogCol != game.World.Env.FogCol)
                {
                    game.World.Env.SetFogColour(newFogCol);
                }
                FastColour newCloudCol = FastColour.Lerp(nightCloudCol, WorldEnv.DefaultCloudsColour, skyMul);
                if (newCloudCol != game.World.Env.CloudsCol)
                {
                    game.World.Env.SetCloudsColour(newCloudCol);
                }
                byte SunLightSub = CalcSunLightSub();
                if (SunLightSub != game.Lighting.sunLightSub)
                {
                    game.Lighting.sunLightSub = SunLightSub;
                    game.MapRenderer.Refresh();
                    game.MapBordersRenderer.ResetEdges();
                }
            }

            // Base skybox rotation
            float    rotTime = (float)(game.accumulator * 2 * Math.PI);          // So speed of 1 rotates whole skybox every second
            WorldEnv env     = game.World.Env;

            //Matrix4.RotateY(out rotY, env.SkyboxHorSpeed * rotTime);
            //Matrix4.Mult(out m, ref m, ref rotY);
            Matrix4.RotateX(out rotX, (float)(360d * CelestialAngle) * Utils.Deg2Rad + 90f * Utils.Deg2Rad);
            Matrix4.Mult(out m, ref m, ref rotX);


            // Rotate around camera
            Vector2 rotation = game.Camera.GetCameraOrientation();

            Matrix4.RotateY(out rotY, rotation.X);             // Camera yaw
            Matrix4.Mult(out m, ref m, ref rotY);
            Matrix4.RotateX(out rotX, rotation.Y);             // Cammera pitch
            Matrix4.Mult(out m, ref m, ref rotX);
            Matrix4.Mult(out m, ref m, ref game.Camera.tiltM);

            game.Graphics.LoadMatrix(ref m);
            game.Graphics.BindVb(vb);
            game.Graphics.DrawVb_IndexedTris(sunCount);

            game.Graphics.BindTexture(MoonTex);

            m = Matrix4.Identity;
            Matrix4.RotateX(out rotX, (float)(360d * CelestialAngle) * Utils.Deg2Rad + 90f * Utils.Deg2Rad);
            Matrix4.Mult(out m, ref m, ref rotX);


            // Rotate around camera
            rotation = game.Camera.GetCameraOrientation();
            Matrix4.RotateY(out rotY, rotation.X);             // Camera yaw
            Matrix4.Mult(out m, ref m, ref rotY);
            Matrix4.RotateX(out rotX, rotation.Y);             // Cammera pitch
            Matrix4.Mult(out m, ref m, ref rotX);
            Matrix4.Mult(out m, ref m, ref game.Camera.tiltM);

            game.Graphics.LoadMatrix(ref m);
            game.Graphics.BindVb(vb);
            game.Graphics.DrawVb_IndexedTris(moonCount, sunCount);

            /*game.Graphics.AlphaBlendFunc(BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha);
             * //game.Graphics.AlphaBlending = false;
             *
             * game.Graphics.BindTexture(0);
             *
             * m = Matrix4.Identity;
             * Matrix4.RotateX(out rotX, (float)(360d * CelestialAngle) * Utils.Deg2Rad + 90f * Utils.Deg2Rad);
             * Matrix4.Mult(out m, ref m, ref rotX);
             *
             *
             * // Rotate around camera
             * rotation = game.Camera.GetCameraOrientation();
             * Matrix4.RotateY(out rotY, rotation.X); // Camera yaw
             * Matrix4.Mult(out m, ref m, ref rotY);
             * Matrix4.RotateX(out rotX, rotation.Y); // Cammera pitch
             * Matrix4.Mult(out m, ref m, ref rotX);
             * Matrix4.Mult(out m, ref m, ref game.Camera.tiltM);
             *
             * game.Graphics.LoadMatrix(ref m);
             * game.Graphics.BindVb(vb);
             * game.Graphics.DrawVb_IndexedTris(starCount, (sunCount + moonCount));*/

            game.Graphics.Fog = true;
            game.Graphics.AlphaBlendFunc(BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha);
            game.Graphics.AlphaBlending = false;
            game.Graphics.Texturing     = false;
            game.Graphics.LoadMatrix(ref game.Graphics.View);
            game.Graphics.DepthWrite = true;
        }