-
-
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
b451567
commit 5014a88
Showing
5 changed files
with
196 additions
and
111 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,23 +1,23 @@ | ||
precision mediump float; | ||
precision highp float; | ||
in vec2 vTextureCoord; | ||
out vec4 finalColor; | ||
|
||
varying vec2 vTextureCoord; | ||
uniform sampler2D uSampler; | ||
uniform vec4 filterArea; | ||
uniform vec2 uTransform; | ||
uniform vec3 uLightColor; | ||
uniform float uLightAlpha; | ||
uniform vec3 uShadowColor; | ||
uniform float uShadowAlpha; | ||
|
||
uniform float transformX; | ||
uniform float transformY; | ||
uniform vec3 lightColor; | ||
uniform float lightAlpha; | ||
uniform vec3 shadowColor; | ||
uniform float shadowAlpha; | ||
uniform vec4 uInputSize; | ||
|
||
void main(void) { | ||
vec2 transform = vec2(1.0 / filterArea) * vec2(transformX, transformY); | ||
vec4 color = texture2D(uSampler, vTextureCoord); | ||
float light = texture2D(uSampler, vTextureCoord - transform).a; | ||
float shadow = texture2D(uSampler, vTextureCoord + transform).a; | ||
vec2 transform = vec2(1.0 / uInputSize) * vec2(uTransform.x, uTransform.y); | ||
vec4 color = texture(uSampler, vTextureCoord); | ||
float light = texture(uSampler, vTextureCoord - transform).a; | ||
float shadow = texture(uSampler, vTextureCoord + transform).a; | ||
|
||
color.rgb = mix(color.rgb, lightColor, clamp((color.a - light) * lightAlpha, 0.0, 1.0)); | ||
color.rgb = mix(color.rgb, shadowColor, clamp((color.a - shadow) * shadowAlpha, 0.0, 1.0)); | ||
gl_FragColor = vec4(color.rgb * color.a, color.a); | ||
color.rgb = mix(color.rgb, uLightColor, clamp((color.a - light) * uLightAlpha, 0.0, 1.0)); | ||
color.rgb = mix(color.rgb, uShadowColor, clamp((color.a - shadow) * uShadowAlpha, 0.0, 1.0)); | ||
finalColor = vec4(color.rgb * color.a, color.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,40 @@ | ||
struct BevelUniforms { | ||
uLightColor: vec3<f32>, | ||
uLightAlpha: f32, | ||
uShadowColor: vec3<f32>, | ||
uShadowAlpha: f32, | ||
uTransform: 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> bevelUniforms : BevelUniforms; | ||
|
||
@fragment | ||
fn mainFragment( | ||
@builtin(position) position: vec4<f32>, | ||
@location(0) uv : vec2<f32> | ||
) -> @location(0) vec4<f32> { | ||
let transform = vec2<f32>(1.0 / gfu.uInputSize.xy) * vec2<f32>(bevelUniforms.uTransform.x, bevelUniforms.uTransform.y); | ||
var color: vec4<f32> = textureSample(uSampler, uSampler, uv); | ||
let lightSample: f32 = textureSample(uSampler, uSampler, uv - transform).a; | ||
let shadowSample: f32 = textureSample(uSampler, uSampler, uv + transform).a; | ||
|
||
let light = vec4<f32>(bevelUniforms.uLightColor, bevelUniforms.uLightAlpha); | ||
let shadow = vec4<f32>(bevelUniforms.uShadowColor, bevelUniforms.uShadowAlpha); | ||
|
||
color = vec4<f32>(mix(color.rgb, light.rgb, clamp((color.a - lightSample) * light.a, 0.0, 1.0)), color.a); | ||
color = vec4<f32>(mix(color.rgb, shadow.rgb, clamp((color.a - shadowSample) * shadow.a, 0.0, 1.0)), color.a); | ||
|
||
return vec4<f32>(color.rgb * color.a, color.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
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