--- /dev/null
+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);
+}
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");
}
/* 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);
}
}
static void draw(long tm)
{
+ glDisable(GL_DEPTH_TEST);
+
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
/*
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);
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);
-#include <assert.h>
#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<MAX_POST_SDR; i++) {
+ if(!(post_sdr[i] = create_program_load("sdr/post.v.glsl", psdr_fname[i]))) {
+ return -1;
+ }
+ }
- glGenTextures(2, fbtex_gltexid);
+ glGenTextures(2, post_fbtex_gltexid);
glGenRenderbuffers(2, rbuf_depth);
for(i=0; i<2; i++) {
- fbtex[i].id = fbtex_gltexid[i];
- fbtex[i].width = 0;
- fbtex[i].height = 0;
- fbtex[i].pixels = 0;
+ post_fbtex[i].id = post_fbtex_gltexid[i];
+ post_fbtex[i].width = 0;
+ post_fbtex[i].height = 0;
+ post_fbtex[i].pixels = 0;
- glBindTexture(GL_TEXTURE_2D, fbtex[i].id);
+ glBindTexture(GL_TEXTURE_2D, post_fbtex[i].id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
void post_cleanup(void)
{
- if(fbtex_gltexid[0]) {
- glDeleteTextures(2, fbtex_gltexid);
+ if(post_fbtex_gltexid[0]) {
+ glDeleteTextures(2, post_fbtex_gltexid);
}
if(rbuf_depth[0]) {
glDeleteRenderbuffers(2, rbuf_depth);
}
- if(fbo[0]) {
- glDeleteFramebuffers(2, fbo);
+ if(post_fbo[0]) {
+ glDeleteFramebuffers(2, post_fbo);
}
}
{
int i, ifmt;
- if(x != fbtex[0].width || y != fbtex[0].height) {
+ if(x != post_fbtex[0].width || y != post_fbtex[0].height) {
ifmt = opt.srgb ? GL_SRGB_ALPHA : GL_RGBA;
for(i=0; i<2; i++) {
- glBindTexture(GL_TEXTURE_2D, fbtex[i].id);
+ glBindTexture(GL_TEXTURE_2D, post_fbtex[i].id);
glTexImage2D(GL_TEXTURE_2D, 0, ifmt, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
- fbtex[i].width = x;
- fbtex[i].height = y;
+ post_fbtex[i].width = x;
+ post_fbtex[i].height = y;
glBindRenderbuffer(GL_RENDERBUFFER, rbuf_depth[i]);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, x, y);
}
- if(!fbo[0]) {
- glGenFramebuffers(2, fbo);
+ if(!post_fbo[0]) {
+ glGenFramebuffers(2, post_fbo);
for(i=0; i<2; i++) {
- glBindFramebuffer(GL_FRAMEBUFFER, fbo[i]);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbtex_gltexid[i], 0);
+ glBindFramebuffer(GL_FRAMEBUFFER, post_fbo[i]);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, post_fbtex_gltexid[i], 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbuf_depth[i]);
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);