[nzsl_version("1.0")]
module;

struct VertOut
{
	[location(0)] uv: vec2[f32]
}

struct FragOut
{
	[location(0)] color: vec4[f32]
}

external
{
	[set(0), binding(0)] u_texture: sampler2D[f32]
}

option approximates_rgb: bool = false;

fn LinearTosRGB(color: vec3[f32]) -> vec3[f32]
{
	const if(!approximates_rgb)
	{
		return select(
			color > (0.0031308).rrr,
			1.055 * pow(color, (1.0 / 2.4).rrr) - (0.055).rrr,
			12.92 * color
		);
	}
	else
		return pow(color, (1.0 / 2.2).rrr);
}

option gamma_correction: bool = false;

[entry(frag)]
fn main(input: VertOut) -> FragOut
{
	let output: FragOut;
	const if(gamma_correction)
		output.color = vec4[f32](LinearTosRGB(u_texture.Sample(input.uv).xyz), 1.0);
	else
		output.color = u_texture.Sample(input.uv);
	return output;
}
