-
-
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
bc896d2
commit a287d90
Showing
6 changed files
with
150 additions
and
42 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 |
---|---|---|
@@ -1,40 +1,36 @@ | ||
precision mediump float; | ||
precision highp float; | ||
in vec2 vTextureCoord; | ||
out vec4 finalColor; | ||
|
||
varying vec2 vTextureCoord; | ||
|
||
uniform vec2 size; | ||
uniform vec2 uSize; | ||
uniform sampler2D uSampler; | ||
|
||
uniform vec4 filterArea; | ||
uniform vec4 uInputSize; | ||
|
||
vec2 mapCoord( vec2 coord ) | ||
{ | ||
coord *= filterArea.xy; | ||
coord += filterArea.zw; | ||
coord *= uInputSize.xy; | ||
coord += uInputSize.zw; | ||
|
||
return coord; | ||
} | ||
|
||
vec2 unmapCoord( vec2 coord ) | ||
{ | ||
coord -= filterArea.zw; | ||
coord /= filterArea.xy; | ||
coord -= uInputSize.zw; | ||
coord /= uInputSize.xy; | ||
|
||
return coord; | ||
} | ||
|
||
vec2 pixelate(vec2 coord, vec2 size) | ||
vec2 pixelate(vec2 coord, vec2 uSize) | ||
{ | ||
return floor( coord / size ) * size; | ||
return floor( coord / uSize ) * uSize; | ||
} | ||
|
||
void main(void) | ||
{ | ||
vec2 coord = mapCoord(vTextureCoord); | ||
|
||
coord = pixelate(coord, size); | ||
|
||
coord = pixelate(coord, uSize); | ||
coord = unmapCoord(coord); | ||
|
||
gl_FragColor = texture2D(uSampler, coord); | ||
finalColor = texture(uSampler, coord); | ||
} |
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,53 @@ | ||
struct PixelateUniforms { | ||
uSize:vec2<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> pixelateUniforms : PixelateUniforms; | ||
|
||
@fragment | ||
fn mainFragment( | ||
@location(0) uv: vec2<f32>, | ||
@builtin(position) position: vec4<f32> | ||
) -> @location(0) vec4<f32> { | ||
let pixelSize: vec2<f32> = pixelateUniforms.uSize; | ||
let coord: vec2<f32> = mapCoord(uv); | ||
|
||
var pixCoord: vec2<f32> = pixelate(coord, pixelSize); | ||
pixCoord = unmapCoord(pixCoord); | ||
|
||
return textureSample(uSampler, uSampler, pixCoord); | ||
} | ||
|
||
fn mapCoord(coord: vec2<f32> ) -> vec2<f32> | ||
{ | ||
var mappedCoord: vec2<f32> = coord; | ||
mappedCoord *= gfu.inputSize.xy; | ||
mappedCoord += gfu.outputFrame.xy; | ||
return mappedCoord; | ||
} | ||
|
||
fn unmapCoord(coord: vec2<f32> ) -> vec2<f32> | ||
{ | ||
var mappedCoord: vec2<f32> = coord; | ||
mappedCoord -= gfu.outputFrame.xy; | ||
mappedCoord /= gfu.inputSize.xy; | ||
return mappedCoord; | ||
} | ||
|
||
fn pixelate(coord: vec2<f32>, size: vec2<f32>) -> vec2<f32> | ||
{ | ||
return floor( coord / size ) * size; | ||
} | ||
|
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
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