-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a148418
commit 442d112
Showing
6 changed files
with
155 additions
and
105 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
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,15 @@ | ||
in vec2 vTextureCoord; | ||
out vec4 finalColor; | ||
|
||
uniform sampler2D uSampler; | ||
uniform vec3 uOriginalColor; | ||
uniform vec3 uNewColor; | ||
uniform float uTolerance; | ||
|
||
void main(void) { | ||
vec4 c = texture(uSampler, vTextureCoord); | ||
vec3 colorDiff = uOriginalColor - (c.rgb / max(c.a, 0.0000000001)); | ||
float colorDistance = length(colorDiff); | ||
float doReplace = step(colorDistance, uTolerance); | ||
finalColor = vec4(mix(c.rgb, (uNewColor + colorDiff) * c.a, doReplace), 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,22 @@ | ||
struct ColorReplaceUniforms { | ||
uOriginalColor: vec3<f32>, | ||
uNewColor: vec3<f32>, | ||
uTolerance: f32, | ||
}; | ||
|
||
@group(0) @binding(1) var uSampler: texture_2d<f32>; | ||
@group(1) @binding(0) var<uniform> colorReplaceUniforms : ColorReplaceUniforms; | ||
|
||
@fragment | ||
fn mainFragment( | ||
@builtin(position) position: vec4<f32>, | ||
@location(0) uv : vec2<f32> | ||
) -> @location(0) vec4<f32> { | ||
let sample: vec4<f32> = textureSample(uSampler, uSampler, uv); | ||
|
||
let colorDiff: vec3<f32> = colorReplaceUniforms.uOriginalColor - (sample.rgb / max(sample.a, 0.0000000001)); | ||
let colorDistance: f32 = length(colorDiff); | ||
let doReplace: f32 = step(colorDistance, colorReplaceUniforms.uTolerance); | ||
|
||
return vec4<f32>(mix(sample.rgb, (colorReplaceUniforms.uNewColor + colorDiff) * sample.a, doReplace), sample.a); | ||
} |
This file was deleted.
Oops, something went wrong.
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