public void Add(MyLodTypeEnum lod, MyRender.MyRenderElement renderElement)
 {
     if (renderElement.DrawTechnique == MyMeshDrawTechnique.VOXEL_MAP)
         AddVoxel(lod, renderElement);
     else
         AddModel(lod, renderElement);
 }
Example #2
0
 public static void Draw()
 {
     if (MyRenderConstants.RenderQualityProfile.EnableDistantImpostors)
     {
         Update();
         m_objectImpostors.Draw(MyRender.GetEffect(MyEffects.DistantImpostors) as MyEffectDistantImpostors);
         m_voxelImpostors.Draw(MyRender.GetEffect(MyEffects.DistantImpostors) as MyEffectDistantImpostors);
     }
 }
Example #3
0
        protected void PostProcess(Texture source, Texture destination, MyEffectHDRBase effect)
        {
            MyRender.SetRenderTarget(destination, null);

            effect.SetHalfPixel(source.GetLevelDescription(0).Width, source.GetLevelDescription(0).Height);
            effect.SetSourceTextureMod(source);

            MyRender.GetFullscreenQuad().Draw(effect);
        }
        internal static void Test()
        {
            MyRender.GetRenderProfiler().StartProfilingBlock("SoftInstancingTest");
            MyGpuProfiler.IC_BeginBlock("SoftInstancingTest");
            DrawBatched();

            MyGpuProfiler.IC_EndBlock();
            MyRender.GetRenderProfiler().EndProfilingBlock();
        }
Example #5
0
        internal static float DrawText(Vector2 screenCoord, StringBuilder text, Color color, float scale)
        {
            BeginSpriteBatch();
            float textLenght = MyRender.GetDebugFont().DrawString(screenCoord, color, text, scale);

            EndSpriteBatch();

            return(textLenght);
        }
Example #6
0
        public override void LoadContent()
        {
            MyRender.Log.WriteLine("MyCockpitGlass.LoadContent() - START");
            MyRender.Log.IncreaseIndent();
            MyRender.GetRenderProfiler().StartProfilingBlock("MyCockpitGlass::LoadContent");

            MyRender.GetRenderProfiler().EndProfilingBlock();
            MyRender.Log.DecreaseIndent();
            MyRender.Log.WriteLine("MyCockpitGlass.LoadContent() - END");
        }
        /// <summary>
        /// Sets the environment render targets.
        /// </summary>
        private static void SetEnvironmentRenderTargets()
        {
            var rt1 = MyRender.GetRenderTargetCube(MyRenderTargets.EnvironmentCube);
            var rt2 = MyRender.GetRenderTargetCube(MyRenderTargets.EnvironmentCubeAux);
            var rt3 = MyRender.GetRenderTargetCube(MyRenderTargets.AmbientCube);
            var rt4 = MyRender.GetRenderTargetCube(MyRenderTargets.AmbientCubeAux);
            var rt5 = MyRender.GetRenderTarget(MyRenderTargets.EnvironmentMap);

            MyEnvironmentMap.SetRenderTargets((CubeTexture)rt1, (CubeTexture)rt2, (CubeTexture)rt3, (CubeTexture)rt4, (Texture)rt5);
        }
        public void PrepareForDraw(MyEffectDistantImpostors effect)
        {
            RasterizerState.CullClockwise.Apply();
            BlendState.Opaque.Apply();
            MyRender.SetRenderTarget(MyRender.GetRenderTarget(MyRenderTargets.AuxiliaryHalf0), null);

            foreach (MyVoxelMapImpostorGroup group in m_voxelMapImpostorGroups)
            {
                group.PrepareForDraw(effect);
            }
        }
Example #9
0
        internal unsafe static void Init()
        {
            FrameConstants          = MyRender.WrapResource(new MyConstantBuffer(sizeof(MyFrameConstantsLayout)), "frame constants");
            ProjectionConstants     = MyRender.WrapResource(new MyConstantBuffer(sizeof(Matrix)), "projection constants");
            ObjectConstants         = MyRender.WrapResource(new MyConstantBuffer(sizeof(Matrix)), "object constants");
            BonesConstants          = MyRender.WrapResource(new MyConstantBuffer(sizeof(Matrix) * MyRenderConstants.SHADER_MAX_BONES), "bones constants");
            LocalTransformConstants = MyRender.WrapResource(new MyConstantBuffer(32), "local transform constants");

            // temporary? merge with frame
            FoliageConstants = MyRender.WrapResource(new MyConstantBuffer(16), "folaige constants");
        }
 public void AddVoxel(MyLodTypeEnum lod, MyRender.MyRenderElement renderElement)
 {
     var matDict = Voxels[GetVoxelIndex(lod, renderElement.VoxelBatch.Type)];
     List<MyRender.MyRenderElement> elements;
     if (!matDict.Voxels.TryGetValue(renderElement.VoxelBatch.MaterialId, out elements))
     {
         elements = new List<MyRender.MyRenderElement>(20);
         matDict.Voxels[renderElement.VoxelBatch.MaterialId] = elements;
     }
     matDict.RenderElementCount++;
     elements.Add(renderElement);
 }
Example #11
0
        /// <summary>
        /// Downscales the source to 1/4th size, using mipmaps
        /// !! IMPORTANT !! you cannot just switch function call. Also changing RTs is necessary.
        /// </summary>
        protected void GenerateDownscale4(Texture sourceMod, Texture sourceDiv, Texture destination, MyEffectScale effect)
        {
            effect.SetTechnique(MyEffectScale.Technique.Downscale4);

            MyRender.SetRenderTarget(destination, null);

            effect.SetSourceTextureMod(sourceMod);
            effect.SetSourceTextureDiv(sourceDiv);
            //effect.SetLumTexture(currentFrameAdaptedLuminance);
            effect.SetHalfPixel(sourceMod.GetLevelDescription(0).Width, sourceMod.GetLevelDescription(0).Height);

            MyRender.GetFullscreenQuad().Draw(effect);
        }
Example #12
0
        /*
         * private void CalculateAverageLuminance(RenderTarget2D source, RenderTarget2D destination, MyEffectLuminance luminanceEffect, MyEffectScale scalingEffect, float dt, float tau)
         * {
         *  // Calculate the initial luminance
         *  luminanceEffect.SetTechniqueLuminance();
         *  PostProcess(source, destination, luminanceEffect);
         *
         *  //// Repeatedly downscale
         *  //scalingEffect.SetTechniqueDownscale();
         *  //for (int i = 1; i < luminanceChain.Length; i++)
         *  //{
         *  //    scalingEffect.SetSourceDimensions(luminanceChain[i - 1].Width, luminanceChain[i - 1].Height);
         *  //    PostProcess(luminanceChain[i - 1], luminanceChain[i], scalingEffect);
         *  //}
         *
         *  //// Final downscale
         *  //scalingEffect.SetTechniqueDownscaleLuminance();
         *  //scalingEffect.SetSourceDimensions(luminanceChain[luminanceChain.Length - 1].Width, luminanceChain[luminanceChain.Length - 1].Height);
         *  //PostProcess(luminanceChain[luminanceChain.Length - 1], currentFrameLuminance, scalingEffect);
         *
         *  // Final downscale
         *  luminanceEffect.SetTechniqueLuminanceMipmap();
         *  float size = MathHelper.Min(MyCamera.ForwardViewport.Width, MyCamera.ForwardViewport.Height);
         *  // TODO check if mipmap level is correct
         *  int mipLevel = (int)Math.Floor(Math.Log(size / 8.0f, 2));
         *  //int mipLevel = (int)Math.Ceiling(Math.Log(size / 8.0f, 2));
         *  luminanceEffect.SetMipLevel(mipLevel);
         *  PostProcess(destination, currentFrameLuminance, luminanceEffect);
         *
         *  // Adapt the luminance, to simulate slowly adjust exposure
         *  MySandboxGame.Static.GraphicsDevice.SetRenderTarget(currentFrameAdaptedLuminance);
         *  luminanceEffect.SetTechniqueAdaptedLuminance();
         *  luminanceEffect.SetDT(dt);
         *  luminanceEffect.SetTau(tau);
         *  luminanceEffect.SetSourceTexture(currentFrameLuminance);
         *  luminanceEffect.SetSourceTexture2(lastFrameAdaptedLuminance);
         *  luminanceEffect.SetHalfPixel(source.Width, source.Height);
         *  MyGuiManager.GetFullscreenQuad().Draw(luminanceEffect);
         * }
         */

        private void HDR(Texture sourceMod, Texture sourceDiv, Texture bloomSource, MyEffectHDR effect, float middleGrey, float exposure)
        {
            effect.SetSourceTextureMod(sourceMod);
            effect.SetSourceTextureDiv(sourceDiv);
            effect.SetBloomTexture(bloomSource);
            //effect.SetLumTexture(currentFrameAdaptedLuminance);
            //effect.SetLumTexture(currentFrameLuminance);
            effect.SetHalfPixel(sourceMod.GetLevelDescription(0).Width, sourceMod.GetLevelDescription(0).Height);
            //effect.SetMiddleGrey(middleGrey);
            effect.SetExposure(exposure);

            MyRender.GetFullscreenQuad().Draw(effect);
        }
Example #13
0
        public void Update()
        {
            m_actualWorldAABB = BoundingBoxD.CreateInvalid();

            ContainmentType containmentType;

            m_aabb.Contains(ref m_actualWorldAABB, out containmentType);
            if (containmentType != ContainmentType.Contains)
            {
                SetDirty();
                MyRender.UpdateRenderObject(this, false);
            }
        }
Example #14
0
        void IMyClipmapCell.UpdateMesh(MyRenderMessageUpdateClipmapCell msg)
        {
            Dispose();
            m_metadata = msg.Metadata;
            foreach (var batch in msg.Batches)
            {
                AddBatch(batch);
            }

            SetDirty();
            UpdateWorldAABB();
            MyRender.UpdateRenderObject(this, true);
        }
Example #15
0
        static MyDistantImpostors()
        {
            MyRender.Log.WriteLine("MyDistantImpostors()");

            const float defaultSize = 200000;

            m_objectImpostors       = new MyDistantObjectImpostors();
            m_objectImpostors.Scale = MySectorConstants.SECTOR_SIZE / defaultSize;

            m_voxelImpostors = new MyVoxelMapImpostors();

            MyRender.RegisterRenderModule(MyRenderModuleEnum.DistantImpostors, "Distant impostors", PrepareForDraw, MyRenderStage.PrepareForDraw);
            MyRender.RegisterRenderModule(MyRenderModuleEnum.DistantImpostors, "Distant impostors", Draw, MyRenderStage.Background);
        }
Example #16
0
        public override void LoadContent()
        {
            MyRender.Log.WriteLine("MyDecals.LoadContent() - START");
            MyRender.Log.IncreaseIndent();
            MyRender.GetRenderProfiler().StartProfilingBlock("MyDecals::LoadContent");

            //  Reason is that if count of neighbour triangles is more then decal triangles buffer, we won't be able to add any triangleVertexes to the buffer.
            MyDebug.AssertRelease(MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER > MyDecalsConstants.TEXTURE_LARGE_MAX_NEIGHBOUR_TRIANGLES);

            MyDebug.AssertRelease(MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER_LARGE <= MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER);
            MyDebug.AssertRelease(MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER_SMALL <= MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER);

            //  Reason is that if count of neighbour triangles is more then decal triangles buffer, we won't be able to add any triangleVertexes to the buffer.
            MyDebug.AssertRelease(MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER > MyDecalsConstants.TEXTURE_SMALL_MAX_NEIGHBOUR_TRIANGLES);

            //  Reason is that if count of neighbour triangles is more then this fade limit, we won't be able to add decals that lay on more triangles, because buffer will be never released to us.
            MyDebug.AssertRelease(MyDecalsConstants.TEXTURE_LARGE_MAX_NEIGHBOUR_TRIANGLES < (MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER * MyDecalsConstants.TEXTURE_LARGE_FADING_OUT_MINIMAL_TRIANGLE_COUNT_PERCENT));

            //  Reason is that if count of neighbour triangles is more then this fade limit, we won't be able to add decals that lay on more triangles, because buffer will be never released to us.
            MyDebug.AssertRelease(MyDecalsConstants.TEXTURE_SMALL_MAX_NEIGHBOUR_TRIANGLES < (MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER * MyDecalsConstants.TEXTURE_SMALL_FADING_OUT_MINIMAL_TRIANGLE_COUNT_PERCENT));

            //  Large must be bigger than small
            MyDebug.AssertRelease(MyDecalsConstants.TEXTURE_LARGE_MAX_NEIGHBOUR_TRIANGLES > MyDecalsConstants.TEXTURE_SMALL_MAX_NEIGHBOUR_TRIANGLES);

            m_vertices = new MyVertexFormatDecal[MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER * MyDecalsConstants.VERTEXES_PER_DECAL];
            // m_neighbourTriangles = new List<MyTriangle_Vertex_Normals>(MyDecalsConstants.TEXTURE_LARGE_MAX_NEIGHBOUR_TRIANGLES);

            m_decalsForModels = new MyDecalsForRenderObjects(MyDecalsConstants.DECAL_BUFFERS_COUNT);
            m_decalsForVoxels = new MyDecalsForVoxels(MyDecalsConstants.DECAL_BUFFERS_COUNT);

            //  Decal textures
            int texturesCount = MyEnumsToStrings.Decals.Length;

            m_texturesDiffuse   = new MyTexture2D[texturesCount];
            m_texturesNormalMap = new MyTexture2D[texturesCount];

            for (int i = 0; i < texturesCount; i++)
            {
                //MyRender.Log.WriteLine("textureManager " + i.ToString() + "Textures\\Decals\\" + MyEnumsToStrings.Decals[i] + "_Diffuse", SysUtils.LoggingOptions.MISC_RENDER_ASSETS);
                m_texturesDiffuse[i] = MyTextureManager.GetTexture <MyTexture2D>("Textures\\Decals\\" + MyEnumsToStrings.Decals[i] + "_Diffuse.dds", "", null, LoadingMode.Immediate);
                //MyRender.Log.WriteLine("textureManager " + i.ToString() + "Textures\\Decals\\" + MyEnumsToStrings.Decals[i] + "_NormalMap", SysUtils.LoggingOptions.MISC_RENDER_ASSETS);
                m_texturesNormalMap[i] = MyTextureManager.GetTexture <MyTexture2D>("Textures\\Decals\\" + MyEnumsToStrings.Decals[i] + "_NormalMap.dds", "", CheckTexture, LoadingMode.Immediate);

                MyUtilsRender9.AssertTexture(m_texturesNormalMap[i]);
            }

            MyRender.GetRenderProfiler().EndProfilingBlock();
            MyRender.Log.DecreaseIndent();
            MyRender.Log.WriteLine("MyDecals.LoadContent() - END");
        }
Example #17
0
        public static void ReloadData()
        {
            MyRender.GetRenderProfiler().StartProfilingBlock("MyModels.ReloadData");
            MyRender.Log.WriteLine(string.Format("MyModels.ReloadData - START"));

            List <MyRenderModel> loadedModels = new List <MyRenderModel>();

#if USE_SERIAL_MODEL_LOAD
            foreach (var pair in m_modelsByAssetName)
            {
                if (pair.Value.UnloadData())
                {
                    loadedModels.Add(pair.Value);
                }
            }
#else
            Parallel.For(0, m_models.Length, i =>
            {
                if (m_models[i].UnloadData())
                {
                    loadedModels.Add(i);
                }
            });
#endif
            //load only previously loaded models
#if USE_SERIAL_MODEL_LOAD
            foreach (MyRenderModel model in loadedModels)
            {
                model.LoadData();
            }
#else
            Parallel.ForEach(loadedModels, i =>
            {
                m_models[i].LoadData();
            });
#endif

            /*
             * if (MyEntities.GetEntities() != null)
             * {
             *  foreach (MyEntity entity in MyEntities.GetEntities())
             *  {
             *      entity.InitDrawTechniques();
             *  }
             * } */

            MyRender.Log.WriteLine(string.Format("MyModels.ReloadData - END"));
            MyRender.GetRenderProfiler().EndProfilingBlock();
        }
Example #18
0
        public static void UpdateScreenSize()
        {
            MyRender.Log.WriteLine("MyRenderCamera.UpdateScreenSize() - START");

            Viewport = MyRender.GraphicsDevice.Viewport;

            if (MyRender.GetScreenshot() != null)
            {
                Viewport = ScaleViewport(Viewport, MyRender.GetScreenshot().SizeMultiplier);
            }

            AspectRatio = (float)Viewport.Width / (float)Viewport.Height;

            MyRender.Log.WriteLine("MyRenderCamera.UpdateScreenSize() - END");
        }
        void IMyClipmapCell.UpdateMesh(MyRenderMessageUpdateClipmapCell msg)
        {
            Dispose();
            m_offset    = msg.PositionOffset;
            m_scale     = msg.PositionScale;
            m_localAabb = msg.MeshAabb;
            foreach (var batch in msg.Batches)
            {
                AddBatch(batch);
            }

            SetDirty();
            UpdateWorldAABB();
            MyRender.UpdateRenderObject(this, true);
        }
Example #20
0
        private void GenerateThreshold(Texture sourceMod, Texture sourceDiv, Texture[] destination, MyEffectThreshold effect, float threshold, float bloomIntensity, float bloomIntensityBackground, float exposure)
        {
            MyRender.SetRenderTargets(destination, null);

            effect.SetSourceTextureMod(sourceMod);
            effect.SetSourceTextureDiv(sourceDiv);
            //effect.SetLumTexture(currentFrameAdaptedLuminance);
            effect.SetHalfPixel(sourceMod.GetLevelDescription(0).Width, sourceMod.GetLevelDescription(0).Height);
            effect.SetThreshold(threshold);
            effect.SetBloomIntensity(bloomIntensity);
            effect.SetBloomIntensityBackground(bloomIntensityBackground);
            effect.SetExposure(exposure);

            MyRender.GetFullscreenQuad().Draw(effect);
        }
Example #21
0
        public virtual bool Draw()
        {
            if (Visible)
            {
                ClearBillboards();
                MyRender.AddRenderObjectToDraw(this);
                return(true);
            }

            //Render character need update bones
            if (CastShadows)
            {
                return(true);
            }

            return(false);
        }
Example #22
0
        internal static void DrawDebugBlendedRenderTargets()
        {
            //  All RT should be of same size, so for size we can use any of them we just pick up depthRT
            float renderTargetAspectRatio = (float)MyRenderCamera.Viewport.Width / (float)MyRenderCamera.Viewport.Height;

            float normalizedSizeY = 0.40f;
            //float normalizedSizeY = MyCamera.Viewport.Height / 1920f;
            float normalizedSizeX = normalizedSizeY * renderTargetAspectRatio;

            Vector2I delta = new Vector2I((int)(MyRenderCamera.Viewport.Height * 0.015f), (int)(MyRenderCamera.Viewport.Height * 0.015f));
            Vector2I size  = new Vector2I((int)(MyRenderCamera.Viewport.Height * normalizedSizeX), (int)(MyRenderCamera.Viewport.Height * normalizedSizeY));

            BeginSpriteBatch(BlendState.Opaque);
            DrawSprite(MyRender.GetRenderTarget(MyRenderTargets.Diffuse), new Rectangle(delta.X, delta.Y, size.X, size.Y), Color.White);
            DrawSprite(MyRender.GetRenderTarget(MyRenderTargets.Normals), new Rectangle(delta.X + size.X + delta.X, delta.Y, size.X, size.Y), Color.White);
            EndSpriteBatch();
        }
Example #23
0
        //  Here we load only textures, effects, etc, no voxel-maps.
        public override void LoadContent()
        {
            MyRender.Log.WriteLine("MyVoxelMaterials.LoadContent() - START");
            MyRender.Log.IncreaseIndent();
            MyRender.GetRenderProfiler().StartProfilingBlock("MyVoxelMaterials::LoadContent");

            if (m_materials != null)
            {
                foreach (var mat in m_materials)
                {
                    mat.Value.LoadContent();
                }
            }

            MyRender.GetRenderProfiler().EndProfilingBlock();
            MyRender.Log.DecreaseIndent();
            MyRender.Log.WriteLine("MyVoxelMaterials.LoadContent() - END");
        }
Example #24
0
        /// <summary>
        /// Render method is called directly by renderer. Depending on stage, post process can do various things
        /// </summary>
        /// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param>public override void RenderAfterBlendLights()
        public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget)
        {
            switch (postProcessStage)
            {
            case PostProcessStage.PostLighting:
            {
                //todo fog
                //if (MySector.FogProperties.FogMultiplier <= 0.0f)
                //  return source;

                MyStateObjects.VolumetricFogBlend.Apply();

                MyEffectVolumetricFog volumetricFog = MyRender.GetEffect(MyEffects.VolumetricFog) as MyEffectVolumetricFog;

                int width  = MyRenderCamera.Viewport.Width;
                int height = MyRenderCamera.Viewport.Height;

                var scale = MyRender.GetScaleForViewport(source);

                volumetricFog.SetSourceRT(source);
                volumetricFog.SetDepthsRT(MyRender.GetRenderTarget(MyRenderTargets.Depth));
                volumetricFog.SetNormalsTexture(MyRender.GetRenderTarget(MyRenderTargets.Normals));
                volumetricFog.SetHalfPixel(width, height);
                volumetricFog.SetViewProjectionMatrix((Matrix)MyRenderCamera.ViewProjectionMatrix);
                volumetricFog.SetCameraPosition((Vector3)MyRenderCamera.Position);
                volumetricFog.SetCameraMatrix((Matrix)MatrixD.Invert(MyRenderCamera.ViewMatrix));
                volumetricFog.SetFrustumCorners(MyRender.GetShadowRenderer().GetFrustumCorners());
                volumetricFog.SetScale(scale);
                MyRenderCamera.SetupBaseEffect(volumetricFog, MyLodTypeEnum.LOD0);

                //volumetricFog.SetWorldMatrix(Matrix.CreateScale(1000) * Matrix.CreateTranslation(MyCamera.Position));
                //todo
                //if (MyFakes.MWBUILDER)
                //    volumetricFog.SetTechnique(MyEffectVolumetricFog.TechniqueEnum.SkipBackground);
                //else
                volumetricFog.SetTechnique(MyEffectVolumetricFog.TechniqueEnum.Default);

                MyRender.GetFullscreenQuad().Draw(volumetricFog);
            }
            break;
            }
            return(source);
        }
Example #25
0
        /// <summary>
        /// Reads and issues occlusions queries and draws sun glare and flare effects based on
        /// the result of the queries.
        /// </summary>
        public static void DrawGlareAndFlare()
        {
            if (MyRender.Sun.Direction == Vector3.Zero)
            {
                return;
            }

            Vector3 projectedPosition = CalculateProjectedPosition();

            m_lightPosition = new Vector2(projectedPosition.X,
                                          projectedPosition.Y);

            // determine caller index and if the caller is allowed
            Debug.Assert(MyRender.CurrentRenderSetup.CallerID != null, "MyRender.CurrentRenderSetup.CallerID cannot be null");
            int callerIndex = Array.IndexOf(m_allowedCallers, (int)MyRender.CurrentRenderSetup.CallerID);

            if (callerIndex < 0)
            {
                Debug.Assert(false, "Sun Glare is called by an unallowed caller.");
            }

            // Check whether the light is hidden behind the scenery.
            MyRender.GetRenderProfiler().StartProfilingBlock("UpdateOcclusion");
            UpdateOcclusion(callerIndex);
            MyRender.GetRenderProfiler().EndProfilingBlock();

            if (m_visibilityRatios[callerIndex] < MyMathConstants.EPSILON)
            {
                return;
            }

            float sizeInv             = 1f / MathHelper.Max(m_querySize, MySunConstants.MIN_QUERY_SIZE);
            float viewportScale       = 0.5f * (MyRender.GetScaleForViewport(null).X + MyRender.GetScaleForViewport(null).Y);
            var   borderFactor        = (50f / viewportScale) * sizeInv * (float)Math.Sqrt(m_occlusionMeasurementResults[callerIndex]);
            float borderFactorClamped = MathHelper.Clamp(borderFactor, 0, 1);

            // If it is visible, draw the flare effect.
            if (m_visibilityRatios[callerIndex] > 0 && borderFactorClamped > 0)
            {
                DrawGlare(borderFactorClamped, m_visibilityRatios[callerIndex]);
                DrawFlares(borderFactorClamped, m_visibilityRatios[callerIndex]);
            }
        }
Example #26
0
        private void IssueSpotQuery()
        {
            if (((LightType & LightTypeEnum.Spotlight) > 0) && SpotQuery != null && SpotQueryState == QueryState.IssueOcc)
            {
                BlendState previousBlendState = BlendState.Current;;
                MyStateObjects.DisabledColorChannels_BlendState.Apply();
                // RasterizerState.CullNone.Apply();
                // DepthStencilState.None.Apply();

                MyEffectOcclusionQueryDraw effectOQ = MyRender.GetEffect(MyEffects.OcclusionQueryDrawMRT) as MyEffectOcclusionQueryDraw;
                effectOQ.SetTechnique(MyEffectOcclusionQueryDraw.Technique.DepthTestEnabled);

                MatrixD spotWorld = SpotWorld;
                spotWorld.Translation = SpotWorld.Translation - MyRenderCamera.Position;
                effectOQ.SetWorldMatrix((Matrix)spotWorld);
                effectOQ.SetViewMatrix(MyRenderCamera.ViewMatrixAtZero);
                effectOQ.SetProjectionMatrix(MyRenderCamera.ProjectionMatrix);

                var depthRenderTarget = MyRender.GetRenderTarget(MyRenderTargets.Depth);
                effectOQ.SetDepthRT(depthRenderTarget);
                effectOQ.SetScale(MyRender.GetScaleForViewport(depthRenderTarget));

                SpotQuery.Begin();

                effectOQ.Begin();

                MyDebugDraw.ModelCone.Render();

                effectOQ.End();

                SpotQuery.End();

                SpotQueryState = QueryState.CheckOcc;

                previousBlendState.Apply();
            }

            if (SpotQueryState == QueryState.WaitOcc)
            {
                SpotQueryState = QueryState.IssueOcc;
            }
        }
        public static void Draw()
        {
            //  We can fill vertex buffer only when in Draw
            LoadInDraw();

            //RasterizerState.CullClockwise.Apply();
            RasterizerState.CullNone.Apply();
            DepthStencilState.None.Apply();
            BlendState.Opaque.Apply();

            m_backgroundProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MyRenderCamera.FieldOfView, MyRenderCamera.AspectRatio,
                                                                               MyRenderCamera.NEAR_PLANE_DISTANCE,
                                                                               100000);

            if (MyRender.CurrentRenderSetup.BackgroundColor != null)
            {
                MyRender.GraphicsDevice.Clear(ClearFlags.Target, new SharpDX.ColorBGRA(MyRender.CurrentRenderSetup.BackgroundColor.Value.R, MyRender.CurrentRenderSetup.BackgroundColor.Value.G, MyRender.CurrentRenderSetup.BackgroundColor.Value.B, MyRender.CurrentRenderSetup.BackgroundColor.Value.A), 1, 0);
            }
            else
            if (m_textureCube != null)
            {
                MyEffectBackgroundCube effect = MyRender.GetEffect(MyEffects.BackgroundCube) as MyEffectBackgroundCube;
                effect.SetViewProjectionMatrix(MyRenderCamera.ViewMatrixAtZero * m_backgroundProjectionMatrix);
                effect.SetBackgroundTexture(m_textureCube);
                effect.SetBackgroundColor(BackgroundColor);
                MyRender.GraphicsDevice.VertexDeclaration = MyVertexFormatPositionTexture3.VertexDeclaration;
                MyRender.GraphicsDevice.SetStreamSource(0, m_boxVertexBuffer, 0, MyVertexFormatPositionTexture3.Stride);

                effect.Begin();

                MyRender.GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, BOX_TRIANGLES_COUNT);

                effect.End();

                MyPerformanceCounter.PerCameraDrawWrite.TotalDrawCalls++;
            }
            else
            {
                MyRender.GraphicsDevice.Clear(ClearFlags.Target, new SharpDX.ColorBGRA(BackgroundColor.X, BackgroundColor.Y, BackgroundColor.Z, 1), 1, 0);
            }
        }
        public override void LoadContent()
        {
            MyRender.Log.WriteLine("MyBackgroundCube.LoadContent() - START");
            MyRender.Log.IncreaseIndent();
            MyRender.GetRenderProfiler().StartProfilingBlock("MyBackgroundCube");

            Static = this;

            UpdateTexture();

            m_loaded = false;

            //  Projection matrix according to zoom level
            m_backgroundProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(1.0f, MyRenderCamera.AspectRatio,
                                                                               50,
                                                                               100000);

            MyRender.GetRenderProfiler().EndProfilingBlock();
            MyRender.Log.DecreaseIndent();
            MyRender.Log.WriteLine("MyBackgroundCube.LoadContent() - END");
        }
Example #29
0
        private static void IssueOcclusionQuery(MyOcclusionQuery query, bool depthTest)
        {
            MyRender.GetRenderProfiler().StartProfilingBlock("IssueOcclusionQuery");
            BlendState previousBlendState = BlendState.Current;

            MyStateObjects.DisabledColorChannels_BlendState.Apply();
            RasterizerState.CullNone.Apply();

            DepthStencilState.None.Apply();

            query.Begin();

            //generate and draw bounding box of our renderCell in occlusion query
            MyDebugDraw.DrawOcclusionBoundingBox(m_occlusionBox, 1.0f, depthTest, true);

            query.End();

            previousBlendState.Apply();

            MyRender.GetRenderProfiler().EndProfilingBlock();
        }
        public void UpdateAmbient(int index)
        {
            CubeMapFace face        = (CubeMapFace)index;
            Surface     cubeSurface = m_ambientRT.GetCubeMapSurface(face, 0);

            MyRender.GraphicsDevice.SetRenderTarget(0, cubeSurface);
            BlendState.Opaque.Apply();

            MyEffectAmbientPrecalculation precalc = MyRender.GetEffect(MyEffects.AmbientMapPrecalculation) as MyEffectAmbientPrecalculation;

            precalc.SetEnvironmentMap(this.m_environmentRT);
            precalc.SetFaceMatrix((Matrix)CreateViewMatrix(face, Vector3D.Zero));
            precalc.SetRandomTexture(MyRender.GetRandomTexture());
            precalc.SetIterationCount(14);
            precalc.SetMainVectorWeight(1.0f);
            precalc.SetBacklightColorAndIntensity(new Vector3(MyRender.Sun.BackColor.X, MyRender.Sun.BackColor.Y, MyRender.Sun.BackColor.Z), MyRender.Sun.BackIntensity);
            MyRender.GetFullscreenQuad().Draw(precalc);

            MyRender.SetRenderTarget(null, null);
            cubeSurface.Dispose();
        }
        public void UpdateFace(Vector3D position, int faceIndex)
        {
            //SetRenderSetup();

            CubeMapFace face = (CubeMapFace)faceIndex;

            // New setup
            m_setup.CameraPosition   = position;
            m_setup.AspectRatio      = 1.0f;
            m_setup.Viewport         = new Viewport(0, 0, (int)m_environmentRT.GetLevelDescription(0).Width, (int)m_environmentRT.GetLevelDescription(0).Width);
            m_setup.ViewMatrix       = CreateViewMatrix(face, position);
            m_setup.Fov              = MathHelper.PiOver2;
            m_setup.ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(m_setup.Fov.Value, m_setup.AspectRatio.Value, NearClip, m_setup.LodTransitionBackgroundEnd.Value);
            m_setup.DepthToAlpha     = true;

            MyRender.GetRenderProfiler().StartProfilingBlock("Draw environmental maps");

            MyRender.PushRenderSetupAndApply(m_setup, ref m_backup);
            MyRender.Draw3D(false);

            MyRender.GetRenderProfiler().EndProfilingBlock();

            Surface cubeSurface = m_environmentRT.GetCubeMapSurface(face, 0);

            MyRender.GraphicsDevice.SetRenderTarget(0, cubeSurface);

            var screenEffect = MyRender.GetEffect(MyEffects.Screenshot) as MyEffectScreenshot;

            screenEffect.SetTechnique(MyEffectScreenshot.ScreenshotTechniqueEnum.Default);
            screenEffect.SetSourceTexture(m_fullSizeRT);
            screenEffect.SetScale(new Vector2(m_environmentRT.GetLevelDescription(0).Width / (float)m_fullSizeRT.GetLevelDescription(0).Width, m_environmentRT.GetLevelDescription(0).Height / (float)m_fullSizeRT.GetLevelDescription(0).Height));
            MyRender.GetFullscreenQuad().Draw(screenEffect);
            screenEffect.SetScale(new Vector2(1, 1));

            //Texture.ToFile(m_fullSizeRT, "C:\\fullSizeRT.dds", ImageFileFormat.Dds);

            cubeSurface.Dispose();

            MyRender.PopRenderSetupAndRevert(m_backup);
        }
        public void AddModel(MyLodTypeEnum lod, MyRender.MyRenderElement renderElement)
        {
            var matDict = Models[GetModelIndex(lod, renderElement.DrawTechnique)];
            ModelMaterialSet vbDict;
            if (!matDict.Models.TryGetValue(renderElement.Material, out vbDict))
            {
                vbDict = new ModelMaterialSet();
                matDict.Models[renderElement.Material] = vbDict;
            }

            List<MyRender.MyRenderElement> elements;
            if (!vbDict.Models.TryGetValue(renderElement.VertexBuffer, out elements))
            {
                elements = new List<MyRender.MyRenderElement>(20);
                vbDict.Models[renderElement.VertexBuffer] = elements;
            }

            matDict.RenderElementCount++;
            vbDict.RenderElementCount++;

            elements.Add(renderElement);
        }
Example #33
0
        public override void GetRenderElements(MyLodTypeEnum lodTypeEnum, List <MyRender.MyRenderElement> elements, List <MyRender.MyRenderElement> transparentElements)
        {
            foreach (var mesh in m_meshes)
            {
                mesh.Material.PreloadTexture(LoadingMode.Background);

                MyRender.MyRenderElement renderElement;
                MyRender.AllocateRenderElement(out renderElement);

                if (!MyRender.IsRenderOverloaded)
                {
                    //renderElement.DebugName = entity.Name;
                    renderElement.RenderObject = this;

                    renderElement.VertexBuffer      = m_vertexBuffer;
                    renderElement.IndexBuffer       = m_indexBuffer;
                    renderElement.VertexCount       = m_vertexCount;
                    renderElement.VertexDeclaration = m_vertexDeclaration;
                    renderElement.VertexStride      = m_vertexStride;
                    renderElement.InstanceBuffer    = null;

                    renderElement.IndexStart = mesh.IndexStart;
                    renderElement.TriCount   = mesh.TriangleCount;

                    renderElement.WorldMatrixForDraw = GetWorldMatrixForDraw();
                    renderElement.WorldMatrix        = WorldMatrix;

                    renderElement.Material      = mesh.Material;
                    renderElement.DrawTechnique = mesh.Material.DrawTechnique;
                    renderElement.Color         = new Vector3(1, 1, 1);
                    renderElement.Dithering     = 0;

                    Debug.Assert(renderElement.VertexBuffer != null, "Vertex buffer cannot be null!");
                    Debug.Assert(renderElement.IndexBuffer != null, "Index buffer cannot be null!");

                    elements.Add(renderElement);
                }
            }
        }
        private void SetupRenderElement(MyRenderVoxelBatch batch, MyRender.MyRenderElement renderElement)
        {
            renderElement.RenderObject = this;

            renderElement.VertexDeclaration = MyVertexFormatVoxelSingleMaterial.VertexDeclaration;
            renderElement.VertexStride = MyVertexFormatVoxelSingleMaterial.Stride;
            renderElement.VertexCount = batch.VertexCount;
            renderElement.VertexBuffer = batch.VertexBuffer;

            renderElement.InstanceBuffer = null;

            renderElement.IndexBuffer = batch.IndexBuffer;
            renderElement.IndexStart = 0;
            if (renderElement.IndexBuffer != null)
            {
                renderElement.TriCount = batch.IndexCount / 3;
            }
            renderElement.WorldMatrix = m_worldMatrix;
            renderElement.WorldMatrix.Translation += m_cellOffset;
            renderElement.VoxelBatch = batch;
        }
        private void SetupRenderElement(MyRenderVoxelBatch batch, MyRender.MyRenderElement renderElement)
        {
            renderElement.RenderObject = this;

            renderElement.VertexDeclaration = MyVertexFormatVoxelSingleMaterial.VertexDeclaration;
            renderElement.VertexStride = MyVertexFormatVoxelSingleMaterial.Stride;
            renderElement.VertexCount = batch.VertexCount;
            renderElement.VertexBuffer = batch.VertexBuffer;

            renderElement.InstanceBuffer = null;

            renderElement.IndexBuffer = batch.IndexBuffer;
            renderElement.IndexStart = 0;
            if (renderElement.IndexBuffer != null)
            {
                renderElement.TriCount = batch.IndexCount / 3;
            }

            {
                var matrix = m_worldMatrix;
                matrix.Right = (Vector3D)m_offset;
                matrix.Up = (Vector3D)m_scale;
                matrix.Backward = MyRenderCamera.Position - m_worldMatrix.Translation;
                Vector2 lodBounds;
                MyClipmap.ComputeLodViewBounds(m_scaleGroup, m_coord.Lod, out lodBounds.X, out lodBounds.Y);
                matrix.M14 = lodBounds.X;
                matrix.M24 = lodBounds.Y;
                matrix.M34 = MathHelper.Clamp(MyClipmap.DebugClipmapMostDetailedLod - m_coord.Lod, 0f, 1f);
                renderElement.WorldMatrix = matrix;
            }
            renderElement.VoxelBatch = batch;
        }