示例#1
0
        static MyRender()
        {
            //Initialize post processes
            m_postProcesses.Add(new MyPostProcessHDR());
            m_postProcesses.Add(new MyPostProcessAntiAlias());
            m_postProcesses.Add(new MyPostProcessVolumetricSSAO2());
            //m_postProcesses.Add(new MyPostProcessContrast());
            m_postProcesses.Add(new MyPostProcessVolumetricFog());

            m_postProcesses.Add(new MyPostProcessGodRays());

            //Initialize for event registration
            for (int i = 0; i < Enum.GetValues(typeof(MyRenderStage)).GetLength(0); i++)
            {
                m_renderModules[i] = new List <MyRenderModuleItem>();
            }

            for (int i = 0; i < MyRenderConstants.MAX_RENDER_ELEMENTS_COUNT; i++)
            {
                m_renderElementsPool[i] = new MyRenderElement();
            }

            m_sun.Start();

            //m_prepareEntitiesEvent = new AutoResetEvent(false);
            //Task.Factory.StartNew(PrepareEntitiesForDrawBackground, TaskCreationOptions.PreferFairness);

            MyRender.RegisterRenderModule(MyRenderModuleEnum.PrunningStructure, "Prunning structure", DebugDrawPrunning, MyRenderStage.DebugDraw, 250, false);
            MyRender.RegisterRenderModule(MyRenderModuleEnum.PhysicsPrunningStructure, "Physics prunning structure", MyPhysics.DebugDrawPhysicsPrunning, MyRenderStage.DebugDraw, 250, false);

            MyRenderConstants.OnRenderQualityChange += new EventHandler(MyRenderConstants_OnRenderQualityChange);
        }
示例#2
0
        static MyRender()
        {
            const string logName = "VRageRender.log";

            Log.Init(logName, new System.Text.StringBuilder("Version unknown"));
            Log.WriteLine("VRage renderer started");

            RegisterPostProcesses();

            //Initialize for event registration
            for (int i = 0; i < Enum.GetValues(typeof(MyRenderStage)).GetLength(0); i++)
            {
                m_renderModules[i] = new List <MyRenderModuleItem>();
            }

            for (int i = 0; i < MyRenderConstants.MAX_RENDER_ELEMENTS_COUNT; i++)
            {
                m_renderElementsPool[i] = new MyRenderElement();
            }

            RegisterComponents();

            m_sun.Start();

            InitDrawTechniques();

            //m_prepareEntitiesEvent = new AutoResetEvent(false);
            //Task.Factory.StartNew(PrepareEntitiesForDrawBackground, TaskCreationOptions.PreferFairness);

            MyRender.RegisterRenderModule(MyRenderModuleEnum.PrunningStructure, "Prunning structure", DebugDrawPrunning, MyRenderStage.DebugDraw, 250, false);
            MyRender.RegisterRenderModule(MyRenderModuleEnum.Atmosphere, "Draw atmosphere", DrawAtmosphere, MyRenderStage.AlphaBlendPreHDR, 1, false);
            //MyRender.RegisterRenderModule(MyRenderModuleEnum.PhysicsPrunningStructure, "Physics prunning structure", MyPhysics.DebugDrawPhysicsPrunning, MyRenderStage.DebugDraw, 250, false);

            MyRenderConstants.OnRenderQualityChange += new EventHandler(MyRenderConstants_OnRenderQualityChange);
        }
        static MyRender()
        {
            const string logName = "VRageRender.log";
            Log.Init(logName, new System.Text.StringBuilder("Version unknown"));
            Log.WriteLine("VRage renderer started");

            RegisterPostProcesses();

            //Initialize for event registration
            for (int i = 0; i < Enum.GetValues(typeof(MyRenderStage)).GetLength(0); i++)
            {
                m_renderModules[i] = new List<MyRenderModuleItem>();
            }

            for (int i = 0; i < MyRenderConstants.MAX_RENDER_ELEMENTS_COUNT; i++)
            {
                m_renderElementsPool[i] = new MyRenderElement();
            }

            RegisterComponents();

            m_sun.Start();

            InitDrawTechniques();

            //m_prepareEntitiesEvent = new AutoResetEvent(false);
            //Task.Factory.StartNew(PrepareEntitiesForDrawBackground, TaskCreationOptions.PreferFairness);

            MyRender.RegisterRenderModule(MyRenderModuleEnum.PrunningStructure, "Prunning structure", DebugDrawPrunning, MyRenderStage.DebugDraw, 250, false);
            MyRender.RegisterRenderModule(MyRenderModuleEnum.Atmosphere, "Draw atmosphere", DrawAtmosphere, MyRenderStage.AlphaBlendPreHDR, 1, false);
            //MyRender.RegisterRenderModule(MyRenderModuleEnum.PhysicsPrunningStructure, "Physics prunning structure", MyPhysics.DebugDrawPhysicsPrunning, MyRenderStage.DebugDraw, 250, false);

            MyRenderConstants.OnRenderQualityChange += new EventHandler(MyRenderConstants_OnRenderQualityChange);
        }
示例#4
0
 internal static void AllocateRenderElement(out MyRenderElement renderElement)
 {
     lock (m_renderElementsPool)
     {
         renderElement = m_renderElementCounter >= MyRenderConstants.MAX_RENDER_ELEMENTS_COUNT ? null : m_renderElementsPool[m_renderElementIndex++ % MyRenderConstants.MAX_RENDER_ELEMENTS_COUNT];
         m_renderElementCounter++;
     }            
     IsRenderOverloaded = m_renderElementCounter >= (MyRenderConstants.MAX_RENDER_ELEMENTS_COUNT - 4096);
 }
示例#5
0
 private static void BeginShader(MyEffectBase shader, ref MyRenderElement renderElement)
 {
     switch (renderElement.DrawTechnique)
     {
         case MyMeshDrawTechnique.DECAL:
             {
                 if (shader is MyEffectModelsDNS)
                 {
                     (shader as MyEffectModelsDNS).BeginBlended();
                 }
             }
             break;
         case MyMeshDrawTechnique.HOLO:
             {
                 if (m_currentLodDrawPass != MyLodTypeEnum.LOD_NEAR && !MyRenderConstants.RenderQualityProfile.ForwardRender)
                 {
                     (shader as MyEffectModelsDNS).ApplyHolo(false);
                 }
                 else
                 {
                     (shader as MyEffectModelsDNS).ApplyHolo(true);
                 }
             }
             break;
         case MyMeshDrawTechnique.ALPHA_MASKED:
             {
                 (shader as MyEffectModelsDNS).ApplyMasked();
             }
             break;
         case MyMeshDrawTechnique.VOXEL_MAP:
             {
                 MyEffectVoxels effectVoxels = shader as MyEffectVoxels;
                 if (renderElement.VoxelBatch.Type == MyVoxelCacheCellRenderBatchType.SINGLE_MATERIAL)
                 {
                     effectVoxels.Apply();
                 }
                 else if (renderElement.VoxelBatch.Type == MyVoxelCacheCellRenderBatchType.MULTI_MATERIAL)
                 {
                     effectVoxels.ApplyMultimaterial();
                 }
                 break;
             }
         case MyMeshDrawTechnique.VOXELS_STATIC_ASTEROID:
             {
                 ((MyEffectVoxelsStaticAsteroid)shader).Apply();
             }
             break;
         case MyMeshDrawTechnique.MESH:
             {
                 ((MyEffectModelsDNS)shader).SetTechnique(MyRenderConstants.RenderQualityProfile.ModelsRenderTechnique);
             }
             break;
         case MyMeshDrawTechnique.VOXELS_DEBRIS:
             {
                 ((MyEffectVoxelsDebris)shader).SetTechnique(MyRenderConstants.RenderQualityProfile.VoxelsRenderTechnique);
             }
             break;
         default:
             {
                 System.Diagnostics.Debug.Assert(false);
             }
             break;
     }
 }
示例#6
0
        private static void PrepareDeviceForRender(ref ShaderContext shaderContext, ref MyRenderElement renderElement)
        {
            //    m_renderProfiler.StartProfilingBlock("PrepareDeviceForRender");

            int lod = (int)m_currentLodDrawPass;

            System.Diagnostics.Debug.Assert(renderElement.Entity != null);

            bool needBegin = false;

            //Material change
            bool voxelMaterialChanged = shaderContext.CurrentVoxelBatch == null && renderElement.VoxelBatch != null;
            bool voxelTechniqueChanged = false;
            
            if (renderElement.VoxelBatch != null && shaderContext.CurrentVoxelBatch != null) 
            {
                voxelMaterialChanged = renderElement.VoxelBatch.SortOrder != shaderContext.CurrentVoxelBatch.SortOrder;
                voxelTechniqueChanged = renderElement.VoxelBatch.Type != shaderContext.CurrentVoxelBatch.Type;
            }
            if ((shaderContext.CurrentMaterial.GetHashCode() != renderElement.Material.GetHashCode())
                || voxelMaterialChanged || voxelTechniqueChanged)
            {
                MyPerformanceCounter.PerCameraDraw.MaterialChanges[lod]++;
                shaderContext.CurrentMaterial = renderElement.Material;
                shaderContext.CurrentVoxelBatch = renderElement.VoxelBatch;

                MyEffectBase oldShader = shaderContext.CurrentShader;
                shaderContext.CurrentShader = MyRender.SetupShaderForMaterial(renderElement.Material, renderElement.VoxelBatch);

                if (shaderContext.CurrentDrawTechnique != (byte)renderElement.DrawTechnique || voxelTechniqueChanged)
                {
                    if (oldShader != null)
                        oldShader.End();
                    
                    needBegin = true;
                    
                    MyPerformanceCounter.PerCameraDraw.TechniqueChanges[lod]++;

                    shaderContext.CurrentDrawTechnique = (byte)renderElement.DrawTechnique;

                    MyRender.SetupShaderPerDraw(shaderContext.CurrentShader, renderElement.DrawTechnique);
                }
            }

            //VB change
            if (!object.ReferenceEquals(shaderContext.CurrentVertexBuffer, renderElement.VertexBuffer))
            {
                MyPerformanceCounter.PerCameraDraw.VertexBufferChanges[lod]++;

                //Now we have IB+VB 1:1 everywhere, subsets are done through offsets
                shaderContext.CurrentVertexBuffer = renderElement.VertexBuffer;
                m_device.Indices = renderElement.IndexBuffer;

                m_device.SetStreamSource(0, renderElement.VertexBuffer, 0, renderElement.VertexStride);
                m_device.VertexDeclaration = renderElement.VertexDeclaration;

                shaderContext.IBChangesStats++;
            }

            //Entity changed
            if (shaderContext.CurrentEntity != renderElement.Entity)
            {
                MyPerformanceCounter.PerCameraDraw.EntityChanges[lod]++;

                shaderContext.CurrentEntity = renderElement.Entity;

                SetupShaderForEntity(shaderContext.CurrentShader, renderElement);
            }

            if (needBegin)
            {
                BeginShader(shaderContext.CurrentShader, ref renderElement);
                shaderContext.CurrentShader.Begin();
            }
            else
                shaderContext.CurrentShader.D3DEffect.CommitChanges();

            //    m_renderProfiler.EndProfilingBlock();
        }
示例#7
0
        private static void CreateRenderElementShadow(List<MyRenderElement> renderElements, MyEntity entity, MyModel model, out MyRenderElement renderElement)
        {
            //AddRenderElement(renderElements, out renderElement);
            AllocateRenderElement(out renderElement);

            if (!IsRenderOverloaded)
            {
                renderElement.Entity = entity;

                renderElement.VertexBuffer = model.VertexBuffer;
                renderElement.IndexBuffer = model.IndexBuffer;
                renderElement.VertexCount = model.GetVerticesCount();
                renderElement.VertexDeclaration = model.GetVertexDeclaration();
                renderElement.VertexStride = model.GetVertexStride();


                renderElement.IndexStart = 0;
                if (renderElement.IndexBuffer != null)
                {
                    renderElement.TriCount = model.GetTrianglesCount();
                }       

                //renderElement.DebugName = entity.Name;
                renderElement.WorldMatrix = entity.WorldMatrix;

                renderElements.Add(renderElement);
            }
        }
示例#8
0
 public static void AllocateRenderElement(out MyRenderElement renderElement)
 {
     lock (m_renderElementsPool)
     {
         renderElement = m_renderElementsPool[m_renderElementIndex++];
     }
     IsRenderOverloaded = m_renderElementIndex >= (MyRenderConstants.MAX_RENDER_ELEMENTS_COUNT - 4096);
 }
示例#9
0
        private static void SetupShaderForEntity(MyEffectBase shader, MyRenderElement renderElement)
        {
            // m_renderProfiler.StartProfilingBlock("SetupShaderForEntity");

            MyEffectBase currRenderEffect = null;

            Vector3 diffuseColor = Vector3.One;
            Vector3 highlightColor = Vector3.Zero;
            float emisivity = 0;

            MyEntity entity = renderElement.Entity;

            if (entity.GetDiffuseColor().HasValue)
                diffuseColor = entity.GetDiffuseColor().Value;

            highlightColor = entity.GetHighlightColor();

            switch (renderElement.DrawTechnique)
            {
                case MyMeshDrawTechnique.MESH:
                case MyMeshDrawTechnique.DECAL:
                case MyMeshDrawTechnique.HOLO:
                case MyMeshDrawTechnique.ALPHA_MASKED:
                    {
                        MyEffectModelsDNS effectDNS = shader as MyEffectModelsDNS;

                        effectDNS.SetWorldMatrix(renderElement.WorldMatrixForDraw);
                        effectDNS.SetDiffuseColor(diffuseColor);
                        effectDNS.SetEmissivity(emisivity);
                        effectDNS.SetHighlightColor(highlightColor);
                    }
                    break;

                case MyMeshDrawTechnique.VOXELS_DEBRIS:
                    {
                        //m_renderProfiler.StartProfilingBlock("VOXELD");

                        MyEffectVoxelsDebris effectVoxelsDebris = shader as MyEffectVoxelsDebris;

                        MyExplosionDebrisVoxel explosionDebrisVoxel = entity as MyExplosionDebrisVoxel;

                        //  Random texture coord scale and per-object random texture coord offset
                        effectVoxelsDebris.SetTextureCoordRandomPositionOffset(explosionDebrisVoxel.GetRandomizedTextureCoordRandomPositionOffset());
                        effectVoxelsDebris.SetTextureCoordScale(explosionDebrisVoxel.GetRandomizedTextureCoordScale());
                        effectVoxelsDebris.SetDiffuseTextureColorMultiplier(explosionDebrisVoxel.GetRandomizedDiffuseTextureColorMultiplier());
                        effectVoxelsDebris.SetViewWorldScaleMatrix(renderElement.WorldMatrixForDraw * MyCamera.ViewMatrixAtZero);
                        effectVoxelsDebris.SetWorldMatrix(ref renderElement.WorldMatrixForDraw);
                        effectVoxelsDebris.SetDiffuseColor(diffuseColor);
                        effectVoxelsDebris.SetHighlightColor(highlightColor);
                        effectVoxelsDebris.SetEmissivity(0);

                        effectVoxelsDebris.UpdateVoxelTextures(explosionDebrisVoxel.VoxelMaterial);

                        currRenderEffect = effectVoxelsDebris;

                        //m_renderProfiler.EndProfilingBlock();
                    }
                    break;

                case MyMeshDrawTechnique.VOXEL_MAP:
                    {
                        //m_renderProfiler.StartProfilingBlock("VOXMAP");

                        MyVoxelMap voxelMap = entity as MyVoxelMap;

                        MyEffectVoxels effectVoxels = shader as MyEffectVoxels;

                        effectVoxels.SetVoxelMapPosition(voxelMap.PositionLeftBottomCorner - MyCamera.Position);

                        effectVoxels.SetDiffuseColor(diffuseColor);
                        effectVoxels.SetHighlightColor(highlightColor);
                        effectVoxels.EnablePerVertexAmbient(EnablePerVertexVoxelAmbient);

                        //m_renderProfiler.EndProfilingBlock();
                    }
                    break;

                case MyMeshDrawTechnique.VOXELS_STATIC_ASTEROID:
                    {
                        // m_renderProfiler.StartProfilingBlock("STATA");

                        MyEffectVoxelsStaticAsteroid effectVoxelsStaticAsteroid = shader as MyEffectVoxelsStaticAsteroid;
                        var asteroid = ((MyStaticAsteroid)entity);
                        //effectVoxelsStaticAsteroid.UpdateVoxelTextures(((MyStaticAsteroid)entity).VoxelMaterial);
                        //effectVoxelsStaticAsteroid.UpdateVoxelMultiTextures(((MyStaticAsteroid)entity).VoxelMaterial, ((MyStaticAsteroid)entity).VoxelMaterial1, null);

                        if (asteroid.VoxelMaterial1 == null || MyRenderConstants.RenderQualityProfile.ForwardRender)
                        {
                            effectVoxelsStaticAsteroid.UpdateVoxelTextures(asteroid.VoxelMaterial);
                        }
                        else
                        {
                            Debug.Assert(asteroid.FieldDir != null);

                            effectVoxelsStaticAsteroid.SetEmissivityPower1(3f);
                            effectVoxelsStaticAsteroid.SetTime(MyMinerGame.TotalGamePlayTimeInMilliseconds);
                            effectVoxelsStaticAsteroid.SetFieldDir(asteroid.FieldDir.Value);
                            effectVoxelsStaticAsteroid.UpdateVoxelMultiTextures(asteroid.VoxelMaterial, asteroid.VoxelMaterial1, null);
                        }

                        effectVoxelsStaticAsteroid.SetWorldMatrix(ref renderElement.WorldMatrixForDraw);
                        effectVoxelsStaticAsteroid.SetDiffuseColor(diffuseColor);
                        effectVoxelsStaticAsteroid.SetHighlightColor(highlightColor);
                        effectVoxelsStaticAsteroid.SetEmissivity(0);

                        //m_renderProfiler.EndProfilingBlock();
                    }
                    break;

                default:
                    {
                        throw new MyMwcExceptionApplicationShouldNotGetHere();
                    }
            }

            //   m_renderProfiler.EndProfilingBlock();
        }