Ejemplo n.º 1
0
        public static void Draw()
        {
            if (MyRender.GetCurrentLodDrawPass() == MyLodTypeEnum.LOD0)
            {
                MyStateObjects.DepthStencil_TestFarObject_DepthReadOnly.Apply();
                MyStateObjects.Dynamic_Decals_BlendState.Apply();
                MyStateObjects.BiasedRasterizer_Decals.Apply();

                Effects.MyEffectDecals effect = (Effects.MyEffectDecals)MyRender.GetEffect(MyEffects.Decals);

                //  Draw voxel decals
                m_decalsForVoxels.Draw(m_vertices, effect, m_texturesDiffuse, m_texturesNormalMap);

                //  Draw model decals
                m_decalsForModels.Draw(m_vertices, effect, m_texturesDiffuse, m_texturesNormalMap);
            }
        }
Ejemplo n.º 2
0
        public void Draw(MyVertexFormatDecal[] vertices, Effects.MyEffectDecals effect, MyTexture2D[] texturesDiffuse, MyTexture2D[] texturesNormalMap)
        {
            CheckIfBufferIsFull();

            //  Sort buffers by texture
            m_sortTriangleBuffersByTexture.Clear();
            foreach (MyDecalsForVoxelsTriangleBuffer buffer in m_usedTriangleBuffers)
            {
                //  Check if render cell is close enought and visible in the view frustum
                if (//(buffer.VoxelMap.GetSmallestDistanceFromCameraToRenderCell(ref buffer.RenderCellCoord) <= (MyDecals.GetMaxDistanceForDrawingDecals())) &&
                    (MyCamera.IsInFrustum(ref buffer.RenderCellBoundingBox) == true))
                {
                    float fadeoutDistance = MyDecals.GetMaxDistanceForDrawingDecals();
                    if (buffer.DecalTexture == MyDecalTexturesEnum.ExplosionSmut)
                    {
                        fadeoutDistance *= MyDecalsConstants.DISTANCE_MULTIPLIER_FOR_LARGE_DECALS;
                    }

                    if (buffer.VoxelMap.GetSmallestDistanceFromCameraToRenderCell(ref buffer.RenderCellCoord) <= fadeoutDistance)
                    {
                        m_sortTriangleBuffersByTexture.Add(buffer);
                    }
                }
            }
            m_sortTriangleBuffersByTexture.Sort();

            if (m_sortTriangleBuffersByTexture.Count <= 0)
            {
                return;
            }

            //  Draw decals - sorted by texture
            MyDecalTexturesEnum?lastDecalTexture = null;

            for (int i = 0; i < m_sortTriangleBuffersByTexture.Count; i++)
            {
                MyDecalsForVoxelsTriangleBuffer buffer = m_sortTriangleBuffersByTexture[i];

                int trianglesCount = buffer.CopyDecalsToVertexBuffer(vertices);

                if (trianglesCount <= 0)
                {
                    continue;
                }

                //  Switch texture only if different than previous one
                if ((lastDecalTexture == null) || (lastDecalTexture != buffer.DecalTexture))
                {
                    int textureIndex = (int)buffer.DecalTexture;
                    effect.SetDecalDiffuseTexture(texturesDiffuse[textureIndex]);
                    effect.SetDecalNormalMapTexture(texturesNormalMap[textureIndex]);
                    lastDecalTexture = buffer.DecalTexture;
                }

                //  This will move all voxel maps back to position [0,0,0]
                effect.SetVoxelMapPosition(buffer.VoxelMap.PositionLeftBottomCorner - MyCamera.Position);

                effect.SetViewProjectionMatrix(MyCamera.ViewProjectionMatrixAtZero);

                // Set fadeout distance
                float fadeoutDistance = MyDecals.GetMaxDistanceForDrawingDecals();
                if (buffer.DecalTexture == MyDecalTexturesEnum.ExplosionSmut)
                {
                    fadeoutDistance *= MyDecalsConstants.DISTANCE_MULTIPLIER_FOR_LARGE_DECALS;
                }

                effect.SetFadeoutDistance(fadeoutDistance);

                if (!MyRenderConstants.RenderQualityProfile.ForwardRender)
                {
                    effect.SetTechnique(Effects.MyEffectDecals.Technique.Voxels);
                }
                else
                {
                    effect.SetTechnique(Effects.MyEffectDecals.Technique.VoxelsForward);
                }

                MyMinerGame.Static.GraphicsDevice.VertexDeclaration = MyVertexFormatDecal.VertexDeclaration;

                effect.Begin();
                MyMinerGame.Static.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, 0, trianglesCount, vertices);
                effect.End();

                MyPerformanceCounter.PerCameraDraw.DecalsForVoxelsInFrustum += trianglesCount;
            }
        }