Quantcast
Channel: openFrameworks - Latest posts
Viewing all articles
Browse latest Browse all 40524

Search shader for brightness and contrast

$
0
0

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;
};

Viewing all articles
Browse latest Browse all 40524

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>