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

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

out vec4 vTexCoords;
out vec4 vColor;

uniform mat4 uProjectionMatrix;
uniform mat4 uViewMatrix;

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




uniform sampler2D uTexture;

void main()
{
	// All lights of a viewport arrive as one vertex stream instead of one instanced quad each: the corners are
	// already in world space, the light's own parameters ride along per vertex (see LightingRenderer::OnDraw).
	// The fragment stage is shared with the single-light program, so the varyings it reads are filled the same
	// way - the light centre it would need for normal mapping is not in the stream and would have to be added.
	gl_Position = uProjectionMatrix * uViewMatrix * modelMatrix * vec4(aPosition.x, aPosition.y, 0.0, 1.0);
	vTexCoords = vec4(0.0, 0.0, aTexCoords.x, 0.0);
	vColor = aColor;
}
)__SHDR__";
#endif

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

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

varying vec4 vTexCoords;
varying vec4 vColor;

uniform mat4 uProjectionMatrix;
uniform mat4 uViewMatrix;

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




uniform sampler2D uTexture;

void main()
{
	// All lights of a viewport arrive as one vertex stream instead of one instanced quad each: the corners are
	// already in world space, the light's own parameters ride along per vertex (see LightingRenderer::OnDraw).
	// The fragment stage is shared with the single-light program, so the varyings it reads are filled the same
	// way - the light centre it would need for normal mapping is not in the stream and would have to be added.
	gl_Position = uProjectionMatrix * uViewMatrix * modelMatrix * vec4(aPosition.x, aPosition.y, 0.0, 1.0);
	vTexCoords = vec4(0.0, 0.0, aTexCoords.x, 0.0);
	vColor = aColor;
}
)__SHDR__";
#endif

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

#ifdef GL_ES
precision mediump float;
#endif

in vec4 vTexCoords;
in vec4 vColor;

uniform sampler2D uTexture;

float lightBlend(float t) {
	return t * t * t;
}

out vec4 COLOR;

void main() {
	vec2 center = vTexCoords.xy;
	float radiusNear = vTexCoords.z;
	float intensity = vColor.r;
	float brightness = vColor.g;

	float dist = length(vColor.zw);
	if (dist > 1.0) {
		COLOR = vec4(0.0, 0.0, 0.0, 1.0);
	} else {
		// TODO: Normal maps
		/*vec4 clrNormal = texture(uTexture, vec2(gl_FragCoord) / ViewSize);
		vec3 normal = normalize(clrNormal.xyz - vec3(0.5, 0.5, 0.5));
		normal.z = -normal.z;

		vec3 lightDir = vec3((center.x - gl_FragCoord.x), (center.y - gl_FragCoord.y), 0);

		// Diffuse lighting
		float diffuseFactor = 1.0 - max(dot(normal, normalize(lightDir)), 0.0);
		diffuseFactor = diffuseFactor * 0.8 + 0.2;*/
		float diffuseFactor = 1.0;

		float strength = diffuseFactor * lightBlend(clamp(1.0 - ((dist - radiusNear) / (1.0 - radiusNear)), 0.0, 1.0));
		COLOR = vec4(strength * intensity, strength * brightness, 0.0, 1.0);
	}
}

)__SHDR__";
#endif

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

precision mediump float;

varying vec4 vTexCoords;
varying vec4 vColor;

uniform sampler2D uTexture;

float lightBlend(float t) {
	return t * t * t;
}


void main() {
	vec4 COLOR;
	vec2 center = vTexCoords.xy;
	float radiusNear = vTexCoords.z;
	float intensity = vColor.r;
	float brightness = vColor.g;

	float dist = length(vColor.zw);
	if (dist > 1.0) {
		COLOR = vec4(0.0, 0.0, 0.0, 1.0);
	} else {
		// TODO: Normal maps
		/*vec4 clrNormal = texture(uTexture, vec2(gl_FragCoord) / ViewSize);
		vec3 normal = normalize(clrNormal.xyz - vec3(0.5, 0.5, 0.5));
		normal.z = -normal.z;

		vec3 lightDir = vec3((center.x - gl_FragCoord.x), (center.y - gl_FragCoord.y), 0);

		// Diffuse lighting
		float diffuseFactor = 1.0 - max(dot(normal, normalize(lightDir)), 0.0);
		diffuseFactor = diffuseFactor * 0.8 + 0.2;*/
		float diffuseFactor = 1.0;

		float strength = diffuseFactor * lightBlend(clamp(1.0 - ((dist - radiusNear) / (1.0 - radiusNear)), 0.0, 1.0));
		COLOR = vec4(strength * intensity, strength * brightness, 0.0, 1.0);
	}
	gl_FragColor = COLOR;
}

)__SHDR__";
#endif

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

	inline constexpr ShaderCompiler::BlockMember LightingMesh_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 },
	};

	inline constexpr ShaderCompiler::UniformBlock LightingMesh_Blocks[] = {
		{ "InstanceBlock", 112, 0, 4, LightingMesh_Block0_Members },
	};

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

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

	inline constexpr ShaderCompiler::ProgramVariant LightingMesh_Variants[] = {
		{ "", "",
#if defined(WITH_RHI_GL) && !defined(RHI_GL_PROFILE_ES2)
			LightingMesh_Vs, LightingMesh_Fs,
#else
			nullptr, nullptr,
#endif
			2, LightingMesh_Uniforms, 1, LightingMesh_Blocks, 1, LightingMesh_Textures, 3, LightingMesh_Attributes,
#if defined(WITH_RHI_GL) && defined(RHI_GL_PROFILE_ES2)
			LightingMesh_Vs100, LightingMesh_Fs100,
#else
			nullptr, nullptr,
#endif
#if defined(WITH_RHI_D3D11)
			LightingMesh_VsHlsl, LightingMesh_FsHlsl,
			LightingMesh_VsDxbc, LightingMesh_VsDxbcSize, LightingMesh_FsDxbc, LightingMesh_FsDxbcSize,
#else
			nullptr, nullptr,
			nullptr, 0, nullptr, 0,
#endif
#if defined(WITH_RHI_VULKAN)
			LightingMesh_VkVs, LightingMesh_VkVsSize, LightingMesh_VkFs, LightingMesh_VkFsSize },
#else
			nullptr, 0, nullptr, 0 },
#endif
	};

	inline constexpr ShaderCompiler::Program LightingMesh = { "LightingMesh", 0, 1, LightingMesh_Variants };
}
#endif
