-
-
Notifications
You must be signed in to change notification settings - Fork 165
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
3797ca2
commit aa0869e
Showing
9 changed files
with
90 additions
and
62 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
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,16 +1,17 @@ | ||
precision mediump float; | ||
in vec2 vTextureCoord; | ||
|
||
out vec4 finalColor; | ||
|
||
varying vec2 vTextureCoord; | ||
uniform sampler2D uSampler; | ||
|
||
// https://en.wikipedia.org/wiki/Luma_(video) | ||
const vec3 weight = vec3(0.299, 0.587, 0.114); | ||
|
||
void main() | ||
{ | ||
vec4 color = texture2D(uSampler, vTextureCoord); | ||
gl_FragColor = vec4( | ||
vec3(color.r * weight.r + color.g * weight.g + color.b * weight.b), | ||
color.a | ||
vec4 c = texture(uSampler, vTextureCoord); | ||
finalColor = vec4( | ||
vec3(c.r * weight.r + c.g * weight.g + c.b * weight.b), | ||
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,12 @@ | ||
@group(0) @binding(1) var uSampler: texture_2d<f32>; | ||
|
||
@fragment | ||
fn mainFragment( | ||
@location(0) uv: vec2<f32>, | ||
@builtin(position) position: vec4<f32> | ||
) -> @location(0) vec4<f32> { | ||
let color: vec4<f32> = textureSample(uSampler, uSampler, uv); | ||
|
||
let g: f32 = dot(color.rgb, vec3<f32>(0.299, 0.587, 0.114)); | ||
return vec4<f32>(vec3<f32>(g), 1.); | ||
} |
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,50 @@ | ||
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; | ||
|
||
struct VSOutput { | ||
@builtin(position) position: vec4<f32>, | ||
@location(0) uv : vec2<f32> | ||
}; | ||
|
||
fn filterVertexPosition(aPosition:vec2<f32>) -> vec4<f32> | ||
{ | ||
var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy; | ||
|
||
position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0; | ||
position.y = position.y * (2.0*gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z; | ||
|
||
return vec4(position, 0.0, 1.0); | ||
} | ||
|
||
fn filterTextureCoord( aPosition:vec2<f32> ) -> vec2<f32> | ||
{ | ||
return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw); | ||
} | ||
|
||
fn globalTextureCoord( aPosition:vec2<f32> ) -> vec2<f32> | ||
{ | ||
return (aPosition.xy / gfu.uGlobalFrame.zw) + (gfu.uGlobalFrame.xy / gfu.uGlobalFrame.zw); | ||
} | ||
|
||
fn getSize() -> vec2<f32> | ||
{ | ||
return gfu.uGlobalFrame.zw; | ||
} | ||
|
||
@vertex | ||
fn mainVertex( | ||
@location(0) aPosition : vec2<f32>, | ||
) -> VSOutput { | ||
return VSOutput( | ||
filterVertexPosition(aPosition), | ||
filterTextureCoord(aPosition) | ||
); | ||
} |
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,4 +1,5 @@ | ||
declare module '@tools/fragments' | ||
{ | ||
export const vertex: string; | ||
export const wgslVertex: string; | ||
} |
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,2 +1,3 @@ | ||
import vertex from './default.vert'; | ||
export { vertex }; | ||
import wgslVertex from './default.vert'; | ||
export { vertex, wgslVertex }; |