#define PI 3.141592653589793 vec3 world_space_location(vec2 uv, float depth) { //converts from normalized range to -1.0..1.0 vec4 clip_space = vec4(1.0); clip_space.xy = uv*2.0-1.0; clip_space.z = depth; mat4 p = projection_data.p; p[0][3] = 0.0; p[1][3] = 0.0; p[2][3] = -1.0; vec4 homogenous = inverse(p)*clip_space; homogenous /= homogenous.w; vec4 world_space = inverse(projection_data.mv) * homogenous; return world_space.xyz; } vec3 get_view_pos() { vec3 pos; pos.x = projection_data.p[0][3]; pos.y = projection_data.p[1][3]; pos.z = projection_data.p[2][3]; return pos; } void swap(inout float a, inout float b) { float t = a; a = b; b = t; }