Volumes Of Fun
http://www.volumesoffun.com/phpBB3/

[resolved] Raycast::doRaycast: abs is for int with gcc
http://www.volumesoffun.com/phpBB3/viewtopic.php?f=15&t=309
Page 1 of 1

Author:  ker [ Thu Jan 05, 2012 1:27 pm ]
Post subject:  [resolved] Raycast::doRaycast: abs is for int with gcc

inside Raycast::doRaycast there are 6 instances of abs used on float that should be std::abs.
otherwise the values get "floor"ed, too as the get cast to int and back.

Changing it to std::abs works fine here and fixes some nasty bugs I had with the raycaster.

Author:  David Williams [ Thu Jan 05, 2012 1:56 pm ]
Post subject:  Re: Raycast::doRaycast: abs is for int with gcc

So if you don't use the std:: prefix, which abs() function is it picking up instead? The C version? Is the wrong header being included, or is it getting it from a header included in your own project? Sorry, I don't have the code in front of me...

Author:  ker [ Thu Jan 05, 2012 2:15 pm ]
Post subject:  Re: Raycast::doRaycast: abs is for int with gcc

it takes the one from stdlib.h which is probably "
extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;"
at least netbeans tells me this inside of my project.

I put debug messages into Raycast.inl which showed that an int casting or sth similar happened.
after putting std:: infront, those debug messages showed that it's a proper "float abs"

I did this inside the BasicExample, so it's not my project messing around here.

Author:  David Williams [ Thu Jan 05, 2012 9:08 pm ]
Post subject:  Re: Raycast::doRaycast: abs is for int with gcc

No problem, I've fixed it (though I'll leave you to test). I also replaced abs() with std::abs() in a few other places.

The actual problem was probably that the C version of abs() is only for integer values... for floats you are supposd to use fabs(). In C++ this is resolved with function overloading.

Please confirm if it works now as I don't have a good test case.

Author:  ker [ Fri Jan 06, 2012 6:53 pm ]
Post subject:  Re: Raycast::doRaycast: abs is for int with gcc

yes it works great now.
here you can see the result: vertex based lighting brought to you by PolyVox::Raycast (combined with a pixel shader for preciser lighting w/o shadows)

Attachment:
screenshot01052012_143828698.jpg
screenshot01052012_143828698.jpg [ 48.69 KiB | Viewed 4586 times ]

Author:  David Williams [ Sun Jan 08, 2012 7:11 pm ]
Post subject:  Re: Raycast::doRaycast: abs is for int with gcc

ker wrote:
here you can see the result: vertex based lighting brought to you by PolyVox::Raycast (combined with a pixel shader for preciser lighting w/o shadows)


Wow, that works surprisingly well :-) I'd be interested to see how it looked in a more complex scene so keep up up to date on this. Does it take long to compute? The Raycast is also used by the AmbientOcclusionCalculator but it casts a lot more rays and is currently too slow I think.

On that topic, the Linux nightly regression tests for the AmbientOcclusionCalculator have started failing since this change. It might be a good thing as the Linux results were always different from the Windows ones and I never new why. Perhaps it was this use of abs(). Just bought my new laptop so once it's set up I'll see if it's now consistent.

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/