예제 #1
0
        /// <summary> Renders all opaque and transparent blocks. </summary>
        /// <remarks> Pixels are either treated as fully replacing existing pixel, or skipped. </remarks>
        public void RenderNormal(double deltaTime)
        {
            if (chunks == null)
            {
                return;
            }

            int[] texIds = game.TerrainAtlas1D.TexIds;
            gfx.SetBatchFormat(VertexFormat.P3fT2fC4b);
            gfx.Texturing = true;
            gfx.AlphaTest = true;

            gfx.EnableMipmaps();
            for (int batch = 0; batch < _1DUsed; batch++)
            {
                if (normalPartsCount[batch] <= 0)
                {
                    continue;
                }
                if (pendingNormal[batch] || usedNormal[batch])
                {
                    gfx.BindTexture(texIds[batch]);
                    RenderNormalBatch(batch);
                    pendingNormal[batch] = false;
                }
            }
            gfx.DisableMipmaps();

            CheckWeather(deltaTime);
            gfx.AlphaTest = false;
            gfx.Texturing = false;
                        #if DEBUG_OCCLUSION
            DebugPickedPos();
                        #endif
        }
예제 #2
0
        public void RenderSides(double delta)
        {
            if (sidesVb == -1)
            {
                return;
            }
            BlockID block = game.World.Env.SidesBlock;

            gfx.Texturing = true;
            gfx.SetupAlphaState(BlockInfo.Draw[block]);
            gfx.EnableMipmaps();

            gfx.BindTexture(sideTexId);
            gfx.SetBatchFormat(VertexFormat.P3fT2fC4b);
            gfx.BindVb(sidesVb);
            gfx.DrawVb_IndexedTris(sidesVertices);

            gfx.DisableMipmaps();
            gfx.RestoreAlphaState(BlockInfo.Draw[block]);
            gfx.Texturing = false;
        }
        void RenderBorders(BlockID block, int vb, int tex, int count)
        {
            if (vb == 0)
            {
                return;
            }
            IGraphicsApi gfx = game.Graphics;

            gfx.Texturing = true;
            gfx.SetupAlphaState(BlockInfo.Draw[block]);
            gfx.EnableMipmaps();

            gfx.BindTexture(tex);
            gfx.SetBatchFormat(VertexFormat.P3fT2fC4b);
            gfx.BindVb(vb);
            if (count > 0)
            {
                gfx.DrawVb_IndexedTris(count);
            }

            gfx.DisableMipmaps();
            gfx.RestoreAlphaState(BlockInfo.Draw[block]);
            gfx.Texturing = false;
        }
        /// <summary> Renders all translucent (e.g. water) blocks. </summary>
        /// <remarks> Pixels drawn blend into existing geometry. </remarks>
        public void RenderTranslucent(double deltaTime)
        {
            if (chunks == null)
            {
                return;
            }
            IGraphicsApi gfx = game.Graphics;

            // First fill depth buffer
            int vertices = game.Vertices;

            gfx.SetBatchFormat(VertexFormat.P3fT2fC4b);
            gfx.Texturing     = false;
            gfx.AlphaBlending = false;
            gfx.ColourWriteMask(false, false, false, false);
            for (int batch = 0; batch < _1DUsed; batch++)
            {
                if (translucentPartsCount[batch] <= 0)
                {
                    continue;
                }
                if (pendingTranslucent[batch] || usedTranslucent[batch])
                {
                    RenderTranslucentBatch(batch);
                    pendingTranslucent[batch] = false;
                }
            }
            game.Vertices = vertices;

            // Then actually draw the transluscent blocks
            gfx.AlphaBlending = true;
            gfx.Texturing     = true;
            gfx.ColourWriteMask(true, true, true, true);
            gfx.DepthWrite = false;             // we already calculated depth values in depth pass

            int[] texIds = TerrainAtlas1D.TexIds;
            gfx.EnableMipmaps();
            for (int batch = 0; batch < _1DUsed; batch++)
            {
                if (translucentPartsCount[batch] <= 0)
                {
                    continue;
                }
                if (!usedTranslucent[batch])
                {
                    continue;
                }
                gfx.BindTexture(texIds[batch]);
                RenderTranslucentBatch(batch);
            }
            gfx.DisableMipmaps();

            gfx.DepthWrite = true;
            // If we weren't under water, render weather after to blend properly
            if (!inTranslucent && game.World.Env.Weather != Weather.Sunny)
            {
                gfx.AlphaTest = true;
                game.WeatherRenderer.Render(deltaTime);
                gfx.AlphaTest = false;
            }
            gfx.AlphaBlending = false;
            gfx.Texturing     = false;
        }