msaa enabled

This commit is contained in:
4sval 2022-08-31 23:04:15 +02:00
parent 5b08fc400d
commit fb330e33da
5 changed files with 56 additions and 35 deletions

View File

@ -79,7 +79,7 @@ public partial class MainWindow
#if DEBUG
await _threadWorkerView.Begin(_ =>
_applicationView.CUE4Parse.Extract(
"/Game/Characters/Player/Female/Medium/Bodies/F_MED_Neon_Cat_Tech/Meshes/F_MED_Neon_Cat_Tech.uasset"));
"FortniteGame/Content/Environments/Props/Winter/Meshes/SM_ChristmasTree_Llama.uasset"));
#endif
}

View File

@ -6,7 +6,8 @@ namespace FModel.Views.Snooper;
public class FramebufferObject : IDisposable
{
private uint _handle;
private uint _framebufferHandle;
private uint _postProcessingHandle;
private GL _gl;
private readonly int _width;
@ -18,7 +19,8 @@ public class FramebufferObject : IDisposable
private VertexArrayObject<float, uint> _vao;
private Shader _shader;
private Texture _texture;
private Texture _framebufferTexture;
private Texture _postProcessingTexture;
public readonly uint[] Indices = { 0, 1, 2, 3, 4, 5 };
public readonly float[] Vertices = {
@ -42,10 +44,11 @@ public class FramebufferObject : IDisposable
public void Setup(GL gl)
{
_gl = gl;
_handle = _gl.GenFramebuffer();
Bind();
_texture = new Texture(_gl, (uint) _width, (uint) _height);
_framebufferHandle = _gl.GenFramebuffer();
Bind(_framebufferHandle);
_framebufferTexture = new Texture(_gl, (uint) _width, (uint) _height);
_renderbuffer.Setup(gl);
@ -63,18 +66,32 @@ public class FramebufferObject : IDisposable
var status = _gl.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
if (status != GLEnum.FramebufferComplete)
{
throw new Exception($"Framebuffer failed to bind with error: {_gl.GetProgramInfoLog(_handle)}");
throw new Exception($"Framebuffer failed to bind with error: {_gl.GetProgramInfoLog(_framebufferHandle)}");
}
_postProcessingHandle = _gl.GenFramebuffer();
Bind(_postProcessingHandle);
_postProcessingTexture = new Texture(_gl, _width, _height);
status = _gl.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
if (status != GLEnum.FramebufferComplete)
{
throw new Exception($"Post-Processing framebuffer failed to bind with error: {_gl.GetProgramInfoLog(_postProcessingHandle)}");
}
}
public void Bind()
public void Bind() => Bind(_framebufferHandle);
public void Bind(uint handle)
{
_gl.BindFramebuffer(FramebufferTarget.DrawFramebuffer, _handle);
_gl.BindFramebuffer(FramebufferTarget.Framebuffer, handle);
}
public void UnBind()
public void BindMsaa()
{
_gl.BindFramebuffer(FramebufferTarget.DrawFramebuffer, 0);
_gl.BindFramebuffer(FramebufferTarget.ReadFramebuffer, _framebufferHandle);
_gl.BindFramebuffer(FramebufferTarget.DrawFramebuffer, _postProcessingHandle);
_gl.BlitFramebuffer(0, 0, _width, _height, 0, 0, _width, _height, ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Nearest);
}
public void BindStuff()
@ -84,21 +101,23 @@ public class FramebufferObject : IDisposable
_shader.Use();
_vao.Bind();
_texture.Bind(TextureUnit.Texture0);
_postProcessingTexture.Bind(TextureUnit.Texture0);
_gl.DrawArrays(PrimitiveType.Triangles, 0, (uint) Indices.Length);
_gl.DepthMask(true);
}
public IntPtr GetPointer() => _texture.GetPointer();
public IntPtr GetPointer() => _postProcessingTexture.GetPointer();
public void Dispose()
{
_vao.Dispose();
_shader.Dispose();
_texture.Dispose();
_framebufferTexture.Dispose();
_postProcessingTexture.Dispose();
_renderbuffer.Dispose();
_gl.DeleteFramebuffer(_handle);
_gl.DeleteFramebuffer(_framebufferHandle);
_gl.DeleteFramebuffer(_postProcessingHandle);
}
}

View File

@ -23,7 +23,7 @@ public class RenderbufferObject : IDisposable
_handle = _gl.GenRenderbuffer();
_gl.BindRenderbuffer(RenderbufferTarget.Renderbuffer, _handle);
_gl.RenderbufferStorage(RenderbufferTarget.Renderbuffer, InternalFormat.Depth24Stencil8, _width, _height);
_gl.RenderbufferStorageMultisample(RenderbufferTarget.Renderbuffer, Constants.SAMPLES_COUNT, InternalFormat.Depth24Stencil8, _width, _height);
_gl.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthStencilAttachment, RenderbufferTarget.Renderbuffer, _handle);
}

View File

@ -51,7 +51,6 @@ public class Snooper
options.Size = _size = new Vector2D<int>(Convert.ToInt32(x * ratio), Convert.ToInt32(y * ratio));
options.WindowBorder = WindowBorder.Hidden;
options.Title = "Snooper";
options.Samples = (int) Constants.SAMPLES_COUNT;
_window = Silk.NET.Windowing.Window.Create(options);
unsafe
@ -161,7 +160,6 @@ public class Snooper
ImGuiExtensions.DrawNavbar();
ImGui.ShowDemoWindow();
_framebuffer.BindStuff();
_skybox.Bind(_camera);
_grid.Bind(_camera);
@ -189,7 +187,10 @@ public class Snooper
ImGuiExtensions.DrawViewport(_framebuffer, _camera, _mouse);
ImGuiExtensions.DrawFPS();
_framebuffer.UnBind(); // switch back to main window
_framebuffer.BindMsaa();
_framebuffer.Bind(0); // switch back to main window
_framebuffer.BindStuff();
_controller.Render(); // render ImGui in main window
}

View File

@ -22,24 +22,24 @@ public class Texture : IDisposable
Bind(TextureUnit.Texture0);
}
// public Texture(GL gl, uint width, uint height) : this(gl, TextureType.MsaaFramebuffer)
// {
// _gl.TexImage2DMultisample(TextureTarget.Texture2DMultisample, Constants.SAMPLES_COUNT, InternalFormat.Rgb, width, height, Silk.NET.OpenGL.Boolean.True);
//
// _gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int) GLEnum.Nearest);
// _gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int) GLEnum.Nearest);
// _gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int) GLEnum.ClampToEdge);
// _gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int) GLEnum.ClampToEdge);
//
// _gl.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2DMultisample, _handle, 0);
// }
public unsafe Texture(GL gl, uint width, uint height) : this(gl, TextureType.Framebuffer)
public Texture(GL gl, uint width, uint height) : this(gl, TextureType.MsaaFramebuffer)
{
_gl.TexImage2D(TextureTarget.Texture2D, 0, (int) InternalFormat.Rgb, width, height, 0, PixelFormat.Rgb, PixelType.UnsignedByte, null);
_gl.TexImage2DMultisample(TextureTarget.Texture2DMultisample, Constants.SAMPLES_COUNT, InternalFormat.Rgb, width, height, Silk.NET.OpenGL.Boolean.True);
_gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int) GLEnum.Nearest);
_gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int) GLEnum.Nearest);
_gl.TexParameter(TextureTarget.Texture2DMultisample, TextureParameterName.TextureMinFilter, (int) GLEnum.Nearest);
_gl.TexParameter(TextureTarget.Texture2DMultisample, TextureParameterName.TextureMagFilter, (int) GLEnum.Nearest);
_gl.TexParameter(TextureTarget.Texture2DMultisample, TextureParameterName.TextureWrapS, (int) GLEnum.ClampToEdge);
_gl.TexParameter(TextureTarget.Texture2DMultisample, TextureParameterName.TextureWrapT, (int) GLEnum.ClampToEdge);
_gl.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2DMultisample, _handle, 0);
}
public unsafe Texture(GL gl, int width, int height) : this(gl, TextureType.Framebuffer)
{
_gl.TexImage2D(TextureTarget.Texture2D, 0, (int) InternalFormat.Rgb, (uint) width, (uint) height, 0, PixelFormat.Rgb, PixelType.UnsignedByte, null);
_gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int) GLEnum.Linear);
_gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int) GLEnum.Linear);
_gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int) GLEnum.ClampToEdge);
_gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int) GLEnum.ClampToEdge);
@ -94,6 +94,7 @@ public class Texture : IDisposable
var target = _type switch
{
TextureType.Cubemap => TextureTarget.TextureCubeMap,
TextureType.MsaaFramebuffer => TextureTarget.Texture2DMultisample,
_ => TextureTarget.Texture2D
};
_gl.BindTexture(target, _handle);