// Generated by ShaderCompiler from Tinted.shader. Do not edit manually.
#pragma once

#include "ShaderCompilerTypes.h"
#if defined(WITH_RHI_D3D11)
#	include "D3d11GeneratedShaders.h"
#endif
#if defined(WITH_RHI_VULKAN)
#	include "VulkanGeneratedShaders.h"
#endif

#ifndef DOXYGEN_GENERATING_OUTPUT
namespace Jazz2::ShadersGen
{
#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
	inline constexpr char Tinted_Vs[] =
R"__SHDR__(#line 1

uniform mat4 uProjectionMatrix;
uniform mat4 uViewMatrix;

layout (std140) uniform InstanceBlock
{
	mat4 modelMatrix;
	vec4 color;
	vec4 texRect;
	vec2 spriteSize;
	// Flat index into the palette texture (added to the per-pixel index for the palette lookup). Lands in the
	// std140 tail padding after spriteSize, so the block stays 112 bytes. Only read by palette shaders.
	float palOffset;
};

out vec2 vTexCoords;
out vec4 vColor;
out highp float vPaletteOffset;

void main()
{
	vec2 aPosition = vec2(1.0 - float(gl_VertexID >> 1), float(gl_VertexID % 2));
	vec4 position = vec4(aPosition.x * spriteSize.x, aPosition.y * spriteSize.y, 0.0, 1.0);

	gl_Position = uProjectionMatrix * uViewMatrix * modelMatrix * position;
	vTexCoords = vec2(aPosition.x * texRect.x + texRect.y, aPosition.y * texRect.z + texRect.w);
	vColor = color;
	vPaletteOffset = palOffset;
}
)__SHDR__";
#endif

#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
	inline constexpr char Tinted_Vs100[] =
R"__SHDR__(attribute vec2 aQuadCorner;
#line 1

uniform mat4 uProjectionMatrix;
uniform mat4 uViewMatrix;

	uniform mat4 modelMatrix;
	uniform vec4 color;
	uniform vec4 texRect;
	uniform vec2 spriteSize;
	// Flat index into the palette texture (added to the per-pixel index for the palette lookup). Lands in the
	// std140 tail padding after spriteSize, so the block stays 112 bytes. Only read by palette shaders.
	uniform float palOffset;

varying vec2 vTexCoords;
varying vec4 vColor;
varying highp float vPaletteOffset;

void main()
{
	vec2 aPosition = vec2(1.0 - (1.0 - aQuadCorner.x), aQuadCorner.y);
	vec4 position = vec4(aPosition.x * spriteSize.x, aPosition.y * spriteSize.y, 0.0, 1.0);

	gl_Position = uProjectionMatrix * uViewMatrix * modelMatrix * position;
	vTexCoords = vec2(aPosition.x * texRect.x + texRect.y, aPosition.y * texRect.z + texRect.w);
	vColor = color;
	vPaletteOffset = palOffset;
}
)__SHDR__";
#endif

#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
	inline constexpr char Tinted_Fs[] =
R"__SHDR__(#line 1

#ifdef GL_ES
precision mediump float;
#endif

in vec2 vTexCoords;
in vec4 vColor;
in highp float vPaletteOffset;

uniform sampler2D uTexture;
#ifdef USE_PALETTE
uniform sampler2D uTexturePalette;
#endif

out vec4 COLOR;

void main() {
	COLOR = vColor;
#ifdef USE_PALETTE
	vec4 src = texture(uTexture, vTexCoords);
	highp float palIndex = floor(vPaletteOffset + 0.5) + floor(src.r * 255.0 + 0.5);
	highp float palX = (mod(palIndex, 256.0) + 0.5) / 256.0;
	highp float palY = (floor(palIndex / 256.0) + 0.5) / 256.0;
	vec4 original = texture(uTexturePalette, vec2(palX, palY));
	original.a *= src.a;
#else
	vec4 original = texture(uTexture, vTexCoords);
#endif
	vec3 tinted = mix(original.rgb, COLOR.rgb, 0.45);
	COLOR = vec4(tinted.r, tinted.g, tinted.b, original.a * COLOR.a);
}

)__SHDR__";
#endif

#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
	inline constexpr char Tinted_Fs100[] =
R"__SHDR__(#line 1

precision mediump float;

varying vec2 vTexCoords;
varying vec4 vColor;
varying highp float vPaletteOffset;

uniform sampler2D uTexture;
#ifdef USE_PALETTE
uniform sampler2D uTexturePalette;
#endif


void main() {
	vec4 COLOR;
	COLOR = vColor;
#ifdef USE_PALETTE
	vec4 src = texture2D(uTexture, vTexCoords);
	highp float palIndex = floor(vPaletteOffset + 0.5) + floor(src.r * 255.0 + 0.5);
	highp float palX = (mod(palIndex, 256.0) + 0.5) / 256.0;
	highp float palY = (floor(palIndex / 256.0) + 0.5) / 256.0;
	vec4 original = texture2D(uTexturePalette, vec2(palX, palY));
	original.a *= src.a;
#else
	vec4 original = texture2D(uTexture, vTexCoords);
#endif
	vec3 tinted = mix(original.rgb, COLOR.rgb, 0.45);
	COLOR = vec4(tinted.r, tinted.g, tinted.b, original.a * COLOR.a);
	gl_FragColor = COLOR;
}

)__SHDR__";
#endif

	inline constexpr ShaderCompiler::Uniform Tinted_Uniforms[] = {
		{ "uProjectionMatrix", ShaderCompiler::UniformType::Mat4, 0 },
		{ "uViewMatrix", ShaderCompiler::UniformType::Mat4, 0 },
	};

	inline constexpr ShaderCompiler::BlockMember Tinted_Block0_Members[] = {
		{ "modelMatrix", ShaderCompiler::UniformType::Mat4, 0, 0 },
		{ "color", ShaderCompiler::UniformType::Vec4, 0, 64 },
		{ "texRect", ShaderCompiler::UniformType::Vec4, 0, 80 },
		{ "spriteSize", ShaderCompiler::UniformType::Vec2, 0, 96 },
		{ "palOffset", ShaderCompiler::UniformType::Float, 0, 104 },
	};

	inline constexpr ShaderCompiler::UniformBlock Tinted_Blocks[] = {
		{ "InstanceBlock", 112, 0, 5, Tinted_Block0_Members },
	};

	inline constexpr ShaderCompiler::TextureBinding Tinted_Textures[] = {
		{ "uTexture", 0 },
	};

#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
	inline constexpr char Tinted_USE_PALETTE_Vs[] =
R"__SHDR__(#define USE_PALETTE (1)
#line 1

uniform mat4 uProjectionMatrix;
uniform mat4 uViewMatrix;

layout (std140) uniform InstanceBlock
{
	mat4 modelMatrix;
	vec4 color;
	vec4 texRect;
	vec2 spriteSize;
	// Flat index into the palette texture (added to the per-pixel index for the palette lookup). Lands in the
	// std140 tail padding after spriteSize, so the block stays 112 bytes. Only read by palette shaders.
	float palOffset;
};

out vec2 vTexCoords;
out vec4 vColor;
out highp float vPaletteOffset;

void main()
{
	vec2 aPosition = vec2(1.0 - float(gl_VertexID >> 1), float(gl_VertexID % 2));
	vec4 position = vec4(aPosition.x * spriteSize.x, aPosition.y * spriteSize.y, 0.0, 1.0);

	gl_Position = uProjectionMatrix * uViewMatrix * modelMatrix * position;
	vTexCoords = vec2(aPosition.x * texRect.x + texRect.y, aPosition.y * texRect.z + texRect.w);
	vColor = color;
	vPaletteOffset = palOffset;
}
)__SHDR__";
#endif

#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
	inline constexpr char Tinted_USE_PALETTE_Vs100[] =
R"__SHDR__(attribute vec2 aQuadCorner;
#define USE_PALETTE (1)
#line 1

uniform mat4 uProjectionMatrix;
uniform mat4 uViewMatrix;

	uniform mat4 modelMatrix;
	uniform vec4 color;
	uniform vec4 texRect;
	uniform vec2 spriteSize;
	// Flat index into the palette texture (added to the per-pixel index for the palette lookup). Lands in the
	// std140 tail padding after spriteSize, so the block stays 112 bytes. Only read by palette shaders.
	uniform float palOffset;

varying vec2 vTexCoords;
varying vec4 vColor;
varying highp float vPaletteOffset;

void main()
{
	vec2 aPosition = vec2(1.0 - (1.0 - aQuadCorner.x), aQuadCorner.y);
	vec4 position = vec4(aPosition.x * spriteSize.x, aPosition.y * spriteSize.y, 0.0, 1.0);

	gl_Position = uProjectionMatrix * uViewMatrix * modelMatrix * position;
	vTexCoords = vec2(aPosition.x * texRect.x + texRect.y, aPosition.y * texRect.z + texRect.w);
	vColor = color;
	vPaletteOffset = palOffset;
}
)__SHDR__";
#endif

#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
	inline constexpr char Tinted_USE_PALETTE_Fs[] =
R"__SHDR__(#define USE_PALETTE (1)
#line 1

#ifdef GL_ES
precision mediump float;
#endif

in vec2 vTexCoords;
in vec4 vColor;
in highp float vPaletteOffset;

uniform sampler2D uTexture;
#ifdef USE_PALETTE
uniform sampler2D uTexturePalette;
#endif

out vec4 COLOR;

void main() {
	COLOR = vColor;
#ifdef USE_PALETTE
	vec4 src = texture(uTexture, vTexCoords);
	highp float palIndex = floor(vPaletteOffset + 0.5) + floor(src.r * 255.0 + 0.5);
	highp float palX = (mod(palIndex, 256.0) + 0.5) / 256.0;
	highp float palY = (floor(palIndex / 256.0) + 0.5) / 256.0;
	vec4 original = texture(uTexturePalette, vec2(palX, palY));
	original.a *= src.a;
#else
	vec4 original = texture(uTexture, vTexCoords);
#endif
	vec3 tinted = mix(original.rgb, COLOR.rgb, 0.45);
	COLOR = vec4(tinted.r, tinted.g, tinted.b, original.a * COLOR.a);
}

)__SHDR__";
#endif

#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
	inline constexpr char Tinted_USE_PALETTE_Fs100[] =
R"__SHDR__(#define USE_PALETTE (1)
#line 1

precision mediump float;

varying vec2 vTexCoords;
varying vec4 vColor;
varying highp float vPaletteOffset;

uniform sampler2D uTexture;
#ifdef USE_PALETTE
uniform sampler2D uTexturePalette;
#endif


void main() {
	vec4 COLOR;
	COLOR = vColor;
#ifdef USE_PALETTE
	vec4 src = texture2D(uTexture, vTexCoords);
	highp float palIndex = floor(vPaletteOffset + 0.5) + floor(src.r * 255.0 + 0.5);
	highp float palX = (mod(palIndex, 256.0) + 0.5) / 256.0;
	highp float palY = (floor(palIndex / 256.0) + 0.5) / 256.0;
	vec4 original = texture2D(uTexturePalette, vec2(palX, palY));
	original.a *= src.a;
#else
	vec4 original = texture2D(uTexture, vTexCoords);
#endif
	vec3 tinted = mix(original.rgb, COLOR.rgb, 0.45);
	COLOR = vec4(tinted.r, tinted.g, tinted.b, original.a * COLOR.a);
	gl_FragColor = COLOR;
}

)__SHDR__";
#endif

	inline constexpr ShaderCompiler::Uniform Tinted_USE_PALETTE_Uniforms[] = {
		{ "uProjectionMatrix", ShaderCompiler::UniformType::Mat4, 0 },
		{ "uViewMatrix", ShaderCompiler::UniformType::Mat4, 0 },
	};

	inline constexpr ShaderCompiler::BlockMember Tinted_USE_PALETTE_Block0_Members[] = {
		{ "modelMatrix", ShaderCompiler::UniformType::Mat4, 0, 0 },
		{ "color", ShaderCompiler::UniformType::Vec4, 0, 64 },
		{ "texRect", ShaderCompiler::UniformType::Vec4, 0, 80 },
		{ "spriteSize", ShaderCompiler::UniformType::Vec2, 0, 96 },
		{ "palOffset", ShaderCompiler::UniformType::Float, 0, 104 },
	};

	inline constexpr ShaderCompiler::UniformBlock Tinted_USE_PALETTE_Blocks[] = {
		{ "InstanceBlock", 112, 0, 5, Tinted_USE_PALETTE_Block0_Members },
	};

	inline constexpr ShaderCompiler::TextureBinding Tinted_USE_PALETTE_Textures[] = {
		{ "uTexture", 0 },
		{ "uTexturePalette", 1 },
	};

	inline constexpr ShaderCompiler::ProgramVariant Tinted_Variants[] = {
		{ "", "",
#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
			Tinted_Vs, Tinted_Fs,
#else
			nullptr, nullptr,
#endif
			2, Tinted_Uniforms, 1, Tinted_Blocks, 1, Tinted_Textures, 0, nullptr,
#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
			Tinted_Vs100, Tinted_Fs100,
#else
			nullptr, nullptr,
#endif
#if defined(WITH_RHI_D3D11)
			Tinted_VsHlsl, Tinted_FsHlsl,
			Tinted_VsDxbc, Tinted_VsDxbcSize, Tinted_FsDxbc, Tinted_FsDxbcSize,
#else
			nullptr, nullptr,
			nullptr, 0, nullptr, 0,
#endif
#if defined(WITH_RHI_VULKAN)
			Tinted_VkVs, Tinted_VkVsSize, Tinted_VkFs, Tinted_VkFsSize },
#else
			nullptr, 0, nullptr, 0 },
#endif
		{ "USE_PALETTE", "USE_PALETTE",
#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
			Tinted_USE_PALETTE_Vs, Tinted_USE_PALETTE_Fs,
#else
			nullptr, nullptr,
#endif
			2, Tinted_USE_PALETTE_Uniforms, 1, Tinted_USE_PALETTE_Blocks, 2, Tinted_USE_PALETTE_Textures, 0, nullptr,
#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
			Tinted_USE_PALETTE_Vs100, Tinted_USE_PALETTE_Fs100,
#else
			nullptr, nullptr,
#endif
#if defined(WITH_RHI_D3D11)
			Tinted_USE_PALETTE_VsHlsl, Tinted_USE_PALETTE_FsHlsl,
			Tinted_USE_PALETTE_VsDxbc, Tinted_USE_PALETTE_VsDxbcSize, Tinted_USE_PALETTE_FsDxbc, Tinted_USE_PALETTE_FsDxbcSize,
#else
			nullptr, nullptr,
			nullptr, 0, nullptr, 0,
#endif
#if defined(WITH_RHI_VULKAN)
			Tinted_USE_PALETTE_VkVs, Tinted_USE_PALETTE_VkVsSize, Tinted_USE_PALETTE_VkFs, Tinted_USE_PALETTE_VkFsSize },
#else
			nullptr, 0, nullptr, 0 },
#endif
	};

	inline constexpr ShaderCompiler::Program Tinted = { "Tinted", 0, 2, Tinted_Variants };

#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
	inline constexpr char BatchedTinted_Vs[] =
R"__SHDR__(#line 1

uniform mat4 uProjectionMatrix;
uniform mat4 uViewMatrix;

struct Instance
{
	mat4 modelMatrix;
	vec4 color;
	vec4 texRect;
	vec2 spriteSize;
	// Flat index into the palette texture; lands in the std140 tail padding, so the stride stays 112 bytes
	float palOffset;
};

layout (std140) uniform InstancesBlock
{
#ifndef BATCH_SIZE
	#define BATCH_SIZE (585) // 64 Kb / 112 b
#endif
	Instance[BATCH_SIZE] instances;
} block;

out vec2 vTexCoords;
out vec4 vColor;
out highp float vPaletteOffset;

#define i block.instances[gl_VertexID / 6]

void main()
{
	vec2 aPosition = vec2(1.0 - float(((gl_VertexID + 2) / 3) % 2), 1.0 - float(((gl_VertexID + 1) / 3) % 2));
	vec4 position = vec4(aPosition.x * i.spriteSize.x, aPosition.y * i.spriteSize.y, 0.0, 1.0);

	gl_Position = uProjectionMatrix * uViewMatrix * i.modelMatrix * position;
	vTexCoords = vec2(aPosition.x * i.texRect.x + i.texRect.y, aPosition.y * i.texRect.z + i.texRect.w);
	vColor = i.color;
	vPaletteOffset = i.palOffset;
}
)__SHDR__";
#endif

#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
	inline constexpr char BatchedTinted_Vs100[] =
R"__SHDR__(attribute vec2 aQuadCorner;
attribute float aInstanceIndex;
#line 1

uniform mat4 uProjectionMatrix;
uniform mat4 uViewMatrix;

struct Instance
{
	mat4 modelMatrix;
	vec4 color;
	vec4 texRect;
	vec2 spriteSize;
	// Flat index into the palette texture; lands in the std140 tail padding, so the stride stays 112 bytes
	float palOffset;
};

#ifndef BATCH_SIZE
	#define BATCH_SIZE (585) // 64 Kb / 112 b
#endif
	uniform Instance instances[BATCH_SIZE];

varying vec2 vTexCoords;
varying vec4 vColor;
varying highp float vPaletteOffset;

#define i instances[int(aInstanceIndex)]

void main()
{
	vec2 aPosition = vec2(1.0 - (1.0 - aQuadCorner.x), 1.0 - (1.0 - aQuadCorner.y));
	vec4 position = vec4(aPosition.x * i.spriteSize.x, aPosition.y * i.spriteSize.y, 0.0, 1.0);

	gl_Position = uProjectionMatrix * uViewMatrix * i.modelMatrix * position;
	vTexCoords = vec2(aPosition.x * i.texRect.x + i.texRect.y, aPosition.y * i.texRect.z + i.texRect.w);
	vColor = i.color;
	vPaletteOffset = i.palOffset;
}
)__SHDR__";
#endif

#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
	inline constexpr char BatchedTinted_Fs[] =
R"__SHDR__(#line 1

#ifdef GL_ES
precision mediump float;
#endif

in vec2 vTexCoords;
in vec4 vColor;
in highp float vPaletteOffset;

uniform sampler2D uTexture;
#ifdef USE_PALETTE
uniform sampler2D uTexturePalette;
#endif

out vec4 COLOR;

void main() {
	COLOR = vColor;
#ifdef USE_PALETTE
	vec4 src = texture(uTexture, vTexCoords);
	highp float palIndex = floor(vPaletteOffset + 0.5) + floor(src.r * 255.0 + 0.5);
	highp float palX = (mod(palIndex, 256.0) + 0.5) / 256.0;
	highp float palY = (floor(palIndex / 256.0) + 0.5) / 256.0;
	vec4 original = texture(uTexturePalette, vec2(palX, palY));
	original.a *= src.a;
#else
	vec4 original = texture(uTexture, vTexCoords);
#endif
	vec3 tinted = mix(original.rgb, COLOR.rgb, 0.45);
	COLOR = vec4(tinted.r, tinted.g, tinted.b, original.a * COLOR.a);
}

)__SHDR__";
#endif

#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
	inline constexpr char BatchedTinted_Fs100[] =
R"__SHDR__(#line 1

precision mediump float;

varying vec2 vTexCoords;
varying vec4 vColor;
varying highp float vPaletteOffset;

uniform sampler2D uTexture;
#ifdef USE_PALETTE
uniform sampler2D uTexturePalette;
#endif


void main() {
	vec4 COLOR;
	COLOR = vColor;
#ifdef USE_PALETTE
	vec4 src = texture2D(uTexture, vTexCoords);
	highp float palIndex = floor(vPaletteOffset + 0.5) + floor(src.r * 255.0 + 0.5);
	highp float palX = (mod(palIndex, 256.0) + 0.5) / 256.0;
	highp float palY = (floor(palIndex / 256.0) + 0.5) / 256.0;
	vec4 original = texture2D(uTexturePalette, vec2(palX, palY));
	original.a *= src.a;
#else
	vec4 original = texture2D(uTexture, vTexCoords);
#endif
	vec3 tinted = mix(original.rgb, COLOR.rgb, 0.45);
	COLOR = vec4(tinted.r, tinted.g, tinted.b, original.a * COLOR.a);
	gl_FragColor = COLOR;
}

)__SHDR__";
#endif

	inline constexpr ShaderCompiler::Uniform BatchedTinted_Uniforms[] = {
		{ "uProjectionMatrix", ShaderCompiler::UniformType::Mat4, 0 },
		{ "uViewMatrix", ShaderCompiler::UniformType::Mat4, 0 },
	};

	inline constexpr ShaderCompiler::BlockMember BatchedTinted_Block0_Members[] = {
		{ "instances", ShaderCompiler::UniformType::Struct, ShaderCompiler::SymbolicArraySize, 0 },
	};

	inline constexpr ShaderCompiler::UniformBlock BatchedTinted_Blocks[] = {
		{ "InstancesBlock", 0, 112, 1, BatchedTinted_Block0_Members },
	};

	inline constexpr ShaderCompiler::TextureBinding BatchedTinted_Textures[] = {
		{ "uTexture", 0 },
	};

#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
	inline constexpr char BatchedTinted_USE_PALETTE_Vs[] =
R"__SHDR__(#define USE_PALETTE (1)
#line 1

uniform mat4 uProjectionMatrix;
uniform mat4 uViewMatrix;

struct Instance
{
	mat4 modelMatrix;
	vec4 color;
	vec4 texRect;
	vec2 spriteSize;
	// Flat index into the palette texture; lands in the std140 tail padding, so the stride stays 112 bytes
	float palOffset;
};

layout (std140) uniform InstancesBlock
{
#ifndef BATCH_SIZE
	#define BATCH_SIZE (585) // 64 Kb / 112 b
#endif
	Instance[BATCH_SIZE] instances;
} block;

out vec2 vTexCoords;
out vec4 vColor;
out highp float vPaletteOffset;

#define i block.instances[gl_VertexID / 6]

void main()
{
	vec2 aPosition = vec2(1.0 - float(((gl_VertexID + 2) / 3) % 2), 1.0 - float(((gl_VertexID + 1) / 3) % 2));
	vec4 position = vec4(aPosition.x * i.spriteSize.x, aPosition.y * i.spriteSize.y, 0.0, 1.0);

	gl_Position = uProjectionMatrix * uViewMatrix * i.modelMatrix * position;
	vTexCoords = vec2(aPosition.x * i.texRect.x + i.texRect.y, aPosition.y * i.texRect.z + i.texRect.w);
	vColor = i.color;
	vPaletteOffset = i.palOffset;
}
)__SHDR__";
#endif

#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
	inline constexpr char BatchedTinted_USE_PALETTE_Vs100[] =
R"__SHDR__(attribute vec2 aQuadCorner;
attribute float aInstanceIndex;
#define USE_PALETTE (1)
#line 1

uniform mat4 uProjectionMatrix;
uniform mat4 uViewMatrix;

struct Instance
{
	mat4 modelMatrix;
	vec4 color;
	vec4 texRect;
	vec2 spriteSize;
	// Flat index into the palette texture; lands in the std140 tail padding, so the stride stays 112 bytes
	float palOffset;
};

#ifndef BATCH_SIZE
	#define BATCH_SIZE (585) // 64 Kb / 112 b
#endif
	uniform Instance instances[BATCH_SIZE];

varying vec2 vTexCoords;
varying vec4 vColor;
varying highp float vPaletteOffset;

#define i instances[int(aInstanceIndex)]

void main()
{
	vec2 aPosition = vec2(1.0 - (1.0 - aQuadCorner.x), 1.0 - (1.0 - aQuadCorner.y));
	vec4 position = vec4(aPosition.x * i.spriteSize.x, aPosition.y * i.spriteSize.y, 0.0, 1.0);

	gl_Position = uProjectionMatrix * uViewMatrix * i.modelMatrix * position;
	vTexCoords = vec2(aPosition.x * i.texRect.x + i.texRect.y, aPosition.y * i.texRect.z + i.texRect.w);
	vColor = i.color;
	vPaletteOffset = i.palOffset;
}
)__SHDR__";
#endif

#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
	inline constexpr char BatchedTinted_USE_PALETTE_Fs[] =
R"__SHDR__(#define USE_PALETTE (1)
#line 1

#ifdef GL_ES
precision mediump float;
#endif

in vec2 vTexCoords;
in vec4 vColor;
in highp float vPaletteOffset;

uniform sampler2D uTexture;
#ifdef USE_PALETTE
uniform sampler2D uTexturePalette;
#endif

out vec4 COLOR;

void main() {
	COLOR = vColor;
#ifdef USE_PALETTE
	vec4 src = texture(uTexture, vTexCoords);
	highp float palIndex = floor(vPaletteOffset + 0.5) + floor(src.r * 255.0 + 0.5);
	highp float palX = (mod(palIndex, 256.0) + 0.5) / 256.0;
	highp float palY = (floor(palIndex / 256.0) + 0.5) / 256.0;
	vec4 original = texture(uTexturePalette, vec2(palX, palY));
	original.a *= src.a;
#else
	vec4 original = texture(uTexture, vTexCoords);
#endif
	vec3 tinted = mix(original.rgb, COLOR.rgb, 0.45);
	COLOR = vec4(tinted.r, tinted.g, tinted.b, original.a * COLOR.a);
}

)__SHDR__";
#endif

#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
	inline constexpr char BatchedTinted_USE_PALETTE_Fs100[] =
R"__SHDR__(#define USE_PALETTE (1)
#line 1

precision mediump float;

varying vec2 vTexCoords;
varying vec4 vColor;
varying highp float vPaletteOffset;

uniform sampler2D uTexture;
#ifdef USE_PALETTE
uniform sampler2D uTexturePalette;
#endif


void main() {
	vec4 COLOR;
	COLOR = vColor;
#ifdef USE_PALETTE
	vec4 src = texture2D(uTexture, vTexCoords);
	highp float palIndex = floor(vPaletteOffset + 0.5) + floor(src.r * 255.0 + 0.5);
	highp float palX = (mod(palIndex, 256.0) + 0.5) / 256.0;
	highp float palY = (floor(palIndex / 256.0) + 0.5) / 256.0;
	vec4 original = texture2D(uTexturePalette, vec2(palX, palY));
	original.a *= src.a;
#else
	vec4 original = texture2D(uTexture, vTexCoords);
#endif
	vec3 tinted = mix(original.rgb, COLOR.rgb, 0.45);
	COLOR = vec4(tinted.r, tinted.g, tinted.b, original.a * COLOR.a);
	gl_FragColor = COLOR;
}

)__SHDR__";
#endif

	inline constexpr ShaderCompiler::Uniform BatchedTinted_USE_PALETTE_Uniforms[] = {
		{ "uProjectionMatrix", ShaderCompiler::UniformType::Mat4, 0 },
		{ "uViewMatrix", ShaderCompiler::UniformType::Mat4, 0 },
	};

	inline constexpr ShaderCompiler::BlockMember BatchedTinted_USE_PALETTE_Block0_Members[] = {
		{ "instances", ShaderCompiler::UniformType::Struct, ShaderCompiler::SymbolicArraySize, 0 },
	};

	inline constexpr ShaderCompiler::UniformBlock BatchedTinted_USE_PALETTE_Blocks[] = {
		{ "InstancesBlock", 0, 112, 1, BatchedTinted_USE_PALETTE_Block0_Members },
	};

	inline constexpr ShaderCompiler::TextureBinding BatchedTinted_USE_PALETTE_Textures[] = {
		{ "uTexture", 0 },
		{ "uTexturePalette", 1 },
	};

	inline constexpr ShaderCompiler::ProgramVariant BatchedTinted_Variants[] = {
		{ "", "",
#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
			BatchedTinted_Vs, BatchedTinted_Fs,
#else
			nullptr, nullptr,
#endif
			2, BatchedTinted_Uniforms, 1, BatchedTinted_Blocks, 1, BatchedTinted_Textures, 0, nullptr,
#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
			BatchedTinted_Vs100, BatchedTinted_Fs100,
#else
			nullptr, nullptr,
#endif
#if defined(WITH_RHI_D3D11)
			BatchedTinted_VsHlsl, BatchedTinted_FsHlsl,
			BatchedTinted_VsDxbc, BatchedTinted_VsDxbcSize, BatchedTinted_FsDxbc, BatchedTinted_FsDxbcSize,
#else
			nullptr, nullptr,
			nullptr, 0, nullptr, 0,
#endif
#if defined(WITH_RHI_VULKAN)
			BatchedTinted_VkVs, BatchedTinted_VkVsSize, BatchedTinted_VkFs, BatchedTinted_VkFsSize },
#else
			nullptr, 0, nullptr, 0 },
#endif
		{ "USE_PALETTE", "USE_PALETTE",
#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
			BatchedTinted_USE_PALETTE_Vs, BatchedTinted_USE_PALETTE_Fs,
#else
			nullptr, nullptr,
#endif
			2, BatchedTinted_USE_PALETTE_Uniforms, 1, BatchedTinted_USE_PALETTE_Blocks, 2, BatchedTinted_USE_PALETTE_Textures, 0, nullptr,
#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
			BatchedTinted_USE_PALETTE_Vs100, BatchedTinted_USE_PALETTE_Fs100,
#else
			nullptr, nullptr,
#endif
#if defined(WITH_RHI_D3D11)
			BatchedTinted_USE_PALETTE_VsHlsl, BatchedTinted_USE_PALETTE_FsHlsl,
			BatchedTinted_USE_PALETTE_VsDxbc, BatchedTinted_USE_PALETTE_VsDxbcSize, BatchedTinted_USE_PALETTE_FsDxbc, BatchedTinted_USE_PALETTE_FsDxbcSize,
#else
			nullptr, nullptr,
			nullptr, 0, nullptr, 0,
#endif
#if defined(WITH_RHI_VULKAN)
			BatchedTinted_USE_PALETTE_VkVs, BatchedTinted_USE_PALETTE_VkVsSize, BatchedTinted_USE_PALETTE_VkFs, BatchedTinted_USE_PALETTE_VkFsSize },
#else
			nullptr, 0, nullptr, 0 },
#endif
	};

	inline constexpr ShaderCompiler::Program BatchedTinted = { "BatchedTinted", 0, 2, BatchedTinted_Variants };
}
#endif
