// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
/// <summary>
/// Packs and stores the normals into the GBuffer. Expected texture output format: float3.
/// </summary>
shader NormalPack
{
	// Compact Normal Storage for Small G-Buffers
	// [Aras Pranckevičius 2010, http://aras-p.info/texts/CompactNormalStorage.html]
	float3 EncodeNormal(float3 n)
	{
		// Pack to [0;1] range
		return n * 0.5 + 0.5;
	}
	
	// Compact Normal Storage for Small G-Buffers
	// [Aras Pranckevičius 2010, http://aras-p.info/texts/CompactNormalStorage.html]
	float3 DecodeNormal(float3 enc)
	{
		// Unpack from [0;1] range
		return normalize(enc * 2 - 1);
	}
};
