コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                DisposePSO();

                TextureWhite.Dispose();
                TextureBlack.Dispose();
                TextureRed.Dispose();
                TextureGreen.Dispose();
                TextureBlue.Dispose();

                vertexBuffer.Dispose();
                indexBuffer.Dispose();
                shader.Dispose();
                constBuffer.Dispose();
            }

            base.Dispose(disposing);
        }
コード例 #2
0
        public void Map()
        {
            var lastCamera = Camera.Current;

            var lights = Game.World.Scene.GetLights();

            var light = lights[0];

            for (int i = 0; i < Shader.ProgramsList.Length; i++)
            {
                var s = Shader.ProgramsList[i];
                if (!s.Compiled)
                {
                    continue;
                }
                s.Use();
                s.SetUniform("GridSizeX", GridSizeX);
                s.SetUniform("GridSizeY", GridSizeY);
                s.SetUniform("GridSizeZ", GridSizeZ);
                s.SetUniform("BoxSize", BoxSize);
                s.SetUniform("MapPosition", -MapPosition);
                light.SetUniforms();
                light.BindShadowMap(20, 21);
                SetUniforms();
                BindTexture(TextureUnit.Texture25);
            }

            TextureRed.Clear();
            TextureGreen.Clear();
            TextureBlue.Clear();
            TextureCount.Clear();
            //TextureResolved.Clear();

            FBO.Use();
            GL.Disable(EnableCap.DepthTest);
            GL.Disable(EnableCap.CullFace);
            TextureRed.BindImageUnit(6, TextureAccess.ReadWrite, SizedInternalFormat.R32ui);
            TextureGreen.BindImageUnit(1, TextureAccess.ReadWrite, SizedInternalFormat.R32ui);
            TextureBlue.BindImageUnit(2, TextureAccess.ReadWrite, SizedInternalFormat.R32ui);
            TextureCount.BindImageUnit(3, TextureAccess.ReadWrite, SizedInternalFormat.R32ui);

            /*
             * TextureNormalX.BindImageUnit(7, TextureAccess.ReadWrite, SizedInternalFormat.R32i);
             * TextureNormalY.BindImageUnit(8, TextureAccess.ReadWrite, SizedInternalFormat.R32i);
             * TextureNormalZ.BindImageUnit(9, TextureAccess.ReadWrite, SizedInternalFormat.R32i);
             */
            //  Camera.Current = RenderingCameraX;
            //  RenderWorld();

            Camera.Current = RenderingCameraX;
            RenderingCameraX.SetOrientation(XForward);
            RenderingCameraX.Update();
            RenderingCameraX.Transformation.ClearModifiedFlag();
            RenderWorld();

            Camera.Current = RenderingCameraY;
            RenderingCameraY.SetOrientation(YForward);
            RenderingCameraY.Update();
            RenderingCameraY.Transformation.ClearModifiedFlag();
            RenderWorld();

            Camera.Current = RenderingCameraZ;
            RenderingCameraZ.SetOrientation(ZForward);
            RenderingCameraZ.Update();
            RenderingCameraZ.Transformation.ClearModifiedFlag();
            RenderWorld();

            //  Camera.Current = RenderingCameraZ;
            // RenderWorld();

            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);
            GL.MemoryBarrier(MemoryBarrierFlags.ShaderImageAccessBarrierBit);
            TextureResolvedMipMaps[0].BindImageUnit(4, TextureAccess.WriteOnly, SizedInternalFormat.Rgba16f);

            TextureRed.Use(TextureUnit.Texture0);
            TextureGreen.Use(TextureUnit.Texture1);
            TextureBlue.Use(TextureUnit.Texture2);
            TextureCount.Use(TextureUnit.Texture3);

            TextureResolverShader.Use();
            TextureResolverShader.Dispatch(GridSizeX / 16, GridSizeY / 8, GridSizeZ / 8);
            GL.MemoryBarrier(MemoryBarrierFlags.ShaderImageAccessBarrierBit);

            /*
             * TextureNormalX.Use(TextureUnit.Texture0);
             * TextureNormalY.Use(TextureUnit.Texture1);
             * TextureNormalZ.Use(TextureUnit.Texture2);
             * TextureCount.Use(TextureUnit.Texture3);
             * TextureNormalResolved.BindImageUnit(10, TextureAccess.ReadWrite, SizedInternalFormat.Rgba16f);
             *
             * TextureResolverNormalShader.Use();
             * TextureResolverNormalShader.Dispatch(GridSize / 16, GridSize / 8, GridSize / 8);
             */

            TextureMipmapShader.Use();
            for (int i = 0; i < TextureResolvedMipMaps.Count - 1; i++)
            {
                TextureResolvedMipMaps[i].Use(TextureUnit.Texture0);
                TextureResolvedMipMaps[i + 1].BindImageUnit(4, TextureAccess.WriteOnly, SizedInternalFormat.Rgba16f);
                TextureMipmapShader.Dispatch(TextureResolvedMipMaps[i + 1].SizeX / 8, TextureResolvedMipMaps[i + 1].SizeY / 8, TextureResolvedMipMaps[i + 1].SizeZ / 8);
                GL.MemoryBarrier(MemoryBarrierFlags.ShaderImageAccessBarrierBit);
            }


            Camera.Current = lastCamera;
        }