// Generated by ShaderCompiler from DefaultSprite.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 nCine::ShadersGen
{
#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
	inline constexpr char DefaultSprite_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;

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;
}
)__SHDR__";
#endif

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

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;
}
)__SHDR__";
#endif

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

#ifdef GL_ES
precision mediump float;
#endif

in vec2 vTexCoords;
in vec4 vColor;

uniform sampler2D uTexture;

out vec4 COLOR;

void main() {
	COLOR = vColor;
	COLOR = texture(uTexture, vTexCoords) * COLOR;
}

)__SHDR__";
#endif

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

precision mediump float;

varying vec2 vTexCoords;
varying vec4 vColor;

uniform sampler2D uTexture;


void main() {
	vec4 COLOR;
	COLOR = vColor;
	COLOR = texture2D(uTexture, vTexCoords) * COLOR;
	gl_FragColor = COLOR;
}

)__SHDR__";
#endif

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

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

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

	inline constexpr ShaderCompiler::ProgramVariant DefaultSprite_Variants[] = {
		{ "", "",
#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
			DefaultSprite_Vs, DefaultSprite_Fs,
#else
			nullptr, nullptr,
#endif
			2, DefaultSprite_Uniforms, 1, DefaultSprite_Blocks, 1, DefaultSprite_Textures, 0, nullptr,
#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
			DefaultSprite_Vs100, DefaultSprite_Fs100,
#else
			nullptr, nullptr,
#endif
#if defined(WITH_RHI_D3D11)
			DefaultSprite_VsHlsl, DefaultSprite_FsHlsl,
			DefaultSprite_VsDxbc, DefaultSprite_VsDxbcSize, DefaultSprite_FsDxbc, DefaultSprite_FsDxbcSize,
#else
			nullptr, nullptr,
			nullptr, 0, nullptr, 0,
#endif
#if defined(WITH_RHI_VULKAN)
			DefaultSprite_VkVs, DefaultSprite_VkVsSize, DefaultSprite_VkFs, DefaultSprite_VkFsSize },
#else
			nullptr, 0, nullptr, 0 },
#endif
	};

	inline constexpr ShaderCompiler::Program DefaultSprite = { "DefaultSprite", 0, 1, DefaultSprite_Variants };

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

#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;
}
)__SHDR__";
#endif

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

#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;
}
)__SHDR__";
#endif

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

#ifdef GL_ES
precision mediump float;
#endif

in vec2 vTexCoords;
in vec4 vColor;

uniform sampler2D uTexture;

out vec4 COLOR;

void main() {
	COLOR = vColor;
	COLOR = texture(uTexture, vTexCoords) * COLOR;
}

)__SHDR__";
#endif

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

precision mediump float;

varying vec2 vTexCoords;
varying vec4 vColor;

uniform sampler2D uTexture;


void main() {
	vec4 COLOR;
	COLOR = vColor;
	COLOR = texture2D(uTexture, vTexCoords) * COLOR;
	gl_FragColor = COLOR;
}

)__SHDR__";
#endif

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

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

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

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

	inline constexpr ShaderCompiler::ProgramVariant DefaultBatchedSprites_Variants[] = {
		{ "", "",
#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
			DefaultBatchedSprites_Vs, DefaultBatchedSprites_Fs,
#else
			nullptr, nullptr,
#endif
			2, DefaultBatchedSprites_Uniforms, 1, DefaultBatchedSprites_Blocks, 1, DefaultBatchedSprites_Textures, 0, nullptr,
#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
			DefaultBatchedSprites_Vs100, DefaultBatchedSprites_Fs100,
#else
			nullptr, nullptr,
#endif
#if defined(WITH_RHI_D3D11)
			DefaultBatchedSprites_VsHlsl, DefaultBatchedSprites_FsHlsl,
			DefaultBatchedSprites_VsDxbc, DefaultBatchedSprites_VsDxbcSize, DefaultBatchedSprites_FsDxbc, DefaultBatchedSprites_FsDxbcSize,
#else
			nullptr, nullptr,
			nullptr, 0, nullptr, 0,
#endif
#if defined(WITH_RHI_VULKAN)
			DefaultBatchedSprites_VkVs, DefaultBatchedSprites_VkVsSize, DefaultBatchedSprites_VkFs, DefaultBatchedSprites_VkFsSize },
#else
			nullptr, 0, nullptr, 0 },
#endif
	};

	inline constexpr ShaderCompiler::Program DefaultBatchedSprites = { "DefaultBatchedSprites", 0, 1, DefaultBatchedSprites_Variants };
}
#endif
