Noise Algorithm fails in Samsung Galaxy SIII (GLES)

后端 未结 2 648
星月不相逢
星月不相逢 2021-01-17 20:39

I am struggling to get the next simple algorithm working in the Samsung Galaxy SIII

float rand(vec2 co)
{
    return fract(sin(dot(co.xy ,vec2(12.9898,78.233         


        
2条回答
  •  后悔当初
    2021-01-17 20:52

    A bit of discussion of this issue on the ARM forums: http://forums.arm.com/index.php?/topic/16364-random-number-with-mali-400-mp/.

    The problem is because of FP16 precision in fragment shaders on the Mali GPU. Basically, there are no fractional bits left by the time fract is invoked (because the multipliers are so large), so you don't get any "noise" back at all. If you make the constants smaller, you'll start getting non-zero values back, but they won't be noisy. (I'm not entirely sure how the values were picked, and its not clear where this algorithm came from).

    Technically this noise algorithm is relying on higher (medium? high?) precision floating point operations, which are optional in fragment shaders. According to this other post you can check the platform's supported precision in fragment shaders by checking for the "OES_fragment_precision_high" extension in glGetString(GL_EXTENSIONS).

    The webgl-noise project in Nicol's answer doesn't seem as susceptible to floating-point truncation issues (it seems to keep things in a tighter bound). However, it has a period of around 300, and it generates more "structured" noise than the "white" (or "pink") noise you currently get. Its an excellent library, though, so its worth working into your code even if its not a drop-in replacement.

提交回复
热议问题