-
-
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
a287d90
commit 194450d
Showing
5 changed files
with
247 additions
and
139 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,66 +1,64 @@ | ||
varying vec2 vTextureCoord; | ||
varying vec4 vColor; | ||
precision highp float; | ||
in vec2 vTextureCoord; | ||
out vec4 finalColor; | ||
|
||
uniform sampler2D uSampler; | ||
uniform vec2 uStrength; | ||
uniform vec3 uColor; | ||
uniform float uKnockout; | ||
uniform float uAlpha; | ||
|
||
uniform float outerStrength; | ||
uniform float innerStrength; | ||
|
||
uniform vec4 glowColor; | ||
|
||
uniform vec4 filterArea; | ||
uniform vec4 filterClamp; | ||
uniform bool knockout; | ||
uniform float alpha; | ||
uniform vec4 uInputSize; | ||
uniform vec4 uInputClamp; | ||
|
||
const float PI = 3.14159265358979323846264; | ||
|
||
// Hard-assignment of DIST and ANGLE_STEP_SIZE instead of using uDistance and uQuality to allow them to be use on GLSL loop conditions | ||
const float DIST = __DIST__; | ||
const float ANGLE_STEP_SIZE = min(__ANGLE_STEP_SIZE__, PI * 2.0); | ||
const float ANGLE_STEP_NUM = ceil(PI * 2.0 / ANGLE_STEP_SIZE); | ||
|
||
const float MAX_TOTAL_ALPHA = ANGLE_STEP_NUM * DIST * (DIST + 1.0) / 2.0; | ||
const float ANGLE_STEP_SIZE = min(__ANGLE_STEP_SIZE__, PI * 2.); | ||
const float ANGLE_STEP_NUM = ceil(PI * 2. / ANGLE_STEP_SIZE); | ||
const float MAX_TOTAL_ALPHA = ANGLE_STEP_NUM * DIST * (DIST + 1.) / 2.; | ||
|
||
void main(void) { | ||
vec2 px = vec2(1.0 / filterArea.x, 1.0 / filterArea.y); | ||
vec2 px = vec2(1.) / uInputSize.xy; | ||
|
||
float totalAlpha = 0.0; | ||
float totalAlpha = 0.; | ||
|
||
vec2 direction; | ||
vec2 displaced; | ||
vec4 curColor; | ||
|
||
for (float angle = 0.0; angle < PI * 2.0; angle += ANGLE_STEP_SIZE) { | ||
direction = vec2(cos(angle), sin(angle)) * px; | ||
for (float angle = 0.; angle < PI * 2.; angle += ANGLE_STEP_SIZE) { | ||
direction = vec2(cos(angle), sin(angle)) * px; | ||
|
||
for (float curDistance = 0.0; curDistance < DIST; curDistance++) { | ||
displaced = clamp(vTextureCoord + direction * | ||
(curDistance + 1.0), filterClamp.xy, filterClamp.zw); | ||
|
||
curColor = texture2D(uSampler, displaced); | ||
|
||
totalAlpha += (DIST - curDistance) * curColor.a; | ||
} | ||
for (float curDistance = 0.; curDistance < DIST; curDistance++) { | ||
displaced = clamp(vTextureCoord + direction * (curDistance + 1.), uInputClamp.xy, uInputClamp.zw); | ||
curColor = texture(uSampler, displaced); | ||
totalAlpha += (DIST - curDistance) * curColor.a; | ||
} | ||
} | ||
|
||
curColor = texture2D(uSampler, vTextureCoord); | ||
curColor = texture(uSampler, vTextureCoord); | ||
|
||
float alphaRatio = (totalAlpha / MAX_TOTAL_ALPHA); | ||
vec4 glowColor = vec4(uColor, uAlpha); | ||
bool knockout = uKnockout > .5; | ||
float innerStrength = uStrength[0]; | ||
float outerStrength = uStrength[1]; | ||
|
||
float innerGlowAlpha = (1.0 - alphaRatio) * innerStrength * curColor.a; | ||
float innerGlowStrength = min(1.0, innerGlowAlpha); | ||
float alphaRatio = totalAlpha / MAX_TOTAL_ALPHA; | ||
float innerGlowAlpha = (1. - alphaRatio) * innerStrength * curColor.a * uAlpha; | ||
float innerGlowStrength = min(1., innerGlowAlpha); | ||
|
||
vec4 innerColor = mix(curColor, glowColor, innerGlowStrength); | ||
|
||
float outerGlowAlpha = alphaRatio * outerStrength * (1. - curColor.a); | ||
float outerGlowStrength = min(1.0 - innerColor.a, outerGlowAlpha); | ||
float outerGlowAlpha = alphaRatio * outerStrength * (1. - curColor.a) * uAlpha; | ||
float outerGlowStrength = min(1. - innerColor.a, outerGlowAlpha); | ||
vec4 outerGlowColor = outerGlowStrength * glowColor.rgba; | ||
|
||
if (knockout) { | ||
float resultAlpha = (outerGlowAlpha + innerGlowAlpha) * alpha; | ||
gl_FragColor = vec4(glowColor.rgb * resultAlpha, resultAlpha); | ||
float resultAlpha = outerGlowAlpha + innerGlowAlpha; | ||
finalColor = vec4(glowColor.rgb * resultAlpha, resultAlpha); | ||
} | ||
else { | ||
vec4 outerGlowColor = outerGlowStrength * glowColor.rgba * alpha; | ||
gl_FragColor = innerColor + outerGlowColor; | ||
finalColor = innerColor + outerGlowColor; | ||
} | ||
} |
Oops, something went wrong.