-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
570a5fc
commit b451567
Showing
6 changed files
with
202 additions
and
96 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,39 @@ | ||
precision highp float; | ||
in vec2 vTextureCoord; | ||
out vec4 finalColor; | ||
|
||
uniform sampler2D uSampler; | ||
uniform vec2 uDimensions; | ||
uniform vec2 uCenter; | ||
uniform float uRadius; | ||
uniform float uStrength; | ||
|
||
uniform vec4 uInputSize; | ||
uniform vec4 uInputClamp; | ||
|
||
void main() | ||
{ | ||
vec2 coord = vTextureCoord * uInputSize.xy; | ||
coord -= uCenter * uDimensions.xy; | ||
float distance = length(coord); | ||
|
||
if (distance < uRadius) { | ||
float percent = distance / uRadius; | ||
if (uStrength > 0.0) { | ||
coord *= mix(1.0, smoothstep(0.0, uRadius / distance, percent), uStrength * 0.75); | ||
} else { | ||
coord *= mix(1.0, pow(percent, 1.0 + uStrength * 0.75) * uRadius / distance, 1.0 - percent); | ||
} | ||
} | ||
|
||
coord += uCenter * uDimensions.xy; | ||
coord /= uInputSize.xy; | ||
vec2 clampedCoord = clamp(coord, uInputClamp.xy, uInputClamp.zw); | ||
vec4 color = texture(uSampler, clampedCoord); | ||
|
||
if (coord != clampedCoord) { | ||
color *= max(0.0, 1.0 - length(coord - clampedCoord)); | ||
} | ||
|
||
finalColor = color; | ||
} |
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,63 @@ | ||
struct BulgePinchUniforms { | ||
uDimensions: vec2<f32>, | ||
uCenter: vec2<f32>, | ||
uRadius: f32, | ||
uStrength: f32, | ||
}; | ||
|
||
struct GlobalFilterUniforms { | ||
uInputSize:vec4<f32>, | ||
uInputPixel:vec4<f32>, | ||
uInputClamp:vec4<f32>, | ||
uOutputFrame:vec4<f32>, | ||
uGlobalFrame:vec4<f32>, | ||
uOutputTexture:vec4<f32>, | ||
}; | ||
|
||
@group(0) @binding(0) var<uniform> gfu: GlobalFilterUniforms; | ||
|
||
@group(0) @binding(1) var uSampler: texture_2d<f32>; | ||
@group(1) @binding(0) var<uniform> bulgePinchUniforms : BulgePinchUniforms; | ||
|
||
@fragment | ||
fn mainFragment( | ||
@builtin(position) position: vec4<f32>, | ||
@location(0) uv : vec2<f32> | ||
) -> @location(0) vec4<f32> { | ||
let dimensions: vec2<f32> = bulgePinchUniforms.uDimensions; | ||
let center: vec2<f32> = bulgePinchUniforms.uCenter; | ||
let radius: f32 = bulgePinchUniforms.uRadius; | ||
let strength: f32 = bulgePinchUniforms.uStrength; | ||
var coord: vec2<f32> = (uv * gfu.uInputSize.xy) - center * dimensions.xy; | ||
|
||
let distance: f32 = length(coord); | ||
|
||
if (distance < radius) { | ||
let percent: f32 = distance / radius; | ||
if (strength > 0.0) { | ||
coord *= mix(1.0, smoothstep(0.0, radius / distance, percent), strength * 0.75); | ||
} else { | ||
coord *= mix(1.0, pow(percent, 1.0 + strength * 0.75) * radius / distance, 1.0 - percent); | ||
} | ||
} | ||
coord += (center * dimensions.xy); | ||
coord /= gfu.uInputSize.xy; | ||
|
||
let clampedCoord: vec2<f32> = clamp(coord, gfu.uInputClamp.xy, gfu.uInputClamp.zw); | ||
var color: vec4<f32> = textureSample(uSampler, uSampler, clampedCoord); | ||
if (coord.x != clampedCoord.x && coord.y != clampedCoord.y) { | ||
color *= max(0.0, 1.0 - length(coord - clampedCoord)); | ||
} | ||
|
||
return color; | ||
} | ||
|
||
fn compareVec2(x: vec2<f32>, y: vec2<f32>) -> bool | ||
{ | ||
if (x.x == y.x && x.y == y.y) | ||
{ | ||
return true; | ||
} | ||
|
||
return false; | ||
} |
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