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/builtin_function.cpp | |
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/builtin_function.cpp')
-rw-r--r-- | src/glsl/builtin_function.cpp | 166 |
1 files changed, 83 insertions, 83 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" }; |