diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-08-18 15:24:29 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-08-18 16:07:17 +0300 |
commit | 25789f24f2d6c6076e8b3d04a12a1a29c2732ba4 (patch) | |
tree | bea7ba9ccd9160fccab3f3dfde871e100fd82277 /source/blender/draw/engines | |
parent | 2018df9939d302dc6ebec0f4eb61e6d50bee07c2 (diff) |
Eevee: Add some utils functions
Diffstat (limited to 'source/blender/draw/engines')
-rw-r--r-- | source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl b/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl index ee2bc08a38a..fc339e93927 100644 --- a/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl @@ -133,17 +133,31 @@ vec2 mip_ratio_interp(float mip) { /* ------- Fast Math ------- */ /* [Drobot2014a] Low Level Optimizations for GCN */ -float fast_sqrt(float x) +float fast_sqrt(float v) { - return intBitsToFloat(0x1fbd1df5 + (floatBitsToInt(x) >> 1)); + return intBitsToFloat(0x1fbd1df5 + (floatBitsToInt(v) >> 1)); +} + +vec2 fast_sqrt(vec2 v) +{ + return intBitsToFloat(0x1fbd1df5 + (floatBitsToInt(v) >> 1)); } /* [Eberly2014] GPGPU Programming for Games and Science */ -float fast_acos(float x) +float fast_acos(float v) { - float res = -0.156583 * abs(x) + M_PI_2; - res *= fast_sqrt(1.0 - abs(x)); - return (x >= 0) ? res : M_PI - res; + float res = -0.156583 * abs(v) + M_PI_2; + res *= fast_sqrt(1.0 - abs(v)); + return (v >= 0) ? res : M_PI - res; +} + +vec2 fast_acos(vec2 v) +{ + vec2 res = -0.156583 * abs(v) + M_PI_2; + res *= fast_sqrt(1.0 - abs(v)); + v.x = (v.x >= 0) ? res.x : M_PI - res.x; + v.y = (v.y >= 0) ? res.y : M_PI - res.y; + return v; } float point_plane_projection_dist(vec3 lineorigin, vec3 planeorigin, vec3 planenormal) @@ -280,6 +294,12 @@ float get_view_z_from_depth(float depth) } } +vec2 get_uvs_from_view(vec3 view) +{ + vec3 ndc = project_point(ProjectionMatrix, view); + return ndc.xy * 0.5 + 0.5; +} + vec3 get_view_space_from_depth(vec2 uvcoords, float depth) { if (ProjectionMatrix[3][3] == 0.0) { |