/* SPDX-FileCopyrightText: 2026 Blender Authors
 *
 * SPDX-License-Identifier: GPL-2.0-or-later */

#include "infos/engine_image_infos.hh"

#include "gpu_shader_math_matrix_transform_lib.glsl"
#include "gpu_shader_tiled_image_lookup_lib.glsl"
#include "image_engine_lib.glsl"

void main()
{
  const float2 coordinates = transform_point(to_float3x3(image_matrix), screen_uv);
  float3 tiled_coordinates = float3(coordinates, 0.0f);
  if (!tiled_image_lookup(tiled_coordinates, image_tile_array, image_tile_data)) {
    out_color = float4(0.0f);
    gl_FragDepth = Z_DEPTH_BORDER;
    return;
  }

  const float4 image_color = texture(image_tile_array, tiled_coordinates);
  out_color = image_engine_apply_parameters(
      image_color, draw_flags, is_image_premultiplied, shuffle, FAR_DISTANCE, NEAR_DISTANCE);
  gl_FragDepth = Z_DEPTH_IMAGE;
}
