Search shader for brightness and contrast

hello!
I try to use shader to control the contrast and brightness of videos.
But I do not see much difference between the two settings shader that I found in the example below:
https://github.com/laserpilot/shaderSandbox
I did some research but find.
(There has here a few months.)
I know there is no more than that shader is that someone would have a clue?
I would have dug but I have little time to solve the story!
(translate.google frensh…)
Here are two screenshots, with me, no differences!

Well now I found:
I replaced the shader and add this line in my code:
brcosaShader.setUniform3f(“avgluma”, 0.62,0.62,0.62);

shader :
_const vec3 LumCoeff = vec3 (0.2125, 0.7154, 0.0721);

varying vec2 texcoord;
uniform sampler2DRect image;

uniform vec3 avgluma;
uniform float saturation;
uniform float contrast;
uniform float brightness;
uniform float alpha;

void main (void)
{
vec3 texColor = texture2DRect(image, texcoord).rgb;
vec3 intensity = vec3 (dot(texColor, LumCoeff));
vec3 color = mix(intensity, texColor, saturation);
color = mix(avgluma, color, contrast);
color *= brightness;
gl_FragColor = vec4 (color, color.g*alpha);_

résultat :

1 Like

Hi - thanks for posting this. It actually helped me out quite a bit, now 2 years later.
I’m using your 0.62 values for avgluma and it works, but I’m wondering how you got that value?

I’m also wondering what the best range of values for contrast/brightness/saturation are?

Also, I’m not sure why “color.g*alpha” is used instead of alpha. I just put alpha there instead, with default of 1.0. Otherwise I get weird results.

Here’s my brightness, contrast, saturation shader code for use with ofxFX addon:

//
//  ofxBrcosa.h
//
//  Created by Tyler Henry on 9-22-15.
//  Copyright (c) 2015 All rights reserved.
//
//  Based on:
//
// Fragment shader for modifying image contrast by
// interpolation and extrapolation
//
// Author: Randi Rost
//
// Copyright (c) 2002: 3Dlabs, Inc.
//
// See 3Dlabs-License.txt for license information
//

#pragma once

#define STRINGIFY(A) #A

#include "ofMain.h"
#include "ofxFXObject.h"

class ofxBrcosa : public ofxFXObject {
public:
    ofxBrcosa(){
        passes = 1;
        internalFormat = GL_RGBA;
        
        fragmentShader =
        STRINGIFY(const vec3 LumCoeff = vec3(0.2125, 0.7154, 0.0721);
                  
                  uniform sampler2DRect tex0;
                  uniform vec3 avgluma;
                  uniform float saturation;
                  uniform float contrast;
                  uniform float brightness;
                  uniform float alpha;
                  
                  void main (void)
                  {
                      vec3 texColor   = vec3(texture2DRect(tex0, gl_TexCoord[0].st));
                      vec3 intensity  = vec3(dot(texColor, LumCoeff));
                      vec3 color      = mix(intensity, texColor, saturation);
                      color           = mix(avgluma, color, contrast);
                      color          *= brightness;
                      gl_FragColor    = vec4(color, alpha);
                  }
        );
    }
    void update(){
        pingPong.dst->begin();
        
        ofClear(0);
        shader.begin();
        
        shader.setUniformTexture( "tex0" , textures[0].getTextureReference(), 0);
        shader.setUniform3f("avgluma", 0.62,0.62,0.62);
        shader.setUniform1f("saturation", saturation);
        shader.setUniform1f("contrast", contrast);
        shader.setUniform1f("brightness", brightness);
        shader.setUniform1f("alpha", alpha);
        
        renderFrame();
        
        shader.end();
        
        pingPong.dst->end();
    };
    
    float saturation;
    float contrast;
    float brightness;
    float alpha = 1.0;
};