Skip to content

Instantly share code, notes, and snippets.

@leochocolat
Created October 7, 2020 08:22
Show Gist options
  • Save leochocolat/49b1b31c87954d126c2327d2e5edce44 to your computer and use it in GitHub Desktop.
Save leochocolat/49b1b31c87954d126c2327d2e5edce44 to your computer and use it in GitHub Desktop.
#define numTextures 7
#define THRESHOLD 0.2
uniform vec3 iResolution;
uniform float iTime;
uniform float iTimeDelta;
uniform float iFrame;
uniform sampler2D u_texture;
// uniform sampler2D u_textures;
// uniform float[] u_transition_values;
uniform vec3 u_plane_resolution;
uniform vec3 u_aspect_ratio;
uniform float u_opacity;
varying vec2 vUv;
float gscale (vec3 c) {
return (c.r+c.g+c.b)/3.0;
}
vec4 resizedTexture(sampler2D texture, vec2 inital_uv, vec3 aspect_ratio)
{
vec2 ratio = vec2(
min((u_plane_resolution.x / u_plane_resolution.y) / (aspect_ratio.x / aspect_ratio.y), 1.0),
min((u_plane_resolution.y / u_plane_resolution.x) / (aspect_ratio.y / aspect_ratio.x), 1.0)
);
vec2 uv = vec2(
inital_uv.x * ratio.x + (1.0 - ratio.x) * 0.5,
inital_uv.y * ratio.y + (1.0 - ratio.y) * 0.5
);
return texture2D(texture, uv);
}
void mainImage (out vec4 fragColor, in vec2 fragCoord)
{
// vec4 mixedTextures = texture2D(u_texture[0], vUv);
// foreach(textures)
// {
// vec4 newText = texture2D(u_texture[0], vUv);
// vec4 mixedTextures = mix(mixedTextures, newText, u_transition_values[0]);
// }
fragColor = resizedTexture(u_texture, vUv, u_aspect_ratio) * u_opacity;
}
void main() {
mainImage(gl_FragColor, gl_FragCoord.xy);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment