/*
 * Copyright 2023-2025 Hartmut Seichter and Contributors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 */
#ifndef PARADISO_SHADER_SPRITE_HPP
#define PARADISO_SHADER_SPRITE_HPP

namespace paradiso {

static constexpr auto sprite_unlit_vertex = R"(
#version 400 core

layout (location = 0) in vec3 vertices;
layout (location = 1) in vec3 normals;
layout (location = 2) in vec2 texture_coords;

// pivot der sprite
uniform vec2 pivot = vec2( 0.0, 0.0 );
// scale
uniform vec2 scale = vec2( 1.0, 1.0 );
// rotation
uniform float rotation = 0.0;

// wir sind natuerlich in homogenenen 3D Koordinaten unterwegs
mat4 mm = mat4(
    vec4( scale.x, 0.0, 0.0, 0.0),
    vec4( 0.0, scale.y, 0.0, 0.0),
    vec4( 0.0, 0.0, 1.0, 0.0),
    vec4( pivot, 0.0, 1.0)
);

float sir = sin(rotation);
float cor = cos(rotation);

mat4 mr = mat4(
    vec4( cor, sir, 0.0, 0.0),
    vec4(-sir, cor, 0.0, 0.0),
    vec4( 0.0, 0.0, 1.0, 0.0),
    vec4( 0.0, 0.0, 0.0, 1.0)
    );

out vec2 tex_c; // das hier reicht die texturkoordinaten durch

void main() {
    tex_c = texture_coords; // umstaendlich aber notwendig
    gl_Position = mm * mr * vec4(vertices, 1.0); // unsere eigentliche shader transformation
}
)";

static constexpr auto sprite_unlit_fragment = R"(
#version 400 core

uniform sampler2D tex_color; // hier ist unsere sprite textur (bitmap)

in vec2 tex_c; // da sind die texturkoordinaten wieder

out vec4 frag_color; // das hier wird der output (pixelwert/fragment)

void main() {
    frag_color = texture(tex_color,tex_c);
})";
} // namespace paradiso

#endif
