Gregory Igehy

Dancing at hemisphere coordinate

Notes of depth prepass (Z Prepass) in Unity

Notes of linear/gamma color space and HDR in Unity 5.4.0.3f3

// HLSLSupport.cginc

// UNITY_NO_RGBM		- no RGBM support, so doubleLDR
// UNITY_NO_LINEAR_COLORSPACE	- no linear color space support

#if defined(SHADER_API_PSP2)
// To get acceptable precision from the SGX interpolators when decoding RGBM type
// textures we have to disable sRGB reads and then convert to gamma space in the shader
// explicitly.
#define UNITY_FORCE_LINEAR_READ_FOR_RGBM
#endif

// Decodes HDR textures
// handles dLDR, RGBM formats
inline half3 DecodeHDR (half4 data, half4 decodeInstructions)
{
	// If Linear mode is not supported we can skip exponent part
	#if defined(UNITY_NO_LINEAR_COLORSPACE)
		return (decodeInstructions.x * data.a) * data.rgb;
	#else
		return (decodeInstructions.x * pow(data.a, decodeInstructions.y)) * data.rgb;
	#endif
}

// Decodes HDR textures
// handles dLDR, RGBM formats
// Called by DecodeLightmap when UNITY_NO_RGBM is not defined.
inline half3 DecodeLightmapRGBM (half4 data, half4 decodeInstructions)
{
	// If Linear mode is not supported we can skip exponent part
	#if defined(UNITY_NO_LINEAR_COLORSPACE)
	# if defined(UNITY_FORCE_LINEAR_READ_FOR_RGBM)
		return (decodeInstructions.x * data.a) * sqrt(data.rgb);
	# else
		return (decodeInstructions.x * data.a) * data.rgb;
	# endif
	#else
		return (decodeInstructions.x * pow(data.a, decodeInstructions.y)) * data.rgb;
	#endif
}
// UnityCG.cginc

inline bool IsGammaSpace()
{
#if defined(UNITY_NO_LINEAR_COLORSPACE)
	return true;
#else
	// unity_ColorSpaceLuminance.w == 1 when in Linear space, otherwise == 0
	return unity_ColorSpaceLuminance.w == 0;
#endif
}

inline float GammaToLinearSpaceExact (float value)
{
	if (value <= 0.04045F)
		return value / 12.92F;
	else if (value < 1.0F)
		return pow((value + 0.055F)/1.055F, 2.4F);
	else
		return pow(value, 2.2F);
}

inline half3 GammaToLinearSpace (half3 sRGB)
{
	// Approximate version from http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1
	return sRGB * (sRGB * (sRGB * 0.305306011h + 0.682171111h) + 0.012522878h);

	// Precise version, useful for debugging.
	//return half3(GammaToLinearSpaceExact(sRGB.r), GammaToLinearSpaceExact(sRGB.g), GammaToLinearSpaceExact(sRGB.b));
}

inline float LinearToGammaSpaceExact (float value)
{
	if (value <= 0.0F)
		return 0.0F;
	else if (value <= 0.0031308F)
		return 12.92F * value;
	else if (value < 1.0F)
		return 1.055F * pow(value, 0.4166667F) - 0.055F;
	else
		return pow(value, 0.45454545F);
}

inline half3 LinearToGammaSpace (half3 linRGB)
{
	linRGB = max(linRGB, half3(0.h, 0.h, 0.h));
	// An almost-perfect approximation from http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1
	return max(1.055h * pow(linRGB, 0.416666667h) - 0.055h, 0.h);
	
	// Exact version, useful for debugging.
	//return half3(LinearToGammaSpaceExact(linRGB.r), LinearToGammaSpaceExact(linRGB.g), LinearToGammaSpaceExact(linRGB.b));
}
// Standard.shader

#pragma multi_compile ___ UNITY_HDR_ON

Notes of slow Unity Functions

Notes of tile-based GPU

Notes of Unity builds scripting

Notes of Multi-threads in Unity