// Shared shadow-map projection. The radial warp spends most texels close to
// the camera while preserving the configured world-space shadow distance.
#ifndef NOISE_SHADOW_SPACE_GLSL
#define NOISE_SHADOW_SPACE_GLSL

const float shadowDistance = 128.0; // [64.0 96.0 128.0 160.0 192.0 256.0]
const float NOISE_SHADOW_DEPTH_SCALE = 0.20;

float noiseShadowWarpBias() {
	return clamp(1.0 - 25.6 / shadowDistance, 0.45, 0.92);
}

float noiseShadowWarpFactor(vec2 position) {
	float radialDistance = length(position * 1.169);
	float warpBias = noiseShadowWarpBias();
	return radialDistance * warpBias + (1.0 - warpBias);
}

vec2 noiseWarpShadowPosition(vec2 position) {
	return position / max(noiseShadowWarpFactor(position), 1e-5);
}

#endif
