Beispiel #1
0
        internal void UpdateCullQuery(MyCullQuery cullQuery)
        {
            if (MyRender11.IsIntelBrokenCubemapsWorkaround)
            {
                return;
            }

            if (m_isInit == false)
            {
                m_isInit = true;

                // compute mipmapLevels
                int mipmapLevels = 0;
                for (int tmp = MyEnvironmentProbe.CubeMapResolution; tmp != 1;)
                {
                    mipmapLevels++;
                    tmp = tmp / 2 + tmp % 2;
                }

                MyArrayTextureManager texManager = MyManagers.ArrayTextures;
                Cubemap = texManager.CreateUavCube("MyEnvironmentProbe.CubemapPrefiltered",
                                                   MyEnvironmentProbe.CubeMapResolution, Format.R16G16B16A16_Float, mipmapLevels);
                m_workCubemap = texManager.CreateUavCube("MyEnvironmentProbe.WorkCubemap",
                                                         MyEnvironmentProbe.CubeMapResolution, Format.R16G16B16A16_Float, mipmapLevels);
                m_workCubemapPrefiltered = texManager.CreateUavCube(
                    "MyEnvironmentProbe.WorkCubemapPrefiltered", MyEnvironmentProbe.CubeMapResolution,
                    Format.R16G16B16A16_Float, mipmapLevels);
                m_prevWorkCubemapPrefiltered =
                    texManager.CreateUavCube("MyEnvironmentProbe.PrevWorkCubemapPrefiltered",
                                             MyEnvironmentProbe.CubeMapResolution, Format.R16G16B16A16_Float, mipmapLevels);
                CubemapDepth = MyManagers.ArrayTextures.CreateDepthCube("MyEnvironmentProbe.CubemapDepth",
                                                                        MyEnvironmentProbe.CubeMapResolution, Format.R24G8_Typeless, Format.R24_UNorm_X8_Typeless,
                                                                        Format.D24_UNorm_S8_UInt);

                m_lastUpdateTime = MyTimeSpan.Zero;
                m_state          = 0;

                AddAllProbes(cullQuery);
            }
            else
            {
                if (m_lastUpdateTime == MyTimeSpan.Zero)
                {
                    AddAllProbes(cullQuery);
                }
                else
                {
                    if (m_state == 0)
                    {
                        m_position = MyRender11.Environment.Matrices.CameraPosition;
                    }
                    if (m_state < 6)
                    {
                        AddProbe(m_state, cullQuery);
                    }
                }
            }
        }
            public void OnDeviceInit()
            {
                ISrvBindable tex0 = m_sourceTextures[0];

                Texture2DDescription texDesc = new Texture2DDescription();

                texDesc.ArraySize                 = m_sourceTextures.Count;
                texDesc.BindFlags                 = BindFlags.ShaderResource;
                texDesc.CpuAccessFlags            = CpuAccessFlags.None;
                texDesc.Format                    = tex0.Srv.Description.Format;
                texDesc.Height                    = tex0.Size.X;
                texDesc.MipLevels                 = tex0.Srv.Description.Texture2D.MipLevels;
                texDesc.OptionFlags               = ResourceOptionFlags.None;
                texDesc.SampleDescription.Count   = 1;
                texDesc.SampleDescription.Quality = 0;
                texDesc.Usage        = ResourceUsage.Default;
                texDesc.Width        = tex0.Size.Y;
                m_resource           = new Texture2D(MyRender11.Device, texDesc);
                m_resource.DebugName = m_debugName;

                ShaderResourceViewDescription srvDesc = new ShaderResourceViewDescription();

                srvDesc.Format    = tex0.Srv.Description.Format;
                srvDesc.Dimension = ShaderResourceViewDimension.Texture2DArray;
                srvDesc.Texture2DArray.ArraySize       = m_sourceTextures.Count;
                srvDesc.Texture2DArray.FirstArraySlice = 0;
                srvDesc.Texture2DArray.MipLevels       = tex0.Srv.Description.Texture2D.MipLevels;
                srvDesc.Texture2DArray.MostDetailedMip = 0;
                m_srv           = new ShaderResourceView(MyRender11.Device, m_resource, srvDesc);
                m_srv.DebugName = m_debugName;

                int i = 0;

                foreach (ISrvBindable tex in m_sourceTextures)
                {
                    Texture2D tex2 = (Texture2D)tex.Resource;
                    if (tex2 == null)
                    {
                        MyRenderProxy.Assert(false, "Array texture is created using resource that is not texture2d");
                        i++;
                        continue;
                    }
                    Texture2DDescription texDesc2 = tex2.Description;
                    MyRenderProxy.Assert(MyArrayTextureManager.CheckArrayCompatible(texDesc, texDesc2),
                                         "Incompatible texture is used to create array texture");

                    int mipmaps = tex.Srv.Description.Texture2D.MipLevels;
                    for (int m = 0; m < mipmaps; m++)
                    {
                        MyRender11.RC.CopySubresourceRegion(tex.Resource,
                                                            Resource.CalculateSubResourceIndex(m, 0, mipmaps), null, Resource,
                                                            Resource.CalculateSubResourceIndex(m, i, mipmaps));
                    }
                    i++;
                }
            }
        private void DestroyCascadeTextures()
        {
            MyRender11.Log.WriteLine("DestroyCascadeTextures");
            MyRender11.Log.IncreaseIndent();

            MyArrayTextureManager arrayManager = MyManagers.ArrayTextures;

            arrayManager.DisposeTex(ref m_cascadeShadowmapArray);
            arrayManager.DisposeTex(ref m_cascadeShadowmapBackup);

            m_cascadesReferenceCount = Math.Max(m_cascadesReferenceCount - 1, 0);
            arrayManager.DisposeTex(ref m_combinedShadowmapArray);

            MyRender11.Log.DecreaseIndent();
        }
Beispiel #4
0
        internal static void ReleaseScreenResources()
        {
            if (m_fullResViewDepthTarget != null)
            {
                MyRwTextureManager rwManager = MyManagers.RwTextures;
                rwManager.DisposeTex(ref m_fullResViewDepthTarget);
                rwManager.DisposeTex(ref m_fullResNormalTexture);
                rwManager.DisposeTex(ref m_fullResAOZTexture);
                rwManager.DisposeTex(ref m_fullResAOZTexture2);

                MyArrayTextureManager arrayManager = MyManagers.ArrayTextures;
                arrayManager.DisposeTex(ref m_quarterResViewDepthTextureArray);
                arrayManager.DisposeTex(ref m_quarterResAOTextureArray);
            }
        }
Beispiel #5
0
        internal static void InitScreenResources()
        {
            MyRwTextureManager rwManager = MyManagers.RwTextures;

            m_fullResViewDepthTarget = rwManager.CreateRtv("MyHBAO.FullResViewDepthTarget", MyRender11.m_resolution.X, MyRender11.m_resolution.Y,
                                                           SharpDX.DXGI.Format.R32_Float, 1, 0);
            m_fullResNormalTexture = rwManager.CreateRtv("MyHBAO.FullResNormalTexture", MyRender11.m_resolution.X, MyRender11.m_resolution.Y,
                                                         SharpDX.DXGI.Format.R8G8B8A8_UNorm, 1, 0);
            m_fullResAOZTexture = rwManager.CreateRtv("MyHBAO.FullResAOZTexture", MyRender11.m_resolution.X, MyRender11.m_resolution.Y,
                                                      SharpDX.DXGI.Format.R16G16_Float, 1, 0);
            m_fullResAOZTexture2 = rwManager.CreateRtv("MyHBAO.FullResAOZTexture2", MyRender11.m_resolution.X, MyRender11.m_resolution.Y,
                                                       SharpDX.DXGI.Format.R16G16_Float, 1, 0);

            MyArrayTextureManager arrayManager = MyManagers.ArrayTextures;

            m_quarterResViewDepthTextureArray = arrayManager.CreateRtvArray("MyHBAO.QuarterResViewDepthTextureArray",
                                                                            DivUp(MyRender11.m_resolution.X, 4), DivUp(MyRender11.m_resolution.Y, 4), NUM_SLICES, SharpDX.DXGI.Format.R16_Float);
            m_quarterResAOTextureArray = arrayManager.CreateRtvArray("MyHBAO.QuarterResAOTextureArray",
                                                                     DivUp(MyRender11.m_resolution.X, 4), DivUp(MyRender11.m_resolution.Y, 4), NUM_SLICES, SharpDX.DXGI.Format.R8_UNorm);
        }
        private void InitCascadeTextures(int cascadeResolution)
        {
            DestroyCascadeTextures();

            MyArrayTextureManager arrayManager = MyManagers.ArrayTextures;

            MyRender11.Log.WriteLine("InitCascadeTextures: " + m_cascadesReferenceCount + " / " + MyScene.SeparateGeometry);
            m_cascadeShadowmapArray = arrayManager.CreateDepthArray("MyShadowCascades.CascadeShadowmapArray",
                                                                    cascadeResolution, cascadeResolution, m_initializedShadowCascadesCount, Format.R32_Typeless, Format.R32_Float, Format.D32_Float);
            m_cascadeShadowmapBackup = arrayManager.CreateDepthArray("MyShadowCascades.CascadeShadowmapBackup",
                                                                     cascadeResolution, cascadeResolution, m_initializedShadowCascadesCount, Format.R32_Typeless, Format.R32_Float, Format.D32_Float);

            if (m_cascadesReferenceCount == 0 && MyScene.SeparateGeometry)
            {
                MyRender11.Log.WriteLine("InitCascadeTextures m_combinedShadowmapArray");
                m_combinedShadowmapArray = arrayManager.CreateDepthArray("MyShadowCascades.CombinedShadowmapArray",
                                                                         cascadeResolution, cascadeResolution, m_initializedShadowCascadesCount, Format.R32_Typeless, Format.R32_Float, Format.D32_Float);
            }

            ++m_cascadesReferenceCount;
        }