Skip to content

Commit

Permalink
Align sampler / texture namings
Browse files Browse the repository at this point in the history
  • Loading branch information
bbazukun123 committed Jan 4, 2024
1 parent 529d5f4 commit d8ffdf5
Show file tree
Hide file tree
Showing 40 changed files with 157 additions and 195 deletions.
4 changes: 2 additions & 2 deletions filters/adjustment/src/adjustment.frag
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
in vec2 vTextureCoord;
out vec4 finalColor;

uniform sampler2D uSampler;
uniform sampler2D uTexture;
uniform float uGamma;
uniform float uContrast;
uniform float uSaturation;
Expand All @@ -10,7 +10,7 @@ uniform vec4 uColor;

void main()
{
vec4 c = texture(uSampler, vTextureCoord);
vec4 c = texture(uTexture, vTextureCoord);

if (c.a > 0.0) {
c.rgb /= c.a;
Expand Down
4 changes: 2 additions & 2 deletions filters/advanced-bloom/src/advanced-bloom.frag
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
in vec2 vTextureCoord;
out vec4 finalColor;

uniform sampler2D uSampler;
uniform sampler2D uTexture;
uniform sampler2D uMapTexture;
uniform float uBloomScale;
uniform float uBrightness;

void main() {
vec4 color = texture(uSampler, vTextureCoord);
vec4 color = texture(uTexture, vTextureCoord);
color.rgb *= uBrightness;
vec4 bloomColor = vec4(texture(uMapTexture, vTextureCoord).rgb, 0.0);
bloomColor.rgb *= uBloomScale;
Expand Down
4 changes: 2 additions & 2 deletions filters/advanced-bloom/src/extract-brightness.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
in vec2 vTextureCoord;
out vec4 finalColor;

uniform sampler2D uSampler;
uniform sampler2D uTexture;
uniform float uThreshold;

void main() {
vec4 color = texture(uSampler, vTextureCoord);
vec4 color = texture(uTexture, vTextureCoord);

// A simple & fast algorithm for getting brightness.
// It's inaccuracy , but good enought for this feature.
Expand Down
4 changes: 2 additions & 2 deletions filters/ascii/src/ascii.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ precision highp float;
in vec2 vTextureCoord;
out vec4 finalColor;

uniform sampler2D uSampler;
uniform sampler2D uTexture;
uniform float uSize;
uniform vec3 uColor;
uniform float uReplaceColor;
Expand Down Expand Up @@ -58,7 +58,7 @@ void main()
pixCoord = unmapCoord(pixCoord);

// sample the color at grid position
vec4 color = texture(uSampler, pixCoord);
vec4 color = texture(uTexture, pixCoord);

// brightness of the color as it's perceived by the human eye
float gray = 0.3 * color.r + 0.59 * color.g + 0.11 * color.b;
Expand Down
8 changes: 4 additions & 4 deletions filters/bevel/src/bevel.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ precision highp float;
in vec2 vTextureCoord;
out vec4 finalColor;

uniform sampler2D uSampler;
uniform sampler2D uTexture;
uniform vec2 uTransform;
uniform vec3 uLightColor;
uniform float uLightAlpha;
Expand All @@ -13,9 +13,9 @@ uniform vec4 uInputSize;

void main(void) {
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;
vec4 color = texture(uTexture, vTextureCoord);
float light = texture(uTexture, vTextureCoord - transform).a;
float shadow = texture(uTexture, vTextureCoord + transform).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));
Expand Down
4 changes: 2 additions & 2 deletions filters/bulge-pinch/src/bulge-pinch.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ precision highp float;
in vec2 vTextureCoord;
out vec4 finalColor;

uniform sampler2D uSampler;
uniform sampler2D uTexture;
uniform vec2 uDimensions;
uniform vec2 uCenter;
uniform float uRadius;
Expand All @@ -29,7 +29,7 @@ void main()
coord += uCenter * uDimensions.xy;
coord /= uInputSize.xy;
vec2 clampedCoord = clamp(coord, uInputClamp.xy, uInputClamp.zw);
vec4 color = texture(uSampler, clampedCoord);
vec4 color = texture(uTexture, clampedCoord);

if (coord != clampedCoord) {
color *= max(0.0, 1.0 - length(coord - clampedCoord));
Expand Down
4 changes: 2 additions & 2 deletions filters/color-gradient/src/color-gradient.frag
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const int TYPE_RADIAL = 1;
const int TYPE_CONIC = 2;
const int MAX_STOPS = 32;

uniform sampler2D uSampler;
uniform sampler2D uTexture;
uniform int uNumStops;
uniform float uAlphas[3*MAX_STOPS];
uniform vec3 uColors[MAX_STOPS];
Expand Down Expand Up @@ -66,7 +66,7 @@ float projectPosition(vec2 pos, int type, float angle) {

void main(void) {
// current/original color
vec4 currentColor = texture(uSampler, vTextureCoord);
vec4 currentColor = texture(uTexture, vTextureCoord);

// skip calculations if gradient alpha is 0
if (0.0 == uAlpha) {
Expand Down
4 changes: 2 additions & 2 deletions filters/color-map/src/color-map.frag
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
in vec2 vTextureCoord;
out vec4 finalColor;

uniform sampler2D uSampler;
uniform sampler2D uTexture;
uniform sampler2D uMapTexture;
uniform float uMix;
uniform float uSize;
Expand All @@ -10,7 +10,7 @@ uniform float uSlicePixelSize;
uniform float uSliceInnerSize;

void main() {
vec4 color = texture(uSampler, vTextureCoord.xy);
vec4 color = texture(uTexture, vTextureCoord.xy);
vec4 adjusted;

if (color.a > 0.0) {
Expand Down
4 changes: 2 additions & 2 deletions filters/color-overlay/src/color-overlay.frag
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
in vec2 vTextureCoord;
out vec4 finalColor;

uniform sampler2D uSampler;
uniform sampler2D uTexture;
uniform vec3 uColor;
uniform float uAlpha;

void main(void) {
vec4 c = texture(uSampler, vTextureCoord);
vec4 c = texture(uTexture, vTextureCoord);
finalColor = vec4(mix(c.rgb, uColor.rgb, c.a * uAlpha), c.a);
}
4 changes: 2 additions & 2 deletions filters/color-replace/src/color-replace.frag
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
in vec2 vTextureCoord;
out vec4 finalColor;

uniform sampler2D uSampler;
uniform sampler2D uTexture;
uniform vec3 uOriginalColor;
uniform vec3 uTargetColor;
uniform float uTolerance;

void main(void) {
vec4 c = texture(uSampler, vTextureCoord);
vec4 c = texture(uTexture, vTextureCoord);
vec3 colorDiff = uOriginalColor - (c.rgb / max(c.a, 0.0000000001));
float colorDistance = length(colorDiff);
float doReplace = step(colorDistance, uTolerance);
Expand Down
20 changes: 10 additions & 10 deletions filters/convolution/src/convolution.frag
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
in vec2 vTextureCoord;
out vec4 finalColor;

uniform sampler2D uSampler;
uniform sampler2D uTexture;
uniform vec2 uTexelSize;
uniform float uMatrix[9];

void main(void)
{
vec4 c11 = texture(uSampler, vTextureCoord - uTexelSize); // top left
vec4 c12 = texture(uSampler, vec2(vTextureCoord.x, vTextureCoord.y - uTexelSize.y)); // top center
vec4 c13 = texture(uSampler, vec2(vTextureCoord.x + uTexelSize.x, vTextureCoord.y - uTexelSize.y)); // top right
vec4 c11 = texture(uTexture, vTextureCoord - uTexelSize); // top left
vec4 c12 = texture(uTexture, vec2(vTextureCoord.x, vTextureCoord.y - uTexelSize.y)); // top center
vec4 c13 = texture(uTexture, vec2(vTextureCoord.x + uTexelSize.x, vTextureCoord.y - uTexelSize.y)); // top right

vec4 c21 = texture(uSampler, vec2(vTextureCoord.x - uTexelSize.x, vTextureCoord.y)); // mid left
vec4 c22 = texture(uSampler, vTextureCoord); // mid center
vec4 c23 = texture(uSampler, vec2(vTextureCoord.x + uTexelSize.x, vTextureCoord.y)); // mid right
vec4 c21 = texture(uTexture, vec2(vTextureCoord.x - uTexelSize.x, vTextureCoord.y)); // mid left
vec4 c22 = texture(uTexture, vTextureCoord); // mid center
vec4 c23 = texture(uTexture, vec2(vTextureCoord.x + uTexelSize.x, vTextureCoord.y)); // mid right

vec4 c31 = texture(uSampler, vec2(vTextureCoord.x - uTexelSize.x, vTextureCoord.y + uTexelSize.y)); // bottom left
vec4 c32 = texture(uSampler, vec2(vTextureCoord.x, vTextureCoord.y + uTexelSize.y)); // bottom center
vec4 c33 = texture(uSampler, vTextureCoord + uTexelSize); // bottom right
vec4 c31 = texture(uTexture, vec2(vTextureCoord.x - uTexelSize.x, vTextureCoord.y + uTexelSize.y)); // bottom left
vec4 c32 = texture(uTexture, vec2(vTextureCoord.x, vTextureCoord.y + uTexelSize.y)); // bottom center
vec4 c33 = texture(uTexture, vTextureCoord + uTexelSize); // bottom right

finalColor =
c11 * uMatrix[0] + c12 * uMatrix[1] + c13 * uMatrix[2] +
Expand Down
4 changes: 2 additions & 2 deletions filters/cross-hatch/src/crosshatch.frag
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
in vec2 vTextureCoord;
out vec4 finalColor;

uniform sampler2D uSampler;
uniform sampler2D uTexture;

void main(void)
{
float lum = length(texture(uSampler, vTextureCoord.xy).rgb);
float lum = length(texture(uTexture, vTextureCoord.xy).rgb);

finalColor = vec4(1.0, 1.0, 1.0, 1.0);

Expand Down
4 changes: 2 additions & 2 deletions filters/crt/src/crt.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ precision highp float;
in vec2 vTextureCoord;
out vec4 finalColor;

uniform sampler2D uSampler;
uniform sampler2D uTexture;
uniform vec4 uLine;
uniform vec2 uNoise;
uniform vec3 uVignette;
Expand Down Expand Up @@ -62,7 +62,7 @@ vec3 interlaceLines(vec3 co, vec2 coord)

void main(void)
{
finalColor = texture(uSampler, vTextureCoord);
finalColor = texture(uTexture, vTextureCoord);
vec2 coord = vTextureCoord * uInputSize.xy / uDimensions;

if (uNoise[0] > 0.0 && uNoise[1] > 0.0)
Expand Down
4 changes: 2 additions & 2 deletions filters/dot/src/dot.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ precision highp float;
in vec2 vTextureCoord;
out vec4 finalColor;

uniform sampler2D uSampler;
uniform sampler2D uTexture;
uniform float uAngle;
uniform float uScale;
uniform bool uGreyscale;
Expand All @@ -22,7 +22,7 @@ float pattern()

void main()
{
vec4 color = texture(uSampler, vTextureCoord);
vec4 color = texture(uTexture, vTextureCoord);
vec3 colorRGB = vec3(color);

if (uGreyscale)
Expand Down
4 changes: 2 additions & 2 deletions filters/drop-shadow/src/DropShadowFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ export class DropShadowFilter extends Filter
fragment: `
in vec2 vTextureCoord;
out vec4 finalColor;
uniform sampler2D uSampler;
uniform sampler2D uTexture;
void main(void){
finalColor = texture(uSampler, vTextureCoord);
finalColor = texture(uTexture, vTextureCoord);
}
`,
name: 'drop-shadow-filter',
Expand Down
4 changes: 2 additions & 2 deletions filters/drop-shadow/src/drop-shadow.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ precision highp float;
in vec2 vTextureCoord;
out vec4 finalColor;

uniform sampler2D uSampler;
uniform sampler2D uTexture;
uniform float uAlpha;
uniform vec3 uColor;
uniform vec2 uOffset;

uniform vec4 uInputSize;

void main(void){
vec4 sample = texture(uSampler, vTextureCoord - uOffset * uInputSize.zw);
vec4 sample = texture(uTexture, vTextureCoord - uOffset * uInputSize.zw);

// Premultiply alpha
sample.rgb = uColor.rgb * sample.a;
Expand Down
8 changes: 4 additions & 4 deletions filters/emboss/src/emboss.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ precision highp float;
in vec2 vTextureCoord;
out vec4 finalColor;

uniform sampler2D uSampler;
uniform sampler2D uTexture;
uniform float uStrength;

uniform vec4 uInputSize;
Expand All @@ -15,12 +15,12 @@ void main(void)

color.rgb = vec3(0.5);

color -= texture(uSampler, vTextureCoord - onePixel) * uStrength;
color += texture(uSampler, vTextureCoord + onePixel) * uStrength;
color -= texture(uTexture, vTextureCoord - onePixel) * uStrength;
color += texture(uTexture, vTextureCoord + onePixel) * uStrength;

color.rgb = vec3((color.r + color.g + color.b) / 3.0);

float alpha = texture(uSampler, vTextureCoord).a;
float alpha = texture(uTexture, vTextureCoord).a;

finalColor = vec4(color.rgb * alpha, alpha);
}
10 changes: 5 additions & 5 deletions filters/glitch/src/glitch.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ precision highp float;
in vec2 vTextureCoord;
out vec4 finalColor;

uniform sampler2D uSampler;
uniform sampler2D uTexture;
uniform sampler2D uDisplacementMap;
uniform float uSeed;
uniform vec2 uDimensions;
Expand Down Expand Up @@ -90,8 +90,8 @@ void main(void)
}
}

finalColor.r = texture(uSampler, coord + uRed * (1.0 - uSeed * 0.4) / uInputSize.xy).r;
finalColor.g = texture(uSampler, coord + uGreen * (1.0 - uSeed * 0.3) / uInputSize.xy).g;
finalColor.b = texture(uSampler, coord + uBlue * (1.0 - uSeed * 0.2) / uInputSize.xy).b;
finalColor.a = texture(uSampler, coord).a;
finalColor.r = texture(uTexture, coord + uRed * (1.0 - uSeed * 0.4) / uInputSize.xy).r;
finalColor.g = texture(uTexture, coord + uGreen * (1.0 - uSeed * 0.3) / uInputSize.xy).g;
finalColor.b = texture(uTexture, coord + uBlue * (1.0 - uSeed * 0.2) / uInputSize.xy).b;
finalColor.a = texture(uTexture, coord).a;
}
6 changes: 3 additions & 3 deletions filters/glow/src/glow.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ precision highp float;
in vec2 vTextureCoord;
out vec4 finalColor;

uniform sampler2D uSampler;
uniform sampler2D uTexture;
uniform vec2 uStrength;
uniform vec3 uColor;
uniform float uKnockout;
Expand Down Expand Up @@ -33,12 +33,12 @@ void main(void) {

for (float curDistance = 0.; curDistance < DIST; curDistance++) {
displaced = clamp(vTextureCoord + direction * (curDistance + 1.), uInputClamp.xy, uInputClamp.zw);
curColor = texture(uSampler, displaced);
curColor = texture(uTexture, displaced);
totalAlpha += (DIST - curDistance) * curColor.a;
}
}

curColor = texture(uSampler, vTextureCoord);
curColor = texture(uTexture, vTextureCoord);

vec4 glowColor = vec4(uColor, uAlpha);
bool knockout = uKnockout > .5;
Expand Down
4 changes: 2 additions & 2 deletions filters/godray/src/god-ray.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ precision highp float;
in vec2 vTextureCoord;
out vec4 finalColor;

uniform sampler2D uSampler;
uniform sampler2D uTexture;
uniform vec2 uDimensions;
uniform float uParallel;
uniform vec2 uLight;
Expand Down Expand Up @@ -51,5 +51,5 @@ void main(void) {
// apply user alpha
mist *= alpha;

finalColor = texture(uSampler, vTextureCoord) + mist;
finalColor = texture(uTexture, vTextureCoord) + mist;
}
4 changes: 2 additions & 2 deletions filters/grayscale/src/grayscale.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ in vec2 vTextureCoord;

out vec4 finalColor;

uniform sampler2D uSampler;
uniform sampler2D uTexture;

// https://en.wikipedia.org/wiki/Luma_(video)
const vec3 weight = vec3(0.299, 0.587, 0.114);

void main()
{
vec4 c = texture(uSampler, vTextureCoord);
vec4 c = texture(uTexture, vTextureCoord);
finalColor = vec4(
vec3(c.r * weight.r + c.g * weight.g + c.b * weight.b),
c.a
Expand Down
Loading

0 comments on commit d8ffdf5

Please sign in to comment.