没有高精度片段着色器的设备上的GLSL噪声功能

时间:2015-06-18 20:59:27

标签: glsl opengl-es-2.0 shader fragment-shader

我正在寻找一种噪音函数,它正在处理一个非highp片段着色器。

我尝试过:

//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);
}

主:

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;
}

两者在支持高点碎片精度的设备上工作正常。但是在像nexus 7这样的设备上,这不起作用。

我还尝试了此存储库中的着色器:webgl-noise 但即使他们没有工作。

关于highp支持片段着色器的结果(看起来很好):

result on highp shader

Nexus 7 2012的结果:

enter image description here

0 个答案:

没有答案