From 7342c28e6be8d3dfaf5b4e0d083c1d796659c953 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Fri, 25 Dec 2020 10:23:02 -0800 Subject: [PATCH] Revert "Attempt to disable multisampling (glTexImage2D instead of glTexImage2DMultisample), but nothing shows up" This reverts commit 5b972cb3eca0251c2c5e40089a8d425c1838ff62. --- src/render/mod.rs | 47 +++++++++++++++++++----------- src/render/shaders/trans_frag.glsl | 10 +++++-- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/render/mod.rs b/src/render/mod.rs index d9a08b1..163e33e 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -41,6 +41,9 @@ use std::thread; const ATLAS_SIZE: usize = 1024; +// TEMP +const NUM_SAMPLES: i32 = 2; + pub struct Camera { pub pos: cgmath::Point3, pub yaw: f64, @@ -774,6 +777,7 @@ init_shader! { required accum => "taccum", required revealage => "trevealage", required color => "tcolor", + required samples => "samples", }, } } @@ -846,30 +850,38 @@ impl TransInfo { main.bind(); let fb_color = gl::Texture::new(); - fb_color.bind(gl::TEXTURE_2D); - fb_color.image_2d( - gl::TEXTURE_2D, - 0, + fb_color.bind(gl::TEXTURE_2D_MULTISAMPLE); + fb_color.image_2d_sample( + gl::TEXTURE_2D_MULTISAMPLE, + NUM_SAMPLES, width, height, - gl::RGBA, - gl::UNSIGNED_BYTE, - None, + gl::RGBA8, + false, + ); + main.texture_2d( + gl::COLOR_ATTACHMENT_0, + gl::TEXTURE_2D_MULTISAMPLE, + &fb_color, + 0, ); - main.texture_2d(gl::COLOR_ATTACHMENT_0, gl::TEXTURE_2D, &fb_color, 0); let fb_depth = gl::Texture::new(); - fb_depth.bind(gl::TEXTURE_2D); - fb_depth.image_2d( - gl::TEXTURE_2D, - 0, + fb_depth.bind(gl::TEXTURE_2D_MULTISAMPLE); + fb_depth.image_2d_sample( + gl::TEXTURE_2D_MULTISAMPLE, + NUM_SAMPLES, width, height, - gl::DEPTH_COMPONENT, - gl::UNSIGNED_BYTE, - None, + gl::DEPTH_COMPONENT24, + false, + ); + main.texture_2d( + gl::DEPTH_ATTACHMENT, + gl::TEXTURE_2D_MULTISAMPLE, + &fb_depth, + 0, ); - main.texture_2d(gl::DEPTH_ATTACHMENT, gl::TEXTURE_2D, &fb_depth, 0); gl::check_framebuffer_status(); gl::unbind_framebuffer(); @@ -913,12 +925,13 @@ impl TransInfo { gl::active_texture(1); self.revealage.bind(gl::TEXTURE_2D); gl::active_texture(2); - self.fb_color.bind(gl::TEXTURE_2D); + self.fb_color.bind(gl::TEXTURE_2D_MULTISAMPLE); shader.program.use_program(); shader.accum.set_int(0); shader.revealage.set_int(1); shader.color.set_int(2); + shader.samples.set_int(NUM_SAMPLES); self.array.bind(); gl::draw_arrays(gl::TRIANGLES, 0, 6); } diff --git a/src/render/shaders/trans_frag.glsl b/src/render/shaders/trans_frag.glsl index e28048d..123e4c3 100644 --- a/src/render/shaders/trans_frag.glsl +++ b/src/render/shaders/trans_frag.glsl @@ -1,6 +1,8 @@ uniform sampler2D taccum; uniform sampler2D trevealage; -uniform sampler2D tcolor; +uniform sampler2DMS tcolor; + +uniform int samples; out vec4 fragColor; @@ -10,6 +12,11 @@ void main() { float aa = texelFetch(trevealage, C, 0).r; vec4 col = texelFetch(tcolor, C, 0); + for (int i = 1; i < samples; i++) { + col += texelFetch(tcolor, C, i); + } + col /= float(samples); + float r = accum.a; accum.a = aa; if (r >= 1.0) { @@ -18,5 +25,4 @@ void main() { vec3 alp = clamp(accum.rgb / clamp(accum.a, 1e-4, 5e4), 0.0, 1.0); fragColor = vec4(col.rgb * r + alp * (1.0 - r), 0.0); } - //fragColor = vec4(0.0, 1.0, 0.0, 0.0); // green test - fragment shader }