-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[orx-fx] Add Invert fx filter (#214)
- Loading branch information
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
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,18 @@ | ||
package org.openrndr.extra.fx.color | ||
|
||
import org.openrndr.draw.Filter | ||
import org.openrndr.extra.fx.fx_invert | ||
import org.openrndr.extra.fx.fx_sepia | ||
import org.openrndr.extra.fx.mppFilterShader | ||
import org.openrndr.extra.parameters.Description | ||
import org.openrndr.extra.parameters.DoubleParameter | ||
|
||
@Description("Invert") | ||
class Invert : Filter(mppFilterShader(fx_invert, "invert")) { | ||
@DoubleParameter("amount", 0.0, 1.0) | ||
var amount: Double by parameters | ||
|
||
init { | ||
amount = 1.0 | ||
} | ||
} |
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,14 @@ | ||
in vec2 v_texCoord0; | ||
uniform sampler2D tex0; // input | ||
uniform float amount; | ||
out vec4 o_color; | ||
|
||
void main() { | ||
vec4 color = texture(tex0, v_texCoord0); | ||
|
||
float a = color.a; | ||
vec3 rgb = a > 0.0 ? color.rgb / a : vec3(0.0); | ||
rgb = mix(rgb, 1.0 - rgb, amount); | ||
|
||
o_color = vec4(rgb * a, a); | ||
} |