From: John Tsiombikas Date: Thu, 10 Dec 2020 07:54:23 +0000 (+0200) Subject: first half-assed attempt at old wahsed-out post effect failed X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=demo_prior;a=commitdiff_plain;h=5eefe7b94c8d6c6caa2c10e3835ab0831a3c42a1 first half-assed attempt at old wahsed-out post effect failed --- diff --git a/sdr/gamma.v.glsl b/sdr/gamma.v.glsl deleted file mode 100644 index 4c3c8ef..0000000 --- a/sdr/gamma.v.glsl +++ /dev/null @@ -1,5 +0,0 @@ -void main() -{ - gl_Position = gl_Vertex; - gl_TexCoord[0] = gl_MultiTexCoord0 * vec4(1.0, -1.0, 1.0, 1.0); -} diff --git a/sdr/oldfig.p.glsl b/sdr/oldfig.p.glsl new file mode 100644 index 0000000..a51e52c --- /dev/null +++ b/sdr/oldfig.p.glsl @@ -0,0 +1,30 @@ +uniform sampler2D tex; + +vec3 rgb2hsv(in vec3 rgb); +vec3 hsv2rgb(in vec3 hsv); + +void main() +{ + vec3 texel = texture2D(tex, gl_TexCoord[0].st).rgb; + vec3 hsv = rgb2hsv(texel); + vec3 rgb = hsv2rgb(hsv * vec3(0.97, 0.8, 0.9)); + + gl_FragColor = vec4(rgb, 1.0); +} + + +vec3 rgb2hsv(in vec3 rgb) +{ + vec4 k = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); + vec4 p = mix(vec4(rgb.bg, k.wz), vec4(rgb.gb, k.xy), step(rgb.b, rgb.g)); + vec4 q = mix(vec4(p.xyw, rgb.r), vec4(rgb.r, p.yzx), step(p.x, rgb.r)); + float d = q.x - min(q.w, q.y); + float e = 1.0e-10; + return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); +} + +vec3 hsv2rgb(in vec3 hsv) +{ + vec3 rgb = clamp(abs(mod(hsv.x * 6.0 + vec3(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0, 0.0, 1.0 ); + return hsv.z * mix(vec3(1.0), rgb, hsv.y); +} diff --git a/sdr/post.v.glsl b/sdr/post.v.glsl new file mode 100644 index 0000000..4c3c8ef --- /dev/null +++ b/sdr/post.v.glsl @@ -0,0 +1,5 @@ +void main() +{ + gl_Position = gl_Vertex; + gl_TexCoord[0] = gl_MultiTexCoord0 * vec4(1.0, -1.0, 1.0, 1.0); +} diff --git a/src/demo.c b/src/demo.c index 3841066..a4bb0c7 100644 --- a/src/demo.c +++ b/src/demo.c @@ -34,7 +34,7 @@ int demo_init(void) post_init(); - if(!(sdr_gamma = create_program_load("sdr/gamma.v.glsl", "sdr/gamma.p.glsl"))) { + if(!(sdr_gamma = create_program_load("sdr/post.v.glsl", "sdr/gamma.p.glsl"))) { fprintf(stderr, "Warning: failed to load the gamma correction shader\n"); } @@ -103,11 +103,11 @@ void demo_display(void) /* no-srgb gamma correction fallback */ if(!opt.srgb) { - glBindTexture(GL_TEXTURE_2D, fbtex[0].id); + glBindTexture(GL_TEXTURE_2D, post_fbtex[0].id); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, win_width, win_height); glUseProgram(sdr_gamma); - overlay_tex(fbtex, 1.0); + overlay_tex(post_fbtex, 1.0); } } diff --git a/src/part_whitted.c b/src/part_whitted.c index 658b2ff..eb0fe5b 100644 --- a/src/part_whitted.c +++ b/src/part_whitted.c @@ -70,6 +70,8 @@ static void stop(void) static void draw(long tm) { + glDisable(GL_DEPTH_TEST); + glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* @@ -81,6 +83,9 @@ static void draw(long tm) glRotatef(-cam_phi, 1, 0, 0); glTranslatef(0, 0, cam_dist); + glBindFramebuffer(GL_FRAMEBUFFER, post_fbo[0]); + glClear(GL_COLOR_BUFFER_BIT); + glUseProgram(sdr); glUniform1f(uloc_aspect, win_aspect); @@ -95,6 +100,10 @@ static void draw(long tm) glVertex2f(-1, 1); glEnd(); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glUseProgram(post_sdr[POST_OLDFIG]); + overlay_tex(post_fbtex, 1.0); + if(dbgtex) { glUseProgram(0); overlay_tex(dbgtex, dbg_alpha); diff --git a/src/post.c b/src/post.c index b78284a..91109b2 100644 --- a/src/post.c +++ b/src/post.c @@ -1,29 +1,40 @@ -#include #include "opengl.h" #include "texture.h" #include "post.h" #include "demo.h" #include "opt.h" +#include "sdr.h" -static unsigned int fbtex_gltexid[2]; -static unsigned int fbo[2], rbuf_depth[2]; -struct texture fbtex[2]; -int fbtex_cur; +static unsigned int post_fbtex_gltexid[2]; +static unsigned int rbuf_depth[2]; + +unsigned int post_fbo[2]; +struct texture post_fbtex[2]; +int post_fbtex_cur; + +unsigned int post_sdr[MAX_POST_SDR]; int post_init(void) { int i; + static const char *psdr_fname[] = {"sdr/oldfig.p.glsl"}; + + for(i=0; i