public LightManager() { skyboxshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/SkyBoxVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/SkyBoxFragment.glsl", ShaderType.FragmentShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/GammaCorrection.glsl", ShaderType.FragmentShader)) .Link(); ambientlightshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/PostProgressVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/Light/AmbientLightFragment.glsl", ShaderType.FragmentShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/GammaCorrection.glsl", ShaderType.FragmentShader)) .Link(); directionallightshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/PostProgressVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/Light/DirectionalLightFragment.glsl", ShaderType.FragmentShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/GammaCorrection.glsl", ShaderType.FragmentShader)) .Link(); pointlightshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/Light/PointLightVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/Light/PointLightFragment.glsl", ShaderType.FragmentShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/GammaCorrection.glsl", ShaderType.FragmentShader)) .Link(); spotlightshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/Light/SpotLightVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/Light/SpotLightFragment.glsl", ShaderType.FragmentShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/GammaCorrection.glsl", ShaderType.FragmentShader)) .Link(); lightrenderer = new GenericLightRenderer(); }
public LightScatteringRenderer(int width, int height) { skyboxshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/SkyBoxVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/SunSkyBoxFragment.glsl", ShaderType.FragmentShader)) .Link(); radialblurshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/PostProgressVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/RadialBlurFragment.glsl", ShaderType.FragmentShader)) .Link(); finalshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/PostProgressVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/LightScatteringFragment.glsl", ShaderType.FragmentShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/GammaCorrection.glsl", ShaderType.FragmentShader)) .Link(); colortexture = new Texture2D(width / 2, height / 2, PixelInternalFormat.R16, PixelFormat.Red, PixelType.UnsignedByte); colortexture.SetFiltering(TextureMinFilter.Linear, TextureMagFilter.Linear); framebuffer = new Framebuffer() .AttachTexture(colortexture, FramebufferAttachment.ColorAttachment0); framebuffer.CheckStatus(); framebuffer.Unbind(); colortexture2 = new Texture2D(width / 4, height / 4, PixelInternalFormat.R16, PixelFormat.Red, PixelType.UnsignedByte); colortexture2.SetFiltering(TextureMinFilter.Linear, TextureMagFilter.Linear); framebuffer2 = new Framebuffer() .AttachTexture(colortexture2, FramebufferAttachment.ColorAttachment0); framebuffer2.CheckStatus(); framebuffer2.Unbind(); this.width = width; this.height = height; }
private void LoadGame(object sender, EventArgs e) { GL.ClearColor(0, 0, 0, 0); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.ProgramPointSize); GL.Enable(EnableCap.CullFace); GL.PointSize(5); worldshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/WorldVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/WorldFragment.glsl", ShaderType.FragmentShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/WorldGeometry.glsl", ShaderType.GeometryShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/GammaCorrection.glsl", ShaderType.VertexShader)) .Link(); ppshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/PostProgressVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/PostProgressFragment.glsl", ShaderType.FragmentShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/GammaCorrection.glsl", ShaderType.FragmentShader)) .Link(); gaussianblurshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/PostProgressVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/GaussianBlurFragment.glsl", ShaderType.FragmentShader)) .Link(); bloomshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/PostProgressVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/BloomFragment.glsl", ShaderType.FragmentShader)) .Link(); gDepth = new Texture2D(Width, Height, PixelInternalFormat.DepthComponent32f, PixelFormat.DepthComponent, PixelType.Float); gPosition = new Texture2D(Width, Height, PixelInternalFormat.Rgb32f, PixelFormat.Rgb, PixelType.Float); gNormal = new Texture2D(Width, Height, PixelInternalFormat.Rgb16f, PixelFormat.Rgb, PixelType.HalfFloat); gAlbedo = new Texture2D(Width, Height, PixelInternalFormat.Rgb, PixelFormat.Rgb, PixelType.UnsignedByte); gLight = new Texture2D(Width, Height, PixelInternalFormat.Rgb, PixelFormat.Rgb, PixelType.UnsignedByte); gBuffer = new Framebuffer() .AttachTexture(gDepth, FramebufferAttachment.DepthAttachment) .AttachTexture(gPosition, FramebufferAttachment.ColorAttachment0) .AttachTexture(gNormal, FramebufferAttachment.ColorAttachment1) .AttachTexture(gAlbedo, FramebufferAttachment.ColorAttachment2) .AttachTexture(gLight, FramebufferAttachment.ColorAttachment3); GL.DrawBuffers(4, new DrawBuffersEnum[] { DrawBuffersEnum.ColorAttachment0, DrawBuffersEnum.ColorAttachment1, DrawBuffersEnum.ColorAttachment2, DrawBuffersEnum.ColorAttachment3 }); gBuffer.CheckStatus(); gBuffer.Unbind(); lightTexture = new Texture2D(Width, Height, PixelInternalFormat.Rgb16f, PixelFormat.Rgb, PixelType.HalfFloat); lightTexture.SetWarpMode(TextureWrapMode.ClampToEdge); lightBuffer = new Framebuffer() .AttachTexture(lightTexture, FramebufferAttachment.ColorAttachment0); lightBuffer.CheckStatus(); lightBuffer.Unbind(); lightManager = new LightManager(); for (int i = 0; i < 2; i++) { blurTexture[i] = new Texture2D((int)(Width / 2f), (int)(Height / 2f), PixelInternalFormat.Rgb16f, PixelFormat.Rgb, PixelType.HalfFloat); blurTexture[i].SetFiltering(TextureMinFilter.Linear, TextureMagFilter.Linear); blurFramebuffer[i] = new Framebuffer().AttachTexture(blurTexture[i], FramebufferAttachment.ColorAttachment0); if (!blurFramebuffer[i].CheckStatus()) { Console.WriteLine("Framebuffer error"); } blurFramebuffer[i].Unbind(); } bloomTexture = new Texture2D((int)(Width / 1f), (int)(Height / 1f), PixelInternalFormat.Rgb16f, PixelFormat.Rgb, PixelType.HalfFloat); bloomTexture.SetFiltering(TextureMinFilter.Linear, TextureMagFilter.Linear); bloomFramebuffer = new Framebuffer().AttachTexture(bloomTexture, FramebufferAttachment.ColorAttachment0); if (!bloomFramebuffer.CheckStatus()) { Console.WriteLine("Framebuffer error"); } bloomFramebuffer.Unbind(); model = new ModelBatch(); lsr = new LightScatteringRenderer(Width, Height); }