<commit_before>/*
===========================================================================
Copyright (C) 2009-2011 <NAME> <<EMAIL>>

This file is part of XreaL source code.

XreaL source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.

XreaL source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with XreaL source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
===========================================================================
*/
// reliefMapping_fp.glsl - Relief mapping helper functions

#if defined(r_normalMapping) || defined(USE_PARALLAX_MAPPING)
uniform sampler2D	u_NormalMap;
uniform int u_HeightMapInNormalMap;
#endif // r_normalMapping || USE_PARALLAX_MAPPING

#if defined(USE_PARALLAX_MAPPING)
uniform float       u_ParallaxDepthScale;
uniform float       u_ParallaxOffsetBias;
#endif // USE_PARALLAX_MAPPING

#if defined(r_normalMapping)
uniform vec3 u_NormalFormat;

vec3 normalFlip(vec3 normal)
{
	// undefined (zero) means default means 1.0 means do nothing

	if (u_NormalFormat.x < 0.0)
	{
		normal.x *= -1.0;
	}

	if (u_NormalFormat.y < 0.0)
	{
		normal.y *= -1.0;
	}

	if (u_NormalFormat.z < 0.0)
	{
		normal.z *= -1.0;
	}

	return normal;
}
#endif // r_normalMapping

// compute normal in tangent space
vec3 NormalInTangentSpace(vec2 texNormal)
{
	vec3 normal;

#if defined(r_normalMapping)
	if (u_HeightMapInNormalMap == 0)
	{
		// the Capcom trick abusing alpha channel of DXT1/5 formats to encode normal map
		// https://github.com/DaemonEngine/Daemon/issues/183#issuecomment-473691252
		//
		// the algorithm also works with normal maps in rgb format without alpha channel
		// but we still must be sure there is no height map in alpha channel hence the test
		//
		// crunch -dxn seems to produce such files, since alpha channel is abused such format
		// is unsuitable to embed height map, then height map must be distributed as loose file
		normal = texture2D(u_NormalMap, texNormal).rga;
		normal.x *= normal.z;
		normal.xy = 2.0 * normal.xy - 1.0;
		normal.z = sqrt(1.0 - dot(normal.xy, normal.xy));
	}
	else
	{
		// alpha channel contains the height map so do not try to restore the normal map from it
		normal = texture2D(u_NormalMap, texNormal).rgb;
		normal = 2.0 * normal - 1.0;
	}

	normal = normalFlip(normal);

#if defined(r_NormalScale)
	normal.z *= r_NormalScale;
#endif
#endif // r_normalMapping

	return normal;
}

// compute normal in worldspace from normalmap
vec3 NormalInWorldSpace(vec2 texNormal, mat3 tangentToWorldMatrix)
{<commit_msg>reliefMapping: revert my mistake introduced in 071c789: the flat texture is not read<commit_after>/*
===========================================================================
Copyright (C) 2009-2011 <NAME> <<EMAIL>>

This file is part of XreaL source code.

XreaL source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.

XreaL source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with XreaL source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
===========================================================================
*/
// reliefMapping_fp.glsl - Relief mapping helper functions

#if defined(r_normalMapping) || defined(USE_PARALLAX_MAPPING)
uniform sampler2D	u_NormalMap;
uniform int u_HeightMapInNormalMap;
#endif // r_normalMapping || USE_PARALLAX_MAPPING

#if defined(USE_PARALLAX_MAPPING)
uniform float       u_ParallaxDepthScale;
uniform float       u_ParallaxOffsetBias;
#endif // USE_PARALLAX_MAPPING

#if defined(r_normalMapping)
uniform vec3 u_NormalFormat;

vec3 normalFlip(vec3 normal)
{
	// undefined (zero) means default means 1.0 means do nothing

	if (u_NormalFormat.x < 0.0)
	{
		normal.x *= -1.0;
	}

	if (u_NormalFormat.y < 0.0)
	{
		normal.y *= -1.0;
	}

	if (u_NormalFormat.z < 0.0)
	{
		normal.z *= -1.0;
	}

	return normal;
}
#endif // r_normalMapping

// compute normal in tangent space
vec3 NormalInTangentSpace(vec2 texNormal)
{
	vec3 normal;

#if defined(r_normalMapping)
	if (u_HeightMapInNormalMap == 0)
	{
		// the Capcom trick abusing alpha channel of DXT1/5 formats to encode normal map
		// https://github.com/DaemonEngine/Daemon/issues/183#issuecomment-473691252
		//
		// the algorithm also works with normal maps in rgb format without alpha channel
		// but we still must be sure there is no height map in alpha channel hence the test
		//
		// crunch -dxn seems to produce such files, since alpha channel is abused such format
		// is unsuitable to embed height map, then height map must be distributed as loose file
		normal = texture2D(u_NormalMap, texNormal).rga;
		normal.x *= normal.z;
		normal.xy = 2.0 * normal.xy - 1.0;
		normal.z = sqrt(1.0 - dot(normal.xy, normal.xy));
	}
	else
	{
		// alpha channel contains the height map so do not try to restore the normal map from it
		normal = texture2D(u_NormalMap, texNormal).rgb;
		normal = 2.0 * normal - 1.0;
	}

	normal = normalFlip(normal);

#if defined(r_NormalScale)
	normal.z *= r_NormalScale;
#endif
#else // !r_normalMapping
	normal = vec3(0.5, 0.5, 1.0);
#endif // !r_normalMapping

	return normal;
}

// compute normal in worldspace from normalmap
vec3 NormalInWorldSpace(vec2 texNormal, mat3 tangentToWorldMatrix)
{
{'fraction_non_alphanumeric': 0.12795821772482455, 'fraction_numerical': 0.025297861922637506, 'mean_word_length': 4.180050718512257, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3627858', 'n_tokens_mistral': 2020, 'n_tokens_neox': 1855, 'n_words': 700}