示例#1
0
        public Matrix4 MapSingle(ShadowMapQuality quality, TransformationManager transformation, float angle, float cutoff)
        {
            Camera last = Camera.Current;

            SingleCamera.UpdatePerspective(1, angle, 0.01f, cutoff);
            SingleCamera.Transformation = transformation;
            SingleCamera.Update();
            SingleCamera.Transformation.ClearModifiedFlag();

            Camera.Current = SingleCamera;
            if (quality == ShadowMapQuality.High)
            {
                SpotHighQuality.Use();
            }
            if (quality == ShadowMapQuality.Medium)
            {
                SpotMediumQuality.Use();
            }
            if (quality == ShadowMapQuality.Low)
            {
                SpotLowQuality.Use();
            }

            RenderWorld();

            Camera.Current = last;
            return(SingleCamera.GetVPMatrix());
        }
示例#2
0
        private void Bloom()
        {
            BloomYPass.Use();
            BloomXPass.Use();

            BlitFramebuffers(CombinerFramebuffer, BloomYPass, BlitMode.Color);
            // here Y has deferred data, X is empty
            BloomShader.Use();
            SetUniformsShared();

            BloomShader.SetUniform("Pass", 0);
            BloomYPass.UseTexture(11);
            BloomXPass.Use();
            PostProcessingMesh.Draw();
            // here Y has deferred data, X has 1 pass result

            BloomYPass.Use();
            // here Y is empty, x has 1 pass
            BloomShader.SetUniform("Pass", 1);
            BloomXPass.UseTexture(11);
            PostProcessingMesh.Draw();
            // here y has 2 pass data
        }
示例#3
0
        public void RenderToFramebuffer(Framebuffer framebuffer)
        {
            if (Camera.Current == null)
            {
                return;
            }
            Width  = framebuffer.Width;
            Height = framebuffer.Height;

            RenderPrepareToBlit();

            framebuffer.Use(false, false);
            GL.Viewport(0, 0, framebuffer.Width, framebuffer.Height);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            HDR();
        }
示例#4
0
        public void RenderToFramebuffer(Framebuffer framebuffer)
        {
            if(Camera.Current == null)
                return;
            Game.World.Scene.RecreateSimpleLightsSSBO();
            Width = framebuffer.Width;
            Height = framebuffer.Height;

            RenderPrepareToBlit();

            framebuffer.Use(false, false);
            GL.Viewport(0, 0, framebuffer.Width, framebuffer.Height);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            HDR();
        }
示例#5
0
 private void SwitchToFB(Framebuffer buffer)
 {
     buffer.Use();
 }
示例#6
0
 private void SwitchToFB(Framebuffer buffer)
 {
     buffer.Use();
 }
示例#7
0
 private void SwitchToFB(Framebuffer buffer)
 {
     buffer.Use();
     if(buffer == Pass1FrameBuffer || buffer == Pass2FrameBuffer)
     {
         LastFrameBuffer.UseTexture(0);
         LastFrameBuffer = buffer;
     }
 }
示例#8
0
        public PostProcessing(int initialWidth, int initialHeight)
        {
            //FullScene3DTexture = new Texture3D(new Vector3(64, 64, 64));
            TestBuffer = new ShaderStorageBuffer();
            NumbersTexture = new Texture(Media.Get("numbers.png"));
            CShader = new ComputeShader("Blur.compute.glsl");
            GLThread.Invoke(() =>
            {
                TestBuffer.MapData(new Vector3[4]{
                    new Vector3(1, 0.25f, 1), new Vector3(0, 0.55f, 0.75f),
                    new Vector3(1, 0.25f, 0), new Vector3(0.55f, 0, 0.75f)
                });

            });
            Width = initialWidth;
            Height = initialHeight;
            MSAAResolvingFrameBuffer = new Framebuffer(initialWidth, initialHeight);
            MSAAResolvingFrameBuffer.SetMultiSample(true);

            MRT = new MRTFramebuffer(initialWidth, initialHeight);
            BackMRT = new MRTFramebuffer(initialWidth / 4, initialHeight / 4);

            Pass1FrameBuffer = new Framebuffer(initialWidth, initialHeight);
            Pass2FrameBuffer = new Framebuffer(initialWidth, initialHeight);

            LightPointsFrameBuffer = new Framebuffer(initialWidth / 6, initialHeight / 6);
            BloomFrameBuffer = new Framebuffer(initialWidth / 4, initialHeight / 4);
            FogFramebuffer = new Framebuffer(initialWidth, initialHeight);
            SmallFrameBuffer = new Framebuffer(initialWidth / 10, initialHeight / 10);
            LastWorldPositionFramebuffer = new Framebuffer(initialWidth / 1, initialHeight / 1);
            RSMFramebuffer = new Framebuffer(initialWidth / 1, initialHeight / 1);
            SSReflectionsFramebuffer = new Framebuffer(initialWidth / 1, initialHeight / 1);
            VDAOFramebuffer = new Framebuffer(initialWidth / 1, initialHeight / 1);

            GlobalIlluminationFrameBuffer = new Framebuffer(initialWidth, initialHeight);
            //GlobalIlluminationFrameBuffer.ColorInternalFormat = PixelInternalFormat.R8;
            //GlobalIlluminationFrameBuffer.ColorPixelFormat = PixelFormat.Red;
            //GlobalIlluminationFrameBuffer.ColorPixelType = PixelType.UnsignedByte;
            GlobalIlluminationFrameBuffer.Use();
            //BackDiffuseFrameBuffer = new Framebuffer(initialWidth / 2, initialHeight  / 2);
            //BackNormalsFrameBuffer = new Framebuffer(initialWidth / 2, initialHeight / 2);

            ScreenSpaceNormalsWriterShader = ShaderProgram.Compile("Generic.vertex.glsl", "ScreenSpaceNormalsWriter.fragment.glsl");
            BackDepthWriterShader = ShaderProgram.Compile("Generic.vertex.glsl", "BackDepthWriter.fragment.glsl");

            BloomShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "Bloom.fragment.glsl");
            MSAAShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "MSAA.fragment.glsl");
            SSAOShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "SSAO.fragment.glsl");
            FogShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "Fog.fragment.glsl");
            LightPointsShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "LightPoints.fragment.glsl");
            LensBlurShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "LensBlur.fragment.glsl");
            HDRShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "HDR.fragment.glsl");
            BlitShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "Blit.fragment.glsl");
            DeferredShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "Deferred.fragment.glsl");
            CombinerShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "Combiner.fragment.glsl");
            PathTracerOutputShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "Output.fragment.glsl");
            GlobalIlluminationShaderX = ShaderProgram.Compile("PostProcess.vertex.glsl", "GlobalIllumination.fragment.glsl");
            GlobalIlluminationShaderX.SetGlobal("SEED", "gl_FragCoord.x");
            GlobalIlluminationShaderY = ShaderProgram.Compile("PostProcess.vertex.glsl", "GlobalIllumination.fragment.glsl");
            GlobalIlluminationShaderY.SetGlobal("SEED", "gl_FragCoord.y");
            RSMShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "RSM.fragment.glsl");
            SSReflectionsShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "SSReflections.fragment.glsl");
            VDAOShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "VDAO.fragment.glsl");
            //ReflectShader = ShaderProgram.Compile(Media.ReadAllText("PostProcess.vertex.glsl"), Media.ReadAllText("Reflect.fragment.glsl"));

            Object3dInfo postPlane3dInfo = new Object3dInfo(postProcessingPlaneVertices, postProcessingPlaneIndices);
            PostProcessingMesh = new Mesh3d(postPlane3dInfo, new GenericMaterial(Color.Pink));
        }
示例#9
0
        public List <Voxel> Voxelize(Object3dManager objinfo, int gridSize)
        {
            List <Voxel> voxels = new List <Voxel>();
            List <byte>  bytes  = new List <byte>();
            var          dv3    = new Vector3(gridSize, gridSize, gridSize);

            for (int x = 0; x < gridSize; x++)
            {
                for (int y = 0; y < gridSize; y++)
                {
                    for (int z = 0; z < gridSize; z++)
                    {
                        var voxel = new Voxel();
                        voxel.Minimum = (Vector3.Divide(new Vector3(x, y, z), (float)gridSize) - new Vector3(0.5f)) * 2.0f;
                        voxel.Maximum = (Vector3.Divide(new Vector3(x + 1, y + 1, z + 1), (float)gridSize) - new Vector3(0.5f)) * 2.0f;
                        voxels.Add(voxel);
                        bytes.AddRange(BitConverter.GetBytes((uint)0));
                        bytes.AddRange(BitConverter.GetBytes((int)0));
                        bytes.AddRange(BitConverter.GetBytes((int)0));
                        bytes.AddRange(BitConverter.GetBytes((int)0));
                    }
                }
            }
            BoxesSSBO.MapData(bytes.ToArray());
            // yay
            Vector3 transFromCenter = objinfo.GetAverageTranslationFromZero();

            objinfo.OriginToCenter();
            float divisor = objinfo.GetNormalizeDivisor();
            var   v3aabb  = objinfo.GetAxisAlignedBox();

            //objinfo.Normalize();
            objinfo.AxisDivide(v3aabb);
            DrawingFramebuffer.Use();
            GL.Disable(EnableCap.DepthTest);
            GL.Disable(EnableCap.CullFace);
            GL.ColorMask(true, false, false, false);
            VoxelizerShader.Use();
            //VoxelizerShader.SetUniform("NormalizationDivisor", 1.0f / divisor);
            // VoxelizerShader.SetUniform("CenterToZero", transFromCenter);
            BoxesSSBO.Use(9);
            var ob3d = new Object3dInfo(objinfo.Vertices);

            VoxelizerShader.SetUniform("Grid", gridSize);
            VoxelizerShader.SetUniform("Pass", 0);
            ob3d.Draw();/*
                         * VoxelizerShader.SetUniform("Pass", 1);
                         * ob3d.Draw();
                         * VoxelizerShader.SetUniform("Pass", 2);
                         * ob3d.Draw();*/
            GL.MemoryBarrier(MemoryBarrierFlags.ShaderStorageBarrierBit);
            var resultBytes = BoxesSSBO.Read(0, bytes.Count);
            int cursor      = 0;
            int i           = 0;
            var newVoxels   = new List <Voxel>();

            for (int x = 0; x < gridSize; x++)
            {
                for (int y = 0; y < gridSize; y++)
                {
                    for (int z = 0; z < gridSize; z++)
                    {
                        uint hit = BitConverter.ToUInt32(resultBytes, cursor);
                        int  nrx = BitConverter.ToInt32(resultBytes, cursor + 4);
                        int  nry = BitConverter.ToInt32(resultBytes, cursor + 8);
                        int  nrz = BitConverter.ToInt32(resultBytes, cursor + 12);
                        cursor += 4 * 4;
                        if (hit > 0)
                        {
                            float fnrx = (float)nrx / (float)hit;
                            float fnry = (float)nry / (float)hit;
                            float fnrz = (float)nrz / (float)hit;
                            if (hit > 65536)
                            {
                                hit = 65536;
                            }
                            float dens = (float)hit / (float)65536;
                            voxels[i].Maximum *= v3aabb;
                            voxels[i].Minimum *= v3aabb;
                            voxels[i].Maximum += transFromCenter;
                            voxels[i].Minimum += transFromCenter;
                            voxels[i].Density  = dens;
                            voxels[i].Normal   = new Vector3(fnrx / 128.0f, fnry / 128.0f, fnrz / 128.0f);
                            newVoxels.Add(voxels[i]);
                        }
                        i++;
                    }
                }
            }
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);
            GL.ColorMask(true, true, true, true);
            return(newVoxels);
        }
示例#10
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;
        }