Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
colorcorrection.h
Go to the documentation of this file.
1 /* Copyright (c) 2014-2016 "Omnidome" by cr8tr
2  * Dome Mapping Projection Software (http://omnido.me).
3  * Omnidome was created by Michael Winkelmann aka Wilston Oreo (@WilstonOreo)
4  *
5  * This file is part of Omnidome.
6  *
7  * Omnidome is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Affero General Public License for more details.
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
21  float gamma;
22  float brightness;
23  float contrast;
24  float multiplier;
25 };
26 
29 cc_green,
30 cc_blue,
31 cc_all;
32 
33 float brightness(float v, float brightness_value) {
34  return max(v + brightness_value,0.0);
35 }
36 
37 /// Calculate contrast corrected value
38 float contrast(float v, float contrast_value) {
39  float _c = (contrast_value <= 0.0) ?
40  contrast_value + 1.0 :
41  (1.0 / (1.0 - contrast_value));
42  return (v - 0.5) * max(_c, 0.0f) + 0.5;
43 }
44 
45 /// Calculate gamma corrected value
46 float gamma(float v, float gamma_value) {
47  float g = 0.0;
48  if (gamma_value >= 0.0) {
49  g = 1.0 / (1.0 + gamma_value);
50  } else {
51  g = (1.0 - gamma_value);
52  }
53  return pow(v,g*g*g*g);
54 }
55 
56 float corrected(in ChannelCorrection c, in float v) {
57  return brightness(contrast(gamma(v,
58  c.gamma * c.multiplier),
59  c.contrast * c.multiplier),
60  c.brightness * c.multiplier);
61 }
62 
63 
64 vec3 color_correction(vec3 color) {
65  if (cc_all.multiplier == 0.0) {
66  return color;
67  }
68  return clamp(vec3(
69  corrected(cc_all,corrected(cc_red,color.r)),
72  ),vec3(0.0,0.0,0.0),vec3(1.0,1.0,1.0));
73 }
float gamma
Definition: colorcorrection.h:21
float contrast(float v, float contrast_value)
Calculate contrast corrected value.
Definition: colorcorrection.h:38
Definition: colorcorrection.h:20
ChannelCorrection cc_red
Definition: colorcorrection.h:28
ChannelCorrection cc_green
Definition: colorcorrection.h:28
float contrast
Definition: colorcorrection.h:23
vec3 color_correction(vec3 color)
Definition: colorcorrection.h:64
float multiplier
Definition: colorcorrection.h:24
ChannelCorrection cc_blue
Definition: colorcorrection.h:28
ChannelCorrection cc_all
Definition: colorcorrection.h:28
float corrected(in ChannelCorrection c, in float v)
Definition: colorcorrection.h:56
float brightness(float v, float brightness_value)
Definition: colorcorrection.h:33
float brightness
Definition: colorcorrection.h:22
float gamma(float v, float gamma_value)
Calculate gamma corrected value.
Definition: colorcorrection.h:46