// Generated by ShaderCompiler from WhiteMask.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 WhiteMask_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 WhiteMask_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 WhiteMask_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

// Resolves the diffuse color, looking the palette index up in the palette texture when the sprite is indexed
vec4 maskSample(vec2 uv) {
	vec4 src = texture(uTexture, uv);
#ifdef USE_PALETTE
	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 c = texture(uTexturePalette, vec2(palX, palY));
	return vec4(c.rgb, c.a * src.a);
#else
	return src;
#endif
}

out vec4 COLOR;

void main() {
	COLOR = vColor;
	vec4 tex = maskSample(vTexCoords);
	float color = min((0.299 * tex.r + 0.587 * tex.g + 0.114 * tex.b) * 6.0, 1.0);
	COLOR = vec4(color, color, color, tex.a) * COLOR;
}

)__SHDR__";
#endif

#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
	inline constexpr char WhiteMask_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

// Resolves the diffuse color, looking the palette index up in the palette texture when the sprite is indexed
vec4 maskSample(vec2 uv) {
	vec4 src = texture2D(uTexture, uv);
#ifdef USE_PALETTE
	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 c = texture2D(uTexturePalette, vec2(palX, palY));
	return vec4(c.rgb, c.a * src.a);
#else
	return src;
#endif
}


void main() {
	vec4 COLOR;
	COLOR = vColor;
	vec4 tex = maskSample(vTexCoords);
	float color = min((0.299 * tex.r + 0.587 * tex.g + 0.114 * tex.b) * 6.0, 1.0);
	COLOR = vec4(color, color, color, tex.a) * COLOR;
	gl_FragColor = COLOR;
}

)__SHDR__";
#endif

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

	inline constexpr ShaderCompiler::BlockMember WhiteMask_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 WhiteMask_Blocks[] = {
		{ "InstanceBlock", 112, 0, 5, WhiteMask_Block0_Members },
	};

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

#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
	inline constexpr char WhiteMask_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 WhiteMask_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 WhiteMask_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

// Resolves the diffuse color, looking the palette index up in the palette texture when the sprite is indexed
vec4 maskSample(vec2 uv) {
	vec4 src = texture(uTexture, uv);
#ifdef USE_PALETTE
	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 c = texture(uTexturePalette, vec2(palX, palY));
	return vec4(c.rgb, c.a * src.a);
#else
	return src;
#endif
}

out vec4 COLOR;

void main() {
	COLOR = vColor;
	vec4 tex = maskSample(vTexCoords);
	float color = min((0.299 * tex.r + 0.587 * tex.g + 0.114 * tex.b) * 6.0, 1.0);
	COLOR = vec4(color, color, color, tex.a) * COLOR;
}

)__SHDR__";
#endif

#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
	inline constexpr char WhiteMask_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

// Resolves the diffuse color, looking the palette index up in the palette texture when the sprite is indexed
vec4 maskSample(vec2 uv) {
	vec4 src = texture2D(uTexture, uv);
#ifdef USE_PALETTE
	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 c = texture2D(uTexturePalette, vec2(palX, palY));
	return vec4(c.rgb, c.a * src.a);
#else
	return src;
#endif
}


void main() {
	vec4 COLOR;
	COLOR = vColor;
	vec4 tex = maskSample(vTexCoords);
	float color = min((0.299 * tex.r + 0.587 * tex.g + 0.114 * tex.b) * 6.0, 1.0);
	COLOR = vec4(color, color, color, tex.a) * COLOR;
	gl_FragColor = COLOR;
}

)__SHDR__";
#endif

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

	inline constexpr ShaderCompiler::BlockMember WhiteMask_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 WhiteMask_USE_PALETTE_Blocks[] = {
		{ "InstanceBlock", 112, 0, 5, WhiteMask_USE_PALETTE_Block0_Members },
	};

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

	inline constexpr ShaderCompiler::ProgramVariant WhiteMask_Variants[] = {
		{ "", "",
#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
			WhiteMask_Vs, WhiteMask_Fs,
#else
			nullptr, nullptr,
#endif
			2, WhiteMask_Uniforms, 1, WhiteMask_Blocks, 1, WhiteMask_Textures, 0, nullptr,
#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
			WhiteMask_Vs100, WhiteMask_Fs100,
#else
			nullptr, nullptr,
#endif
#if defined(WITH_RHI_D3D11)
			WhiteMask_VsHlsl, WhiteMask_FsHlsl,
			WhiteMask_VsDxbc, WhiteMask_VsDxbcSize, WhiteMask_FsDxbc, WhiteMask_FsDxbcSize,
#else
			nullptr, nullptr,
			nullptr, 0, nullptr, 0,
#endif
#if defined(WITH_RHI_VULKAN)
			WhiteMask_VkVs, WhiteMask_VkVsSize, WhiteMask_VkFs, WhiteMask_VkFsSize },
#else
			nullptr, 0, nullptr, 0 },
#endif
		{ "USE_PALETTE", "USE_PALETTE",
#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
			WhiteMask_USE_PALETTE_Vs, WhiteMask_USE_PALETTE_Fs,
#else
			nullptr, nullptr,
#endif
			2, WhiteMask_USE_PALETTE_Uniforms, 1, WhiteMask_USE_PALETTE_Blocks, 2, WhiteMask_USE_PALETTE_Textures, 0, nullptr,
#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
			WhiteMask_USE_PALETTE_Vs100, WhiteMask_USE_PALETTE_Fs100,
#else
			nullptr, nullptr,
#endif
#if defined(WITH_RHI_D3D11)
			WhiteMask_USE_PALETTE_VsHlsl, WhiteMask_USE_PALETTE_FsHlsl,
			WhiteMask_USE_PALETTE_VsDxbc, WhiteMask_USE_PALETTE_VsDxbcSize, WhiteMask_USE_PALETTE_FsDxbc, WhiteMask_USE_PALETTE_FsDxbcSize,
#else
			nullptr, nullptr,
			nullptr, 0, nullptr, 0,
#endif
#if defined(WITH_RHI_VULKAN)
			WhiteMask_USE_PALETTE_VkVs, WhiteMask_USE_PALETTE_VkVsSize, WhiteMask_USE_PALETTE_VkFs, WhiteMask_USE_PALETTE_VkFsSize },
#else
			nullptr, 0, nullptr, 0 },
#endif
	};

	inline constexpr ShaderCompiler::Program WhiteMask = { "WhiteMask", 0, 2, WhiteMask_Variants };

#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
	inline constexpr char BatchedWhiteMask_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 BatchedWhiteMask_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 BatchedWhiteMask_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

// Resolves the diffuse color, looking the palette index up in the palette texture when the sprite is indexed
vec4 maskSample(vec2 uv) {
	vec4 src = texture(uTexture, uv);
#ifdef USE_PALETTE
	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 c = texture(uTexturePalette, vec2(palX, palY));
	return vec4(c.rgb, c.a * src.a);
#else
	return src;
#endif
}

out vec4 COLOR;

void main() {
	COLOR = vColor;
	vec4 tex = maskSample(vTexCoords);
	float color = min((0.299 * tex.r + 0.587 * tex.g + 0.114 * tex.b) * 6.0, 1.0);
	COLOR = vec4(color, color, color, tex.a) * COLOR;
}

)__SHDR__";
#endif

#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
	inline constexpr char BatchedWhiteMask_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

// Resolves the diffuse color, looking the palette index up in the palette texture when the sprite is indexed
vec4 maskSample(vec2 uv) {
	vec4 src = texture2D(uTexture, uv);
#ifdef USE_PALETTE
	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 c = texture2D(uTexturePalette, vec2(palX, palY));
	return vec4(c.rgb, c.a * src.a);
#else
	return src;
#endif
}


void main() {
	vec4 COLOR;
	COLOR = vColor;
	vec4 tex = maskSample(vTexCoords);
	float color = min((0.299 * tex.r + 0.587 * tex.g + 0.114 * tex.b) * 6.0, 1.0);
	COLOR = vec4(color, color, color, tex.a) * COLOR;
	gl_FragColor = COLOR;
}

)__SHDR__";
#endif

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

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

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

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

#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
	inline constexpr char BatchedWhiteMask_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 BatchedWhiteMask_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 BatchedWhiteMask_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

// Resolves the diffuse color, looking the palette index up in the palette texture when the sprite is indexed
vec4 maskSample(vec2 uv) {
	vec4 src = texture(uTexture, uv);
#ifdef USE_PALETTE
	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 c = texture(uTexturePalette, vec2(palX, palY));
	return vec4(c.rgb, c.a * src.a);
#else
	return src;
#endif
}

out vec4 COLOR;

void main() {
	COLOR = vColor;
	vec4 tex = maskSample(vTexCoords);
	float color = min((0.299 * tex.r + 0.587 * tex.g + 0.114 * tex.b) * 6.0, 1.0);
	COLOR = vec4(color, color, color, tex.a) * COLOR;
}

)__SHDR__";
#endif

#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
	inline constexpr char BatchedWhiteMask_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

// Resolves the diffuse color, looking the palette index up in the palette texture when the sprite is indexed
vec4 maskSample(vec2 uv) {
	vec4 src = texture2D(uTexture, uv);
#ifdef USE_PALETTE
	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 c = texture2D(uTexturePalette, vec2(palX, palY));
	return vec4(c.rgb, c.a * src.a);
#else
	return src;
#endif
}


void main() {
	vec4 COLOR;
	COLOR = vColor;
	vec4 tex = maskSample(vTexCoords);
	float color = min((0.299 * tex.r + 0.587 * tex.g + 0.114 * tex.b) * 6.0, 1.0);
	COLOR = vec4(color, color, color, tex.a) * COLOR;
	gl_FragColor = COLOR;
}

)__SHDR__";
#endif

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

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

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

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

	inline constexpr ShaderCompiler::ProgramVariant BatchedWhiteMask_Variants[] = {
		{ "", "",
#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
			BatchedWhiteMask_Vs, BatchedWhiteMask_Fs,
#else
			nullptr, nullptr,
#endif
			2, BatchedWhiteMask_Uniforms, 1, BatchedWhiteMask_Blocks, 1, BatchedWhiteMask_Textures, 0, nullptr,
#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
			BatchedWhiteMask_Vs100, BatchedWhiteMask_Fs100,
#else
			nullptr, nullptr,
#endif
#if defined(WITH_RHI_D3D11)
			BatchedWhiteMask_VsHlsl, BatchedWhiteMask_FsHlsl,
			BatchedWhiteMask_VsDxbc, BatchedWhiteMask_VsDxbcSize, BatchedWhiteMask_FsDxbc, BatchedWhiteMask_FsDxbcSize,
#else
			nullptr, nullptr,
			nullptr, 0, nullptr, 0,
#endif
#if defined(WITH_RHI_VULKAN)
			BatchedWhiteMask_VkVs, BatchedWhiteMask_VkVsSize, BatchedWhiteMask_VkFs, BatchedWhiteMask_VkFsSize },
#else
			nullptr, 0, nullptr, 0 },
#endif
		{ "USE_PALETTE", "USE_PALETTE",
#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
			BatchedWhiteMask_USE_PALETTE_Vs, BatchedWhiteMask_USE_PALETTE_Fs,
#else
			nullptr, nullptr,
#endif
			2, BatchedWhiteMask_USE_PALETTE_Uniforms, 1, BatchedWhiteMask_USE_PALETTE_Blocks, 2, BatchedWhiteMask_USE_PALETTE_Textures, 0, nullptr,
#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
			BatchedWhiteMask_USE_PALETTE_Vs100, BatchedWhiteMask_USE_PALETTE_Fs100,
#else
			nullptr, nullptr,
#endif
#if defined(WITH_RHI_D3D11)
			BatchedWhiteMask_USE_PALETTE_VsHlsl, BatchedWhiteMask_USE_PALETTE_FsHlsl,
			BatchedWhiteMask_USE_PALETTE_VsDxbc, BatchedWhiteMask_USE_PALETTE_VsDxbcSize, BatchedWhiteMask_USE_PALETTE_FsDxbc, BatchedWhiteMask_USE_PALETTE_FsDxbcSize,
#else
			nullptr, nullptr,
			nullptr, 0, nullptr, 0,
#endif
#if defined(WITH_RHI_VULKAN)
			BatchedWhiteMask_USE_PALETTE_VkVs, BatchedWhiteMask_USE_PALETTE_VkVsSize, BatchedWhiteMask_USE_PALETTE_VkFs, BatchedWhiteMask_USE_PALETTE_VkFsSize },
#else
			nullptr, 0, nullptr, 0 },
#endif
	};

	inline constexpr ShaderCompiler::Program BatchedWhiteMask = { "BatchedWhiteMask", 0, 2, BatchedWhiteMask_Variants };
}
#endif
