-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added basic tone mapping and exposure shaders #31
- Loading branch information
Showing
7 changed files
with
219 additions
and
6 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifdef GL_ES | ||
precision mediump float; | ||
precision mediump int; | ||
#endif | ||
|
||
#define PROCESSING_TEXTURE_SHADER | ||
|
||
uniform sampler2D texture; | ||
|
||
varying vec4 vertColor; | ||
varying vec4 vertTexCoord; | ||
|
||
vec3 n; | ||
|
||
uniform float exposure = 0.0; | ||
|
||
void main() { | ||
vec4 c = texture2D(texture, vertTexCoord.st) * vertColor; | ||
vec3 n = c.rgb * pow(2.0, exposure); | ||
gl_FragColor = vec4(n, c.a); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#ifdef GL_ES | ||
precision mediump float; | ||
precision mediump int; | ||
#endif | ||
|
||
#define PROCESSING_TEXTURE_SHADER | ||
|
||
uniform sampler2D texture; | ||
|
||
varying vec4 vertColor; | ||
varying vec4 vertTexCoord; | ||
|
||
vec3 n; | ||
|
||
uniform float gamma = 2.2; | ||
|
||
vec3 linearToneMapping(vec3 color) | ||
{ | ||
float exposure = 1.; | ||
color = clamp(exposure * color, 0., 1.); | ||
color = pow(color, vec3(1. / gamma)); | ||
return color; | ||
} | ||
|
||
vec3 simpleReinhardToneMapping(vec3 color) | ||
{ | ||
float exposure = 1.5; | ||
color *= exposure/(1. + color / exposure); | ||
color = pow(color, vec3(1. / gamma)); | ||
return color; | ||
} | ||
|
||
vec3 lumaBasedReinhardToneMapping(vec3 color) | ||
{ | ||
float luma = dot(color, vec3(0.2126, 0.7152, 0.0722)); | ||
float toneMappedLuma = luma / (1. + luma); | ||
color *= toneMappedLuma / luma; | ||
color = pow(color, vec3(1. / gamma)); | ||
return color; | ||
} | ||
|
||
vec3 whitePreservingLumaBasedReinhardToneMapping(vec3 color) | ||
{ | ||
float white = 2.; | ||
float luma = dot(color, vec3(0.2126, 0.7152, 0.0722)); | ||
float toneMappedLuma = luma * (1. + luma / (white*white)) / (1. + luma); | ||
color *= toneMappedLuma / luma; | ||
color = pow(color, vec3(1. / gamma)); | ||
return color; | ||
} | ||
|
||
vec3 RomBinDaHouseToneMapping(vec3 color) | ||
{ | ||
color = exp( -1.0 / ( 2.72*color + 0.15 ) ); | ||
color = pow(color, vec3(1. / gamma)); | ||
return color; | ||
} | ||
|
||
vec3 filmicToneMapping(vec3 color) | ||
{ | ||
color = max(vec3(0.), color - vec3(0.004)); | ||
color = (color * (6.2 * color + .5)) / (color * (6.2 * color + 1.7) + 0.06); | ||
return color; | ||
} | ||
|
||
vec3 Uncharted2ToneMapping(vec3 color) | ||
{ | ||
float A = 0.15; | ||
float B = 0.50; | ||
float C = 0.10; | ||
float D = 0.20; | ||
float E = 0.02; | ||
float F = 0.30; | ||
float W = 11.2; | ||
float exposure = 2.; | ||
color *= exposure; | ||
color = ((color * (A * color + C * B) + D * E) / (color * (A * color + B) + D * F)) - E / F; | ||
float white = ((W * (A * W + C * B) + D * E) / (W * (A * W + B) + D * F)) - E / F; | ||
color /= white; | ||
color = pow(color, vec3(1. / gamma)); | ||
return color; | ||
} | ||
|
||
void main() { | ||
vec4 c = texture2D(texture, vertTexCoord.st) * vertColor; | ||
vec3 n = linearToneMapping(c.rgb); | ||
gl_FragColor = vec4(n, c.a); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package ch.bildspur.postfx.pass; | ||
|
||
import ch.bildspur.postfx.Supervisor; | ||
import processing.core.PApplet; | ||
|
||
/** | ||
* Created by cansik on 27.03.17. | ||
*/ | ||
public class ExposurePass extends BasePass { | ||
private static final String PASS_NAME = "exposureFrag"; | ||
|
||
private float exposure; | ||
|
||
public ExposurePass(PApplet sketch) { | ||
this(sketch, 0.0f); | ||
} | ||
|
||
public ExposurePass(PApplet sketch, float exposure) { | ||
super(sketch, PASS_NAME); | ||
|
||
this.exposure = exposure; | ||
} | ||
|
||
@Override | ||
public void prepare(Supervisor supervisor) { | ||
shader.set("exposure", exposure); | ||
} | ||
|
||
public float getExposure() { | ||
return exposure; | ||
} | ||
|
||
public void setExposure(float exposure) { | ||
this.exposure = exposure; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/ch/bildspur/postfx/pass/ToneMappingPass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package ch.bildspur.postfx.pass; | ||
|
||
import ch.bildspur.postfx.Supervisor; | ||
import processing.core.PApplet; | ||
|
||
/** | ||
* Created by cansik on 14.05.17. | ||
*/ | ||
public class ToneMappingPass extends BasePass { | ||
private static final String PASS_NAME = "toneMappingFrag"; | ||
|
||
private float gamma; | ||
|
||
public ToneMappingPass(PApplet sketch) { | ||
this(sketch, 2.2f); | ||
} | ||
|
||
public ToneMappingPass(PApplet sketch, float gamma) { | ||
super(sketch, PASS_NAME); | ||
|
||
this.gamma = gamma; | ||
} | ||
|
||
@Override | ||
public void prepare(Supervisor supervisor) { | ||
shader.set("gamma", gamma); | ||
} | ||
|
||
public float getGamma() { | ||
return gamma; | ||
} | ||
|
||
public void setGamma(float gamma) { | ||
this.gamma = gamma; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters