// Generated by ShaderCompiler from PaletteRemap.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 PaletteRemap_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 PaletteRemap_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 PaletteRemap_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;
uniform sampler2D uTexturePalette;

out vec4 COLOR;

void main() {
	COLOR = vColor;
	vec4 src = texture(uTexture, vTexCoords);
	// Flat palette position = per-instance offset + the per-pixel index (red channel), mapped into the 256x256 texture
	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 color = texture(uTexturePalette, vec2(palX, palY));
	COLOR = vec4(color.rgb, color.a * src.a) * COLOR;
}

)__SHDR__";
#endif

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

precision mediump float;

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

uniform sampler2D uTexture;
uniform sampler2D uTexturePalette;


void main() {
	vec4 COLOR;
	COLOR = vColor;
	vec4 src = texture2D(uTexture, vTexCoords);
	// Flat palette position = per-instance offset + the per-pixel index (red channel), mapped into the 256x256 texture
	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 color = texture2D(uTexturePalette, vec2(palX, palY));
	COLOR = vec4(color.rgb, color.a * src.a) * COLOR;
	gl_FragColor = COLOR;
}

)__SHDR__";
#endif

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

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

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

	inline constexpr ShaderCompiler::ProgramVariant PaletteRemap_Variants[] = {
		{ "", "",
#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
			PaletteRemap_Vs, PaletteRemap_Fs,
#else
			nullptr, nullptr,
#endif
			2, PaletteRemap_Uniforms, 1, PaletteRemap_Blocks, 2, PaletteRemap_Textures, 0, nullptr,
#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
			PaletteRemap_Vs100, PaletteRemap_Fs100,
#else
			nullptr, nullptr,
#endif
#if defined(WITH_RHI_D3D11)
			PaletteRemap_VsHlsl, PaletteRemap_FsHlsl,
			PaletteRemap_VsDxbc, PaletteRemap_VsDxbcSize, PaletteRemap_FsDxbc, PaletteRemap_FsDxbcSize,
#else
			nullptr, nullptr,
			nullptr, 0, nullptr, 0,
#endif
#if defined(WITH_RHI_VULKAN)
			PaletteRemap_VkVs, PaletteRemap_VkVsSize, PaletteRemap_VkFs, PaletteRemap_VkFsSize },
#else
			nullptr, 0, nullptr, 0 },
#endif
	};

	inline constexpr ShaderCompiler::Program PaletteRemap = { "PaletteRemap", 0, 1, PaletteRemap_Variants };

#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
	inline constexpr char BatchedPaletteRemap_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 BatchedPaletteRemap_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 BatchedPaletteRemap_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;
uniform sampler2D uTexturePalette;

out vec4 COLOR;

void main() {
	COLOR = vColor;
	vec4 src = texture(uTexture, vTexCoords);
	// Flat palette position = per-instance offset + the per-pixel index (red channel), mapped into the 256x256 texture
	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 color = texture(uTexturePalette, vec2(palX, palY));
	COLOR = vec4(color.rgb, color.a * src.a) * COLOR;
}

)__SHDR__";
#endif

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

precision mediump float;

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

uniform sampler2D uTexture;
uniform sampler2D uTexturePalette;


void main() {
	vec4 COLOR;
	COLOR = vColor;
	vec4 src = texture2D(uTexture, vTexCoords);
	// Flat palette position = per-instance offset + the per-pixel index (red channel), mapped into the 256x256 texture
	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 color = texture2D(uTexturePalette, vec2(palX, palY));
	COLOR = vec4(color.rgb, color.a * src.a) * COLOR;
	gl_FragColor = COLOR;
}

)__SHDR__";
#endif

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

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

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

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

	inline constexpr ShaderCompiler::ProgramVariant BatchedPaletteRemap_Variants[] = {
		{ "", "",
#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
			BatchedPaletteRemap_Vs, BatchedPaletteRemap_Fs,
#else
			nullptr, nullptr,
#endif
			2, BatchedPaletteRemap_Uniforms, 1, BatchedPaletteRemap_Blocks, 2, BatchedPaletteRemap_Textures, 0, nullptr,
#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
			BatchedPaletteRemap_Vs100, BatchedPaletteRemap_Fs100,
#else
			nullptr, nullptr,
#endif
#if defined(WITH_RHI_D3D11)
			BatchedPaletteRemap_VsHlsl, BatchedPaletteRemap_FsHlsl,
			BatchedPaletteRemap_VsDxbc, BatchedPaletteRemap_VsDxbcSize, BatchedPaletteRemap_FsDxbc, BatchedPaletteRemap_FsDxbcSize,
#else
			nullptr, nullptr,
			nullptr, 0, nullptr, 0,
#endif
#if defined(WITH_RHI_VULKAN)
			BatchedPaletteRemap_VkVs, BatchedPaletteRemap_VkVsSize, BatchedPaletteRemap_VkFs, BatchedPaletteRemap_VkFsSize },
#else
			nullptr, 0, nullptr, 0 },
#endif
	};

	inline constexpr ShaderCompiler::Program BatchedPaletteRemap = { "BatchedPaletteRemap", 0, 1, BatchedPaletteRemap_Variants };
}
#endif
