// Generated by ShaderCompiler from TileMapMeshPalette.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 TileMapMeshPalette_Vs[] =
R"__SHDR__(#line 1

in vec2 aPosition;
in vec2 aTexCoords;
in vec4 aColor;

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

// Every global reaches both stages, InstanceBlock included, and a named uniform block whose members
// disagree on precision between them does not link - so the fragment prologue keeps the vertex default

uniform mat4 uProjectionMatrix;
uniform mat4 uViewMatrix;

layout (std140) uniform InstanceBlock
{
	mat4 modelMatrix;
	vec4 color;
	vec4 texRect;
	vec2 spriteSize;
	float palOffset;
};




void main()
{
	gl_Position = uProjectionMatrix * uViewMatrix * modelMatrix * vec4(aPosition.x, aPosition.y, 0.0, 1.0);
	vTexCoords = aTexCoords;
	vColor = aColor * color;
	vPaletteOffset = palOffset;
}
)__SHDR__";
#endif

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

attribute vec2 aPosition;
attribute vec2 aTexCoords;
attribute vec4 aColor;

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

// Every global reaches both stages, InstanceBlock included, and a named uniform block whose members
// disagree on precision between them does not link - so the fragment prologue keeps the vertex default

uniform mat4 uProjectionMatrix;
uniform mat4 uViewMatrix;

	uniform mat4 modelMatrix;
	uniform vec4 color;
	uniform vec4 texRect;
	uniform vec2 spriteSize;
	uniform float palOffset;




void main()
{
	gl_Position = uProjectionMatrix * uViewMatrix * modelMatrix * vec4(aPosition.x, aPosition.y, 0.0, 1.0);
	vTexCoords = aTexCoords;
	vColor = aColor * color;
	vPaletteOffset = palOffset;
}
)__SHDR__";
#endif

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

#ifdef GL_ES
#	ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#	else
precision mediump float;
#	endif
#endif

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

// Every global reaches both stages, InstanceBlock included, and a named uniform block whose members
// disagree on precision between them does not link - so the fragment prologue keeps the vertex default

layout (std140) uniform InstanceBlock
{
	mat4 modelMatrix;
	vec4 color;
	vec4 texRect;
	vec2 spriteSize;
	float palOffset;
};




uniform sampler2D uTexture;
uniform sampler2D uTexturePalette;

out vec4 COLOR;

void main() {
	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) * vColor;
}

)__SHDR__";
#endif

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

#	ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#	else
precision mediump float;
#	endif

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

// Every global reaches both stages, InstanceBlock included, and a named uniform block whose members
// disagree on precision between them does not link - so the fragment prologue keeps the vertex default

	uniform mat4 modelMatrix;
	uniform vec4 color;
	uniform vec4 texRect;
	uniform vec2 spriteSize;
	uniform float palOffset;




uniform sampler2D uTexture;
uniform sampler2D uTexturePalette;


void main() {
	vec4 COLOR;
	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) * vColor;
	gl_FragColor = COLOR;
}

)__SHDR__";
#endif

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

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

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

	inline constexpr ShaderCompiler::Attribute TileMapMeshPalette_Attributes[] = {
		{ "aPosition", ShaderCompiler::UniformType::Vec2, -1 },
		{ "aTexCoords", ShaderCompiler::UniformType::Vec2, -1 },
		{ "aColor", ShaderCompiler::UniformType::Vec4, -1 },
	};

	inline constexpr ShaderCompiler::ProgramVariant TileMapMeshPalette_Variants[] = {
		{ "", "",
#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
			TileMapMeshPalette_Vs, TileMapMeshPalette_Fs,
#else
			nullptr, nullptr,
#endif
			2, TileMapMeshPalette_Uniforms, 1, TileMapMeshPalette_Blocks, 2, TileMapMeshPalette_Textures, 3, TileMapMeshPalette_Attributes,
#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
			TileMapMeshPalette_Vs100, TileMapMeshPalette_Fs100,
#else
			nullptr, nullptr,
#endif
#if defined(WITH_RHI_D3D11)
			TileMapMeshPalette_VsHlsl, TileMapMeshPalette_FsHlsl,
			TileMapMeshPalette_VsDxbc, TileMapMeshPalette_VsDxbcSize, TileMapMeshPalette_FsDxbc, TileMapMeshPalette_FsDxbcSize,
#else
			nullptr, nullptr,
			nullptr, 0, nullptr, 0,
#endif
#if defined(WITH_RHI_VULKAN)
			TileMapMeshPalette_VkVs, TileMapMeshPalette_VkVsSize, TileMapMeshPalette_VkFs, TileMapMeshPalette_VkFsSize },
#else
			nullptr, 0, nullptr, 0 },
#endif
	};

	inline constexpr ShaderCompiler::Program TileMapMeshPalette = { "TileMapMeshPalette", 0, 1, TileMapMeshPalette_Variants };
}
#endif
