Skip to content

Commit

Permalink
seamless transition between nearest and mipmap texture interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
PWhiddy committed Jan 30, 2024
1 parent 3aab74f commit 0374d71
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions visualizer_live.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ document.body.appendChild(app.view);

const zoomSpeed = 0.0015;

function smoothstep(min, max, value) {
const x = Math.max(0, Math.min(1, (value-min)/(max-min)));
return x*x*(3 - 2*x);
}

app.view.addEventListener('wheel', (e) => {
e.preventDefault();
const scaleFactor = 1.0 - (e.deltaY * zoomSpeed);
Expand All @@ -59,13 +64,12 @@ app.view.addEventListener('wheel', (e) => {
container.scale.y *= scaleFactor;

if (backgroundSmooth && backgroundSharp) {
if (container.scale.x < 2.0) {
backgroundSmooth.visible = true;
backgroundSharp.visible = false;
} else if (container.scale.x > 2.0) {
backgroundSmooth.visible = false;
backgroundSharp.visible = true;
}
const val = container.scale.x;
const start = 2;
const end = 4.5;
const smooth = smoothstep(start, end, val);
backgroundSharp.alpha = Math.pow(smooth, 0.3);
backgroundSmooth.alpha = Math.pow(1.0 - smooth, 0.3);
}

// Calculate the new position of the point
Expand Down Expand Up @@ -152,7 +156,7 @@ PIXI.Assets.load([
let textureSharp = new PIXI.Texture(baseTextureSharp);
backgroundSharp = new PIXI.Sprite(textureSharp);
backgroundSharp.anchor.set(0.5);
backgroundSharp.visible = false;
backgroundSharp.alpha = 0.0;

container.addChild(backgroundSmooth);
container.addChild(backgroundSharp);
Expand All @@ -165,7 +169,7 @@ PIXI.Assets.load([
const path = data["coords"];
const meta = data["metadata"];
console.log(meta);
if (Date.now() - lastFrameTime < animationDuration) {
if (Date.now() - lastFrameTime < 2 * animationDuration) {
startAnimationForPath(path, meta);
}
};
Expand All @@ -182,7 +186,7 @@ PIXI.Assets.load([
}, 120000);

let baseTextureChar = new PIXI.BaseTexture("assets/characters_transparent.png", {
// mipmap: PIXI.MIPMAP_MODES.ON
scaleMode: PIXI.SCALE_MODES.NEAREST,
});

const charOffset = 1; // 1 index here gets sprite direction index
Expand Down

0 comments on commit 0374d71

Please sign in to comment.