From 3fa1b85196b7d57c6c139e62000ac519b1b2320c Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Fri, 30 Jul 2010 10:20:34 -0700 Subject: 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 --- src/glsl/builtins/110/atan | 166 ++++++++++++++++++++++----------------------- 1 file changed, 83 insertions(+), 83 deletions(-) (limited to 'src/glsl/builtins/110/atan') 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))))) )) -- cgit v1.2.3