Esempio n. 1
0
 public ProjectionLight(Vector3 position, Quaternion rotation, int mapwidth, int mapheight, float fov, float near, float far)
 {
     camera = new Camera(position, Vector3.Zero, Vector3.UnitY, mapwidth / mapheight, fov, near, far);
     camera.LookAt(Vector3.Zero);
     FBO = new Framebuffer(mapwidth, mapheight, true);
     FBO.DepthInternalFormat = PixelInternalFormat.DepthComponent32f;
     FBO.DepthPixelFormat = PixelFormat.DepthComponent;
     FBO.DepthPixelType = PixelType.Float;
 }
Esempio n. 2
0
 public ProjectionLight(Vector3 position, Quaternion rotation, int mapwidth, int mapheight, float fov, float near, float far)
 {
     FarPlane = far;
     camera = new Camera(position, Vector3.Zero, mapwidth / mapheight, fov, near, far);
     camera.LookAt(Vector3.Zero);
     FBO = new Framebuffer(mapwidth, mapheight, true);
     //FBO.ColorInternalFormat = PixelInternalFormat.Rgba8;
     //FBO.ColorPixelFormat = PixelFormat.Rgba;
     //FBO.ColorPixelType = PixelType.UnsignedByte;
     Shader = GenericMaterial.FromName("ConeLight");
     ViewPort = new Size(mapwidth, mapheight);
 }
Esempio n. 3
0
 public PassiveVoxelizer()
 {
     VoxelizerShader = ShaderProgram.Compile("Voxelizer.vertex.glsl", "Voxelizer.fragment.glsl");
     BoxesSSBO = new ShaderStorageBuffer();
     DrawingFramebuffer = new Framebuffer(256, 256, false)
     {
         ColorOnly = true,
         ColorInternalFormat = PixelInternalFormat.R8,
         ColorPixelType = PixelType.Byte,
         ColorPixelFormat = PixelFormat.Red
     };
 }
Esempio n. 4
0
        public Renderer(int initialWidth, int initialHeight)
        {
            

            CubeMap = new CubeMapTexture(Media.Get("posx.jpg"), Media.Get("posy.jpg"), Media.Get("posz.jpg"),
                Media.Get("negx.jpg"), Media.Get("negy.jpg"), Media.Get("negz.jpg"));

            Width = initialWidth;
            Height = initialHeight;
            //   initialWidth *= 4; initialHeight *= 4;
            MRT = new MRTFramebuffer(initialWidth, initialHeight);
            
            DistanceFramebuffer = new Framebuffer(initialWidth / 1, initialHeight / 1)
            {
                ColorOnly = false,
                ColorInternalFormat = PixelInternalFormat.R32f,
                ColorPixelFormat = PixelFormat.Red,
                ColorPixelType = PixelType.Float
            };

            HDRShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "HDR.fragment.glsl");
            
            PostProcessingMesh = new Object3dInfo(VertexInfo.FromFloatArray(postProcessingPlaneVertices));
        }
Esempio n. 5
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();
        }
Esempio n. 6
0
 private void SwitchToFB(Framebuffer buffer)
 {
     buffer.Use();
 }
Esempio n. 7
0
 private void SwitchToFB(Framebuffer buffer)
 {
     buffer.Use();
 }
Esempio n. 8
0
        private void CreateBuffers()
        {
            MRT = new MRTFramebuffer(Width, Height, Samples);

            VXGIFramebuffer = new Framebuffer(Width / 1, Height / 1)
            {
                ColorOnly           = true,
                ColorInternalFormat = PixelInternalFormat.Rgba16f,
                ColorPixelFormat    = PixelFormat.Rgba,
                ColorPixelType      = PixelType.HalfFloat
            };
            DeferredFramebuffer = new Framebuffer(Width / 1, Height / 1)
            {
                ColorOnly           = true,
                ColorInternalFormat = PixelInternalFormat.Rgba16f,
                ColorPixelFormat    = PixelFormat.Rgba,
                ColorPixelType      = PixelType.HalfFloat
            };
            HelperFramebuffer = new Framebuffer(Width / 1, Height / 1)
            {
                ColorOnly           = true,
                ColorInternalFormat = PixelInternalFormat.Rgba16f,
                ColorPixelFormat    = PixelFormat.Rgba,
                ColorPixelType      = PixelType.HalfFloat
            };
            CombinerFramebuffer = new Framebuffer(Width / 1, Height / 1)
            {
                ColorOnly           = true,
                ColorInternalFormat = PixelInternalFormat.Rgba16f,
                ColorPixelFormat    = PixelFormat.Rgba,
                ColorPixelType      = PixelType.HalfFloat
            };
            ForwardPassFramebuffer = new Framebuffer(Width / 1, Height / 1)
            {
                ColorOnly           = false,
                ColorInternalFormat = PixelInternalFormat.Rgba16f,
                ColorPixelFormat    = PixelFormat.Rgba,
                ColorPixelType      = PixelType.HalfFloat
            };
            EnvLightFramebuffer = new Framebuffer(Width / 1, Height / 1)
            {
                ColorOnly           = true,
                ColorInternalFormat = PixelInternalFormat.Rgba16f,
                ColorPixelFormat    = PixelFormat.Rgba,
                ColorPixelType      = PixelType.HalfFloat
            };
            BloomXPass = new Framebuffer(Width / 4, Height / 4)
            {
                ColorOnly           = true,
                ColorInternalFormat = PixelInternalFormat.Rgba16f,
                ColorPixelFormat    = PixelFormat.Rgba,
                ColorPixelType      = PixelType.HalfFloat
            };
            BloomYPass = new Framebuffer(Width / 4, Height / 4)
            {
                ColorOnly           = true,
                ColorInternalFormat = PixelInternalFormat.Rgba16f,
                ColorPixelFormat    = PixelFormat.Rgba,
                ColorPixelType      = PixelType.HalfFloat
            };
            AmbientOcclusionFramebuffer = new Framebuffer(Width / 1, Height / 1)
            {
                ColorOnly           = true,
                ColorInternalFormat = PixelInternalFormat.R8,
                ColorPixelFormat    = PixelFormat.Red,
                ColorPixelType      = PixelType.UnsignedByte
            };
            FogFramebuffer = new Framebuffer(Width / 2, Height / 2)
            {
                ColorOnly           = true,
                ColorInternalFormat = PixelInternalFormat.Rgba8,
                ColorPixelFormat    = PixelFormat.Rgba,
                ColorPixelType      = PixelType.UnsignedByte
            };
        }
Esempio n. 9
0
 private Framebuffer SwitchToFB2()
 {
     Pass2FrameBuffer.Use();
     if(LastFrameBuffer != null)
         LastFrameBuffer.UseTexture(0);
     LastFrameBuffer = Pass2FrameBuffer;
     return Pass2FrameBuffer;
 }
Esempio n. 10
0
 private void SwitchToFB(Framebuffer buffer)
 {
     buffer.Use();
     if(buffer == Pass1FrameBuffer || buffer == Pass2FrameBuffer)
     {
         LastFrameBuffer.UseTexture(0);
         LastFrameBuffer = buffer;
     }
 }
Esempio n. 11
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));
        }
Esempio n. 12
0
        public Voxel3dTextureWriter(int gridsizeX, int gridsizeY, int gridsizeZ, Vector3 boxsize, Vector3 staticPosition)
        {
            GridSizeX             = gridsizeX;
            GridSizeY             = gridsizeY;
            GridSizeZ             = gridsizeZ;
            MapPosition           = staticPosition;
            BoxSize               = boxsize;
            TextureResolverShader = new ComputeShader("Texture3DResolve.compute.glsl");
            //TextureResolverNormalShader = new ComputeShader("Texture3DResolveNormal.compute.glsl");
            TextureMipmapShader = new ComputeShader("Texture3DMipmap.compute.glsl");

            TextureRed   = new Texture3D(gridsizeX, gridsizeY, gridsizeZ);
            TextureGreen = new Texture3D(gridsizeX, gridsizeY, gridsizeZ);
            TextureBlue  = new Texture3D(gridsizeX, gridsizeY, gridsizeZ);

            /*
             * TextureNormalX = new Texture3D(gridsize, gridsize, gridsize)
             * {
             *  ColorInternalFormat = PixelInternalFormat.R32i,
             *  ColorPixelFormat = PixelFormat.RedInteger,
             *  ColorPixelType = PixelType.Int
             * };
             * TextureNormalY = new Texture3D(gridsize, gridsize, gridsize)
             * {
             *  ColorInternalFormat = PixelInternalFormat.R32i,
             *  ColorPixelFormat = PixelFormat.RedInteger,
             *  ColorPixelType = PixelType.Int
             * };
             * TextureNormalZ = new Texture3D(gridsize, gridsize, gridsize)
             * {
             *  ColorInternalFormat = PixelInternalFormat.R32i,
             *  ColorPixelFormat = PixelFormat.RedInteger,
             *  ColorPixelType = PixelType.Int
             * };
             * TextureNormalResolved = new Texture3D(gridsize, gridsize, gridsize)
             * {
             *  ColorInternalFormat = PixelInternalFormat.Rgba16f,
             *  ColorPixelFormat = PixelFormat.Rgba,
             *  ColorPixelType = PixelType.HalfFloat
             * };
             */
            TextureCount = new Texture3D(gridsizeX, gridsizeY, gridsizeZ);

            /*
             * TEXTURE LAYOUT:
             * 1 - Initial - RES / 1 - 256
             * 2 - Blurred 2 PX 1 res / 2 128
             * 3 - Blurred 2 PX 2 res / 2 64
             * 4 - Blurred 2 PX 3 res / 2 32
             */

            TextureResolvedMipMaps = new List <Texture3D>();
            int szx = gridsizeX;
            int szy = gridsizeY;
            int szz = gridsizeZ;

            //while(szx > 8 && szy > 8 && szz > 8)
            for (int i = 0; i < 4; i++)
            {
                TextureResolvedMipMaps.Add(new Texture3D(szx, szy, szz)
                {
                    ColorInternalFormat = PixelInternalFormat.Rgba16f,
                    ColorPixelFormat    = PixelFormat.Rgba,
                    ColorPixelType      = PixelType.HalfFloat
                });
                szx = szx / 2;
                szy = szy / 2;
                szz = szz / 2;
            }

            FBO = new Framebuffer(512, 512, true)
            {
            };

            XForward = Matrix4.LookAt(Vector3.Zero, Vector3.UnitX, Vector3.UnitY).ExtractRotation();
            YForward = Matrix4.LookAt(Vector3.Zero, Vector3.UnitY, Vector3.UnitZ).ExtractRotation();
            ZForward = Matrix4.LookAt(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY).ExtractRotation();

            Vector3 boxhalf = boxsize * 0.5f;


            RenderingCameraX = new Camera();
            RenderingCameraX.UpdatePerspectiveOrtho(-boxhalf.X, boxhalf.X, -boxhalf.Y, boxhalf.Y, boxhalf.Z, -boxhalf.Z);
            RenderingCameraX.SetOrientation(XForward);
            RenderingCameraX.SetPosition(MapPosition);
            RenderingCameraX.Update();

            RenderingCameraY = new Camera();
            RenderingCameraY.UpdatePerspectiveOrtho(-boxhalf.X, boxhalf.X, -boxhalf.Z, boxhalf.Z, boxhalf.Y, -boxhalf.Y);
            RenderingCameraY.SetOrientation(YForward);
            RenderingCameraY.SetPosition(MapPosition);
            RenderingCameraY.Update();

            RenderingCameraZ = new Camera();
            RenderingCameraZ.UpdatePerspectiveOrtho(-boxhalf.X, boxhalf.X, -boxhalf.Y, boxhalf.Y, boxhalf.Z, -boxhalf.Z);
            RenderingCameraZ.SetOrientation(ZForward);
            RenderingCameraZ.SetPosition(MapPosition);
            RenderingCameraZ.Update();

            Shader = new ShaderPool.ShaderPack("Voxel3dTextureWriter.fragment.glsl");
        }