#version 330 core

// fx-basic / move_scene vertex shader. Port of Android `v2_transform.vert`
// from the v2 (transition v2) renderer. Drives the per-slice "move
// scene" animated filter family (FxMoveUp/Down/Left/Right, FxZoomIn,
// ...). The host code rebuilds `transformMatrix` per frame from the
// FxBasicData sampler (translation + uniform scale) and supplies
// `orthographicMatrix` from the canvas aspect ratio. `hwRatio` is the
// source's height/width so the vertex math runs in a square space and
// the projection stretches it back to the canvas rect.
//
// The plain yuv420p.vs is too simple (it ignores any per-frame
// transform); we keep the v2 layout so future fx-basic variants can
// drop in extra matrices without changing the vertex pipeline.

layout(location = 0) in vec4 position;
layout(location = 1) in vec4 inputTextureCoordinate;

uniform mat4  transformMatrix;
uniform mat4  orthographicMatrix;
uniform float hwRatio;

out vec2 textureCoordinate;

// Pre-scale the quad's vertex position AND uv by `kOversize` around their
// respective centers (NDC origin for position, (0.5, 0.5) for uv) before
// applying the per-frame transformMatrix. This is the cheapest way to
// match Android `v1_reflect_tile.frag`: when a v1 fx-basic effect's
// centerX/centerY pushes the focus off-frame (e.g. Drop 01 starts at
// cx=1.089), the un-oversized quad would not cover the canvas's far
// side and that region rasterized to the background black-fill. With
// kOversize=3 the transformed quad spans roughly 3x the canvas on
// every axis even at maximum |tx|, so the rasterizer always invokes
// the fragment shader across the full canvas; the fragment then
// mirror-wraps any UV that falls outside [0,1]. Scaling both position
// and uv by the same factor (uv centered on 0.5 instead of 0) preserves
// the original visual mapping inside the visible region: at any canvas
// pixel the interpolated uv matches the pre-oversize formula exactly.
const float kOversize = 3.0;

void main() {
    vec2 posIn = position.xy * kOversize;
    vec2 uvIn  = (inputTextureCoordinate.xy - vec2(0.5)) * kOversize
                 + vec2(0.5);
    gl_Position = transformMatrix
                * vec4(posIn.x, posIn.y * hwRatio, position.z, 1.0)
                * orthographicMatrix;
    textureCoordinate = uvIn;
}
