internal IBorrowedUavTexture PostProcess(IDepthArrayTexture cascadeArray)
        {
            IBorrowedUavTexture postProcessed = MyManagers.RwTexturesPool.BorrowUav("MyShadowCascades.PostProcess", Format.R8_UNorm);

            m_cascadePostProcessor.GatherArray(postProcessed, cascadeArray, m_cascadeInfo, m_csmConstants);
            return(postProcessed);
        }
Ejemplo n.º 2
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);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        internal void DisposeTex(ref IDepthArrayTexture texture)
        {
            if (texture == null)
            {
                return;
            }

            MyDepthArrayTexture castedTexture = (MyDepthArrayTexture)texture;

            if (m_isDeviceInit)
            {
                castedTexture.OnDeviceEnd();
            }

            m_depthArrays.Deallocate(castedTexture);
            texture = null;
        }
        internal static void Combine(IDepthArrayTexture targetArray, MyShadowCascades firstCascades, MyShadowCascades secondCascades)
        {
            // Not tested at all!

            //if (!MyRender11.Settings.EnableShadows || !MyRender11.DebugOverrides.Shadows)
            //    return;

            //ProfilerShort.Begin("MyShadowCascadesPostProcess.Combine");
            //MyGpuProfiler.IC_BeginBlock("MyShadowCascadesPostProcess.Combine");

            //firstCascades.FillConstantBuffer(firstCascades.CascadeConstantBuffer);
            //secondCascades.FillConstantBuffer(secondCascades.CascadeConstantBuffer);
            //secondCascades.PostProcessor.MarkCascadesInStencil(secondCascades.CascadeInfo);

            //MyRenderContext renderContext = MyRenderContext.Immediate;
            //DeviceContext deviceContext = renderContext.DeviceContext;

            //deviceContext.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            //deviceContext.PixelShader.SetConstantBuffer(10, firstCascades.CascadeConstantBuffer);
            //deviceContext.PixelShader.SetConstantBuffer(11, secondCascades.CascadeConstantBuffer);
            //deviceContext.PixelShader.SetConstantBuffer(12, m_inverseConstants);

            //for (int subresourceIndex = 0; subresourceIndex < targetArray.Description2d.ArraySize; ++subresourceIndex)
            //{
            //    renderContext.BindGBufferForRead(0, MyGBuffer.Main);
            //    deviceContext.OutputMerger.SetTargets((DepthStencilView)null, (RenderTargetView)targetArray.SubresourceRtv(subresourceIndex));
            //    deviceContext.PixelShader.SetShaderResource(0, firstCascades.CascadeShadowmapArray.SubresourceSrv(subresourceIndex));
            //    deviceContext.PixelShader.SetShaderResource(1, secondCascades.CascadeShadowmapArray.Srv);
            //    //deviceContext.PixelShader.SetShaderResource(4, MyGBuffer.Main.DepthStencil.m_SRV_stencil);
            //    renderContext.PixelShader.Set(m_combinePS);

            //    Matrix inverseCascadeMatrix = MatrixD.Transpose(MatrixD.Invert(firstCascades.CascadeInfo[subresourceIndex].CurrentLocalToProjection * MyMatrixHelpers.ClipspaceToTexture));
            //    var mapping = MyMapping.MapDiscard(m_inverseConstants);
            //    mapping.WriteAndPosition(ref inverseCascadeMatrix);
            //    mapping.Unmap();

            //    MyScreenPass.DrawFullscreenQuad(new MyViewport(0, 0, targetArray.Description2d.Width, targetArray.Description2d.Height));
            //}

            //deviceContext.OutputMerger.SetTargets(null as DepthStencilView, null as RenderTargetView);
            //deviceContext.PixelShader.SetShaderResource(0, null);
            //deviceContext.PixelShader.SetShaderResource(1, null);
            //deviceContext.PixelShader.SetShaderResource(2, null);
            //MyGpuProfiler.IC_EndBlock();
            //ProfilerShort.End();
        }
Ejemplo n.º 5
0
            public void Init(int texSize, int numSlices)
            {
                m_volumes = new MyShadowVolume[numSlices];
                for (int i = 0; i < numSlices; i++)
                {
                    m_volumes[i] = new MyShadowVolume();
                }

                m_slices = new MyCascadeShadowMapSlice[numSlices];
                for (int i = 0; i < numSlices; i++)
                {
                    m_slices[i] = new MyCascadeShadowMapSlice();
                    m_slices[i].Init(m_volumes[i], texSize);
                }

                m_depthArrayTexture = MyManagers.ArrayTextures.CreateDepthArray("MyCascadeShadowMap.DepthArrayTexture", texSize, texSize, numSlices,
                                                                                Format.R32_Typeless, Format.R32_Float, Format.D32_Float);

                CsmPlacementStrategy = m_csmDefaultPlacementStrategy;
            }
        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;
        }
Ejemplo n.º 7
0
            public void Init(int texSize, int numSlices)
            {
                m_volumes = new MyShadowVolume[numSlices];
                for (int i = 0; i < numSlices; i++)
                {
                    m_volumes[i] = new MyShadowVolume();
                }

                m_slices = new MyCascadeShadowMapSlice[numSlices];
                for (int i = 0; i < numSlices; i++)
                {
                    m_slices[i] = new MyCascadeShadowMapSlice();
                    m_slices[i].Init(m_volumes[i], texSize);
                }

                m_depthArrayTexture = MyManagers.ArrayTextures.CreateDepthArray("MyCascadeShadowMap.DepthArrayTexture", texSize, texSize, numSlices,
                    Format.R32_Typeless, Format.R32_Float, Format.D32_Float);

                CsmPlacementStrategy = m_csmDefaultPlacementStrategy;
            }
        internal static void Combine(IDepthArrayTexture targetArray, MyShadowCascades firstCascades, MyShadowCascades secondCascades)
        {
            // Not tested at all!

            //if (!MyRender11.Settings.EnableShadows || !MyRender11.DebugOverrides.Shadows)
            //    return;

            //ProfilerShort.Begin("MyShadowCascadesPostProcess.Combine");
            //MyGpuProfiler.IC_BeginBlock("MyShadowCascadesPostProcess.Combine");

            //firstCascades.FillConstantBuffer(firstCascades.CascadeConstantBuffer);
            //secondCascades.FillConstantBuffer(secondCascades.CascadeConstantBuffer);
            //secondCascades.PostProcessor.MarkCascadesInStencil(secondCascades.CascadeInfo);

            //MyRenderContext renderContext = MyRenderContext.Immediate;
            //DeviceContext deviceContext = renderContext.DeviceContext;

            //deviceContext.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            //deviceContext.PixelShader.SetConstantBuffer(10, firstCascades.CascadeConstantBuffer);
            //deviceContext.PixelShader.SetConstantBuffer(11, secondCascades.CascadeConstantBuffer);
            //deviceContext.PixelShader.SetConstantBuffer(12, m_inverseConstants);

            //for (int subresourceIndex = 0; subresourceIndex < targetArray.Description2d.ArraySize; ++subresourceIndex)
            //{
            //    renderContext.BindGBufferForRead(0, MyGBuffer.Main);
            //    deviceContext.OutputMerger.SetTargets((DepthStencilView)null, (RenderTargetView)targetArray.SubresourceRtv(subresourceIndex));
            //    deviceContext.PixelShader.SetShaderResource(0, firstCascades.CascadeShadowmapArray.SubresourceSrv(subresourceIndex));
            //    deviceContext.PixelShader.SetShaderResource(1, secondCascades.CascadeShadowmapArray.Srv);
            //    //deviceContext.PixelShader.SetShaderResource(4, MyGBuffer.Main.DepthStencil.m_SRV_stencil);
            //    renderContext.PixelShader.Set(m_combinePS);

            //    Matrix inverseCascadeMatrix = MatrixD.Transpose(MatrixD.Invert(firstCascades.CascadeInfo[subresourceIndex].CurrentLocalToProjection * MyMatrixHelpers.ClipspaceToTexture));
            //    var mapping = MyMapping.MapDiscard(m_inverseConstants);
            //    mapping.WriteAndPosition(ref inverseCascadeMatrix);
            //    mapping.Unmap();

            //    MyScreenPass.DrawFullscreenQuad(new MyViewport(0, 0, targetArray.Description2d.Width, targetArray.Description2d.Height));
            //}

            //deviceContext.OutputMerger.SetTargets(null as DepthStencilView, null as RenderTargetView);
            //deviceContext.PixelShader.SetShaderResource(0, null);
            //deviceContext.PixelShader.SetShaderResource(1, null);
            //deviceContext.PixelShader.SetShaderResource(2, null);
            //MyGpuProfiler.IC_EndBlock();
            //ProfilerShort.End();
        }
Ejemplo n.º 9
0
 internal static void DrawDepthArrayTexture(IDepthArrayTexture tex, int quadStartX, int quadStartY, int quadSize)
 {
     DrawSrvArrayTexture(tex, tex.NumSlices, quadStartX, quadStartY, quadSize);
 }
Ejemplo n.º 10
0
        internal void DisposeTex(ref IDepthArrayTexture texture)
        {
            if (texture == null)
                return;

            MyDepthArrayTexture castedTexture = (MyDepthArrayTexture)texture;

            if (m_isDeviceInit)
                castedTexture.OnDeviceEnd();

            m_depthArrays.Deallocate(castedTexture);
            texture = null;
        }
Ejemplo n.º 11
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);
                }
            }
        }
Ejemplo n.º 12
0
 internal static void DrawDepthArrayTexture(IDepthArrayTexture tex, int quadStartX, int quadStartY, int quadSize)
 {
     DrawSrvArrayTexture(tex, tex.NumSlices, quadStartX, quadStartY, quadSize);
 }
Ejemplo n.º 13
0
 internal IBorrowedUavTexture PostProcess(IDepthArrayTexture cascadeArray)
 {
     IBorrowedUavTexture postProcessed = MyManagers.RwTexturesPool.BorrowUav("MyShadowCascades.PostProcess", Format.R8_UNorm);
     m_cascadePostProcessor.GatherArray(postProcessed, cascadeArray, m_cascadeInfo, m_csmConstants);
     return postProcessed;
 }
Ejemplo n.º 14
0
        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;
        }