Jump to content
  • Advertisement
Sign in to follow this  
deshan

GLSL iOS values beyond 2048 modules operation fails

This topic is 847 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

Hi,

 

I have a simple shader program which runs on iOS devices. Below is the part of the fragment shader code where i face the problem.

highp float val = floor(gl_FragCoord.x); // val anything beyond 2048 below condition never reach else part.

if(mod(val, 2.0) == 0.0)
  // execute 1
else
  // execute 2

For the  above float variable 'val', it assign values beyond 2048 in iPad Pro(iPad Pro resolution 2732 x 2048). For iPhones and other iPads I never faced this issue. 

 

If I assign values directly as

highp float val = 2050; // 2051;

Then I do not get this issue. Only have this issue when assign values using gl_FragCoord.x.

 

Please help.

 

Thanks and Regards,

Des

Edited by deshan

Share this post


Link to post
Share on other sites
Advertisement

First, you may want to start printing gl_FragCoord.x / 2732.0f to see if you actually get a black to white gradient; the resolution may be different from what you expect. And be sure you've declared gl_FragCoord as highp.

 

Second, when floating point precision begins to have problems, it will start by eliminating odd numbers and preserving even numbers. This is extremely suspicious.

I wouldn't be surprised if by oversight gl_FragCoord.x doesn't have enough precision to represent the entire iPad Pro's resolution. See Precision limitations on integer values.

Edited by Matias Goldberg

Share this post


Link to post
Share on other sites

First, you may want to start printing gl_FragCoord.x / 2732.0f to see if you actually get a black to white gradient; the resolution may be different from what you expect. And be sure you've declared gl_FragCoord as highp.

 

Second, when floating point precision begins to have problems, it will start by eliminating odd numbers and preserving even numbers. This is extremely suspicious.

I wouldn't be surprised if by oversight gl_FragCoord.x doesn't have enough precision to represent the entire iPad Pro's resolution. See Precision limitations on integer values.

 

Thanks Matias for the reply.

 

I have tried experimenting with resolution values. I do not know how to get the gradients but resolution is correct.

 

I tried like below, and it's ok

highp float xpos = floor(gl_FragCoord.x) ;

if (xpos <= 2048.0)
 gl_FragColor = // red;
else if (xpos > 2048.0 && xpos < 2500.0)
 gl_FragColor = // green;
else
 gl_FragColor = // blue;

But if I use mod operation as below, then it fails above 2048. I just want to check odd and even check. 

highp float xpos = floor(gl_FragCoord.x) ;

if(mod(xpos, 2.0) == 0.0)
  gl_FragColor = // red;
else
 gl_FragColor = // green;

Very difficult to understand why. If I assign values directly to xpos even beyond 2048. Then program works ok.

highp float xpos = 2050.0; // 2051.0, 2052.0

if(mod(xpos, 2.0) == 0.0)
  gl_FragColor = // red;
else
 gl_FragColor = // green;

Thanks

 

Edit : And this works ok in iPad Pro simulator

Edited by deshan

Share this post


Link to post
Share on other sites
In general you should not use the == operator for floating point values.

If you are just looking for the rounded number to be odd or even, then try something like:
if(mod(xpos, 2.0) <= 1.0)

Share this post


Link to post
Share on other sites

Also note that gl_FragCoord contains the window relative position of the fragment, thus the floor( gl_FragCoord.x ) is superfluous, there is no fractional component. What matias suggest is to set the output color based on the calculation he described and you should see an color gradient as the final output in your render target. One suggestion I would make it to have the GLSL ES specification on hand when working for consultation, very helpful in a pinch sometimes.

Share this post


Link to post
Share on other sites

Ok, from what I can see, this is clearly a precision problem. gl_FragCoord must be a 16-bit floating point; which would make perfect sense because 16-bit floats can represent up to 2048 perfectly, but can only represent multiples of 2 between the range [2048; 4096].

By spec gl_FragCoord is defined to be mediump; but obviously that's going to break multiple apps on the iPad Pro and should be considered an iOS bug.

I suggest you raise a bug ticket to Apple. They like having everything handed in silver plate (can't blame them), so make a simple XCode project that can repro the problem so they can quickly open in XCode, build and run.

Edited by Matias Goldberg

Share this post


Link to post
Share on other sites

gl_FragCoord is declared as highp in GLSL ES 3.00, so you could switch to GLSL ES 3.00 instead of GLSL ES 1.00 if you're using GLES3.

Share this post


Link to post
Share on other sites

I am relying on GPU Image which uses GLES 2.0

 

I have raised a bug in the apple bug tracker. But still no response and status is:

 

 

24224673 
State:OpenProduct:iOS SDK

Rank:No Value

Share this post


Link to post
Share on other sites

This is the simple Xcode version, if someone got an iPad pro. please test.

 

Still didn't manage to figure it out. No response from the apple either.

Share this post


Link to post
Share on other sites

Ok I have a reply in apple bug tracker.

 

This issue behaves as intended based on the following:

You should either try with an es 300 shader or redefine gl_FragCoord to be highp.

Please update your bug report to let us know if this is still an issue for you.

 

 

Since I am develop the program on GPUImage library es 300 won't suit for me (As I know, please correct if i'm wrong).

 

But can some one please explain how to redefine the gl_fragcoord to be highhp?

 

I googled it but not managed to find a proper answer.

 

I am new to glsl.

 

Thanks 

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!