Jump to content
  • Advertisement
Sign in to follow this  
nullsquared

Shader arbitrary precision

This topic is 3201 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there any way of making arbitrary precision calculations in GLSL? I searched around the web but didn't find anything interesting.

Share this post


Link to post
Share on other sites
Advertisement
You can roll your own algorithms which do that, but don't expect a lot of performance. CPUs are better suited to such things.

Share this post


Link to post
Share on other sites
If you can write CPU code, then you can almost copy and paste to GLSL. Like the guy above, I don't think you will get much out of it. There would probably be an immense number of if statements to emulate any type of precision and I'm sure you will also need to do bit shifting and OR ing

Share this post


Link to post
Share on other sites
You may not need anything special.
For example, if I were writing a shader to draw fractals on faces, I would need some method to accurately zoom in on a specific area arbitrarily. This sounds like something you need arbitrary precision numbers for, but I think expressing a number as the sum of 2 floats would be enough, simply by taking advantage of how floats are concentrated exponentially around 0. That is, I have a complex number indicating the center of the sample area, and another complex number indicating the offset from that center to sample at, to determine if that point is within the set.

Of course, this would take some mathematical transformation trickery to perform right. Just outright adding a tiny float variable to a much larger float variable is likely to have no effect.

And also, I'm just talking about fractals, as they are the only thing I can think of right off the top of my head that you might want to use arbitrary precision for in a shader.

Share this post


Link to post
Share on other sites
No problem!
I'm suggesting you express p as a sum of 2 points: M, a uniform representing the center of the region you're sampling (i.e. the center of the screen), and D, the offset of this pixel from M. p = M + D. You are going to expect that M is much larger in magnitude than D, especially when you zoom way into the fractal to see smaller details.
Now go through all the calculations with that in mind, but try to avoid any cases where you *add* D and M components together because they are wildly different in magnitude, and you will lose precision. Multiplying is actually a lot better. (Just think of the internal way that floats are multiplied. You only lose at most one digit of precision provided the arguments aren't edge cases) z starts around 0 and should hang around 0, provided it is part of the set.
So instead of z^2 + p, you should try z^2 + D, and the explosion condition is (z + M)^2 > 2^2. Rearrange this to be z^2 > (4 - M^2) - 2*(z_r*M_r + z_i*M_i) or maybe you could put the z_r*M_r crap part on the other side or something. z_r is the real component, and z_i is the imaginary component. Same for M_r and M_i.

Hopefully this should work reasonably.

[Edited by - Cathbadh on March 9, 2010 12:06:50 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!