2

I'm looking for a noise function wich is working on a none highp fragment shader.

What I have tried:

//http://stackoverflow.com/questions/4200224/random-noise-functions-for-glsl
float snoise(vec2 co)
{
    return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}


//http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/
float snoise(vec2 co)
{
    float a = 12.9898;
    float b = 78.233;
    float c = 43758.5453;
    float dt= dot(co.xy ,vec2(a,b));
    float sn= mod(dt,3.14);
    return fract(sin(sn) * c);
}

Main:

void main()
{
    vec4 texCol = texture2D(uTexDiffuse, vTexCoord.xy);

    float n = snoise(vec2(vTexCoord.x*cos(uTime),vTexCoord.y*sin(uTime))); 

    gl_FragColor = texCol;
    gl_FragColor.rgb *= n;
}

both are working fine on a device which supports high point fragmentshader precision. But on a device like the nexus 7 this is not working.

I also tried the shader from this repository: webgl-noise But even they are not working.

Result on highp supporting fragment shader (looking fine):

result on highp shader

Result on Nexus 7 2012:

enter image description here

Bastl
  • 883
  • 2
  • 10
  • 27
  • 1
    I am having the same problem. Random function is less random on mobile device, than on desktop. I think it is because of different implementation of sine function. – Ivan Kuckir Aug 18 '15 at 14:11
  • If you find a workaround please let me know – Bastl Aug 18 '15 at 21:05
  • Here is my workaround: float random(vec2 co){ return max(0.00001, fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453*fract(float(iter+1)*3.17821*(0.71+rndnum)) ) ); } "iter" uniform is integer number of frame, "rndnum" uniform is random float, changed at each frame. I am averaging the result over multiple frames and it converges to uniform distribution. – Ivan Kuckir Aug 19 '15 at 07:49
  • I used it for real-time path-tracing in GLSL in my game http://powerstones.ivank.net/ :) – Ivan Kuckir Aug 20 '15 at 10:11

0 Answers0