diff options
author | Eric Anholt <[email protected]> | 2010-07-30 10:20:34 -0700 |
---|---|---|
committer | Eric Anholt <[email protected]> | 2010-07-30 15:19:00 -0700 |
commit | 3fa1b85196b7d57c6c139e62000ac519b1b2320c (patch) | |
tree | 45f9c77753353f9bf47d22429934be0ea3244018 /src/glsl | |
parent | ec9675ec533cc0c0c7b1c738280e9b9adf2591fb (diff) |
glsl2: Fix the implementation of atan(y, x).
So many problems here. One is that we can't do the quadrant handling
for all the channels at the same time, so we call the float(y, x)
version multiple times. I'd also left out the x == 0 handling. Also,
the quadrant handling was broken for y == 0, so there was a funny
discontinuity on the +x side if you plugged in obvious values to test.
I generated the atan(float y, float x) code from a short segment of
GLSL and pasted it in by hand. It would be nice to automate that
somehow.
Fixes:
glsl-fs-atan-1
glsl-fs-atan-2
Diffstat (limited to 'src/glsl')
-rw-r--r-- | src/glsl/builtin_function.cpp | 166 | ||||
-rw-r--r-- | src/glsl/builtins/110/atan | 166 |
2 files changed, 166 insertions, 166 deletions
diff --git a/src/glsl/builtin_function.cpp b/src/glsl/builtin_function.cpp index 3343cf5638b..eade72ad3a5 100644 --- a/src/glsl/builtin_function.cpp +++ b/src/glsl/builtin_function.cpp @@ -299,56 +299,66 @@ static const char *builtins_110_atan = { " (var_ref y_over_x))\n" " (constant float (1.0))))))))))\n" "\n" - " (signature float\n" - " (parameters\n" - " (declare (in) float y)\n" - " (declare (in) float x))\n" - " ((declare () float r)\n" - " (if (expression bool >\n" - " (expression float abs (var_ref x))\n" - " (constant float (.0001)))\n" - " ((assign (constant bool (1))\n" - " (var_ref r) (call atan ((expression float /\n" - " (var_ref y)\n" - " (var_ref x)))))\n" - " (if (expression bool <\n" - " (var_ref x)\n" - " (constant float (0.0)))\n" - " ((assign (constant bool (1))\n" - " (var_ref r)\n" - " (expression float +\n" - " (var_ref r)\n" - " (expression float *\n" - " (expression float sign (var_ref y))\n" - " (constant float (3.1415926))))))\n" - " ()))\n" - " ())\n" - " (return (var_ref r))))\n" + " (signature float\n" + " (parameters\n" + " (declare (in ) float y)\n" + " (declare (in ) float x)\n" + " )\n" + " (\n" + " (declare () float r)\n" + " (declare ( ) float abs_retval)\n" + " (assign (constant bool (1)) (var_ref abs_retval) (call abs ((var_ref x) ))\n" + ") \n" + " (if (expression bool > (var_ref abs_retval) (constant float (0.000100)) ) (\n" + " (declare ( ) float atan_retval)\n" + " (assign (constant bool (1)) (var_ref atan_retval) (call atan ((expression float / (var_ref y) (var_ref x) ) ))\n" + ") \n" + " (assign (constant bool (1)) (var_ref r) (var_ref atan_retval) ) \n" + " (if (expression bool < (var_ref x) (constant float (0.000000)) ) (\n" + " (if (expression bool >= (var_ref y) (constant float (0.000000)) ) (\n" + " (declare ( ) float assignment_tmp)\n" + " (assign (constant bool (1)) (var_ref assignment_tmp) (expression float + (var_ref r) (constant float (3.141593)) ) ) \n" + " (assign (constant bool (1)) (var_ref r) (var_ref assignment_tmp) ) \n" + " )\n" + " (\n" + " (declare ( ) float assignment_tmp)\n" + " (assign (constant bool (1)) (var_ref assignment_tmp) (expression float - (var_ref r) (constant float (3.141593)) ) ) \n" + " (assign (constant bool (1)) (var_ref r) (var_ref assignment_tmp) ) \n" + " ))\n" + "\n" + " )\n" + " (\n" + " ))\n" + "\n" + " )\n" + " (\n" + " (if (expression bool >= (var_ref y) (constant float (0.000000)) ) (\n" + " (assign (constant bool (1)) (var_ref r) (constant float (1.570796)) ) \n" + " )\n" + " (\n" + " (assign (constant bool (1)) (var_ref r) (constant float (-1.570796)) ) \n" + " ))\n" + "\n" + " ))\n" + "\n" + " (return (var_ref r) )\n" + " ))\n" + "\n" + "\n" "\n" " (signature vec2\n" " (parameters\n" " (declare (in) vec2 y)\n" " (declare (in) vec2 x))\n" " ((declare () vec2 r)\n" - " (if (expression bool >\n" - " (expression vec2 abs (var_ref x))\n" - " (constant float (.0001)))\n" - " ((assign (constant bool (1))\n" - " (var_ref r) (call atan ((expression vec2 /\n" - " (var_ref y)\n" - " (var_ref x)))))\n" - " (if (expression bool <\n" - " (var_ref x)\n" - " (constant float (0.0)))\n" - " ((assign (constant bool (1))\n" - " (var_ref r)\n" - " (expression vec2 +\n" - " (var_ref r)\n" - " (expression vec2 *\n" - " (expression float sign (var_ref y))\n" - " (constant float (3.1415926))))))\n" - " ()))\n" - " ())\n" + " (assign (constant bool (1))\n" + " (swiz x (var_ref r))\n" + " (call atan ((swiz x (var_ref y))\n" + " (swiz x (var_ref x)))))\n" + " (assign (constant bool (1))\n" + " (swiz y (var_ref r))\n" + " (call atan ((swiz y (var_ref y))\n" + " (swiz y (var_ref x)))))\n" " (return (var_ref r))))\n" "\n" " (signature vec3\n" @@ -356,25 +366,18 @@ static const char *builtins_110_atan = { " (declare (in) vec3 y)\n" " (declare (in) vec3 x))\n" " ((declare () vec3 r)\n" - " (if (expression bool >\n" - " (expression vec3 abs (var_ref x))\n" - " (constant float (.0001)))\n" - " ((assign (constant bool (1))\n" - " (var_ref r) (call atan ((expression vec3 /\n" - " (var_ref y)\n" - " (var_ref x)))))\n" - " (if (expression bool <\n" - " (var_ref x)\n" - " (constant float (0.0)))\n" - " ((assign (constant bool (1))\n" - " (var_ref r)\n" - " (expression vec3 +\n" - " (var_ref r)\n" - " (expression vec3 *\n" - " (expression float sign (var_ref y))\n" - " (constant float (3.1415926))))))\n" - " ()))\n" - " ())\n" + " (assign (constant bool (1))\n" + " (swiz x (var_ref r))\n" + " (call atan ((swiz x (var_ref y))\n" + " (swiz x (var_ref x)))))\n" + " (assign (constant bool (1))\n" + " (swiz y (var_ref r))\n" + " (call atan ((swiz y (var_ref y))\n" + " (swiz y (var_ref x)))))\n" + " (assign (constant bool (1))\n" + " (swiz z (var_ref r))\n" + " (call atan ((swiz z (var_ref y))\n" + " (swiz z (var_ref x)))))\n" " (return (var_ref r))))\n" "\n" " (signature vec4\n" @@ -382,26 +385,23 @@ static const char *builtins_110_atan = { " (declare (in) vec4 y)\n" " (declare (in) vec4 x))\n" " ((declare () vec4 r)\n" - " (if (expression bool >\n" - " (expression vec4 abs (var_ref x))\n" - " (constant float (.0001)))\n" - " ((assign (constant bool (1))\n" - " (var_ref r) (call atan ((expression vec4 /\n" - " (var_ref y)\n" - " (var_ref x)))))\n" - " (if (expression bool <\n" - " (var_ref x)\n" - " (constant float (0.0)))\n" - " ((assign (constant bool (1))\n" - " (var_ref r)\n" - " (expression vec4 +\n" - " (var_ref r)\n" - " (expression vec4 *\n" - " (expression float sign (var_ref y))\n" - " (constant float (3.1415926))))))\n" - " ()))\n" - " ())\n" - " (return (var_ref r))))\n" + " (assign (constant bool (1))\n" + " (swiz x (var_ref r))\n" + " (call atan ((swiz x (var_ref y))\n" + " (swiz x (var_ref x)))))\n" + " (assign (constant bool (1))\n" + " (swiz y (var_ref r))\n" + " (call atan ((swiz y (var_ref y))\n" + " (swiz y (var_ref x)))))\n" + " (assign (constant bool (1))\n" + " (swiz z (var_ref r))\n" + " (call atan ((swiz z (var_ref y))\n" + " (swiz z (var_ref x)))))\n" + " (assign (constant bool (1))\n" + " (swiz w (var_ref r))\n" + " (call atan ((swiz w (var_ref y))\n" + " (swiz w (var_ref x)))))\n" + " (return (var_ref r)))))\n" "\n" "))\n" }; diff --git a/src/glsl/builtins/110/atan b/src/glsl/builtins/110/atan index bcf75718e45..84048293870 100644 --- a/src/glsl/builtins/110/atan +++ b/src/glsl/builtins/110/atan @@ -47,56 +47,66 @@ (var_ref y_over_x)) (constant float (1.0)))))))))) - (signature float - (parameters - (declare (in) float y) - (declare (in) float x)) - ((declare () float r) - (if (expression bool > - (expression float abs (var_ref x)) - (constant float (.0001))) - ((assign (constant bool (1)) - (var_ref r) (call atan ((expression float / - (var_ref y) - (var_ref x))))) - (if (expression bool < - (var_ref x) - (constant float (0.0))) - ((assign (constant bool (1)) - (var_ref r) - (expression float + - (var_ref r) - (expression float * - (expression float sign (var_ref y)) - (constant float (3.1415926)))))) - ())) - ()) - (return (var_ref r)))) + (signature float + (parameters + (declare (in ) float y) + (declare (in ) float x) + ) + ( + (declare () float r) + (declare ( ) float abs_retval) + (assign (constant bool (1)) (var_ref abs_retval) (call abs ((var_ref x) )) +) + (if (expression bool > (var_ref abs_retval) (constant float (0.000100)) ) ( + (declare ( ) float atan_retval) + (assign (constant bool (1)) (var_ref atan_retval) (call atan ((expression float / (var_ref y) (var_ref x) ) )) +) + (assign (constant bool (1)) (var_ref r) (var_ref atan_retval) ) + (if (expression bool < (var_ref x) (constant float (0.000000)) ) ( + (if (expression bool >= (var_ref y) (constant float (0.000000)) ) ( + (declare ( ) float assignment_tmp) + (assign (constant bool (1)) (var_ref assignment_tmp) (expression float + (var_ref r) (constant float (3.141593)) ) ) + (assign (constant bool (1)) (var_ref r) (var_ref assignment_tmp) ) + ) + ( + (declare ( ) float assignment_tmp) + (assign (constant bool (1)) (var_ref assignment_tmp) (expression float - (var_ref r) (constant float (3.141593)) ) ) + (assign (constant bool (1)) (var_ref r) (var_ref assignment_tmp) ) + )) + + ) + ( + )) + + ) + ( + (if (expression bool >= (var_ref y) (constant float (0.000000)) ) ( + (assign (constant bool (1)) (var_ref r) (constant float (1.570796)) ) + ) + ( + (assign (constant bool (1)) (var_ref r) (constant float (-1.570796)) ) + )) + + )) + + (return (var_ref r) ) + )) + + (signature vec2 (parameters (declare (in) vec2 y) (declare (in) vec2 x)) ((declare () vec2 r) - (if (expression bool > - (expression vec2 abs (var_ref x)) - (constant float (.0001))) - ((assign (constant bool (1)) - (var_ref r) (call atan ((expression vec2 / - (var_ref y) - (var_ref x))))) - (if (expression bool < - (var_ref x) - (constant float (0.0))) - ((assign (constant bool (1)) - (var_ref r) - (expression vec2 + - (var_ref r) - (expression vec2 * - (expression float sign (var_ref y)) - (constant float (3.1415926)))))) - ())) - ()) + (assign (constant bool (1)) + (swiz x (var_ref r)) + (call atan ((swiz x (var_ref y)) + (swiz x (var_ref x))))) + (assign (constant bool (1)) + (swiz y (var_ref r)) + (call atan ((swiz y (var_ref y)) + (swiz y (var_ref x))))) (return (var_ref r)))) (signature vec3 @@ -104,25 +114,18 @@ (declare (in) vec3 y) (declare (in) vec3 x)) ((declare () vec3 r) - (if (expression bool > - (expression vec3 abs (var_ref x)) - (constant float (.0001))) - ((assign (constant bool (1)) - (var_ref r) (call atan ((expression vec3 / - (var_ref y) - (var_ref x))))) - (if (expression bool < - (var_ref x) - (constant float (0.0))) - ((assign (constant bool (1)) - (var_ref r) - (expression vec3 + - (var_ref r) - (expression vec3 * - (expression float sign (var_ref y)) - (constant float (3.1415926)))))) - ())) - ()) + (assign (constant bool (1)) + (swiz x (var_ref r)) + (call atan ((swiz x (var_ref y)) + (swiz x (var_ref x))))) + (assign (constant bool (1)) + (swiz y (var_ref r)) + (call atan ((swiz y (var_ref y)) + (swiz y (var_ref x))))) + (assign (constant bool (1)) + (swiz z (var_ref r)) + (call atan ((swiz z (var_ref y)) + (swiz z (var_ref x))))) (return (var_ref r)))) (signature vec4 @@ -130,25 +133,22 @@ (declare (in) vec4 y) (declare (in) vec4 x)) ((declare () vec4 r) - (if (expression bool > - (expression vec4 abs (var_ref x)) - (constant float (.0001))) - ((assign (constant bool (1)) - (var_ref r) (call atan ((expression vec4 / - (var_ref y) - (var_ref x))))) - (if (expression bool < - (var_ref x) - (constant float (0.0))) - ((assign (constant bool (1)) - (var_ref r) - (expression vec4 + - (var_ref r) - (expression vec4 * - (expression float sign (var_ref y)) - (constant float (3.1415926)))))) - ())) - ()) - (return (var_ref r)))) + (assign (constant bool (1)) + (swiz x (var_ref r)) + (call atan ((swiz x (var_ref y)) + (swiz x (var_ref x))))) + (assign (constant bool (1)) + (swiz y (var_ref r)) + (call atan ((swiz y (var_ref y)) + (swiz y (var_ref x))))) + (assign (constant bool (1)) + (swiz z (var_ref r)) + (call atan ((swiz z (var_ref y)) + (swiz z (var_ref x))))) + (assign (constant bool (1)) + (swiz w (var_ref r)) + (call atan ((swiz w (var_ref y)) + (swiz w (var_ref x))))) + (return (var_ref r))))) )) |