title: Perlin noise shader
body: <p>I am trying to create animated background for one of my applications. </p>
  
  <p>Basically, I want my activity to display <a href="http://www.youtube.com/watch?v=S4P81fk7z50" rel="nofollow">animated Perlin or Simplex noise</a> as the background. For low energy consumption I am trying to do everything using OpenGL. Unfortunately, I know very little about OpenGL.</p>
  
  <p>I started with <a href="http://developer.android.com/training/graphics/opengl/index.html" rel="nofollow">Displaying Graphics with OpenGL ES</a> and it worked. Then I tried to replace drawing code and vertex / fragment shaders for the Square but ended up with runtime exceptions. </p>
  
  <p>I am trying to use following vertex shader:</p>
  
  <pre><code>uniform mat4 uMVPMatrix;
  attribute vec4 vPosition;
  
  void main()
  {
      gl_Position = uMVPMatrix * vPosition;
  }
  </code></pre>
  
  <p>and slightly changed fragment shader from <a href="https://github.com/ashima/webgl-noise" rel="nofollow">Ashima Arts</a>:</p>
  
  <pre><code>float snoise(vec3 v) { 
    // ..
  }
  
  
  uniform float time; // Used for texture animation
  
  void main( void )
  {
    vec3 v_texCoord3D = gl_Position.xyz; 
  
    vec3 uvw = v_texCoord3D + 0.1*vec3(snoise(v_texCoord3D + vec3(0.0, 0.0, time)),
      snoise(v_texCoord3D + vec3(43.0, 17.0, time)),
      snoise(v_texCoord3D + vec3(-17.0, -43.0, time)));
    // Six components of noise in a fractal sum
    float n = snoise(uvw - vec3(0.0, 0.0, time));
    n += 0.5 * snoise(uvw * 2.0 - vec3(0.0, 0.0, time*1.4)); 
    n += 0.25 * snoise(uvw * 4.0 - vec3(0.0, 0.0, time*2.0)); 
    n += 0.125 * snoise(uvw * 8.0 - vec3(0.0, 0.0, time*2.8)); 
    n += 0.0625 * snoise(uvw * 16.0 - vec3(0.0, 0.0, time*4.0)); 
    n += 0.03125 * snoise(uvw * 32.0 - vec3(0.0, 0.0, time*5.6)); 
    n = n * 0.7;
    // A "hot" colormap - cheesy but effective 
    gl_FragColor = vec4(vec3(1.0, 0.5, 0.0) + vec3(n, n, n), 1.0);
  }
  </code></pre>
  
  <p>The draw function:</p>
  
  <pre><code>public void draw(float[] mvpMatrix)
  {
      GLES20.glUseProgram(m_program);
  
      int positionHandle = GLES20.glGetAttribLocation(m_program, "vPosition");
      GLES20.glEnableVertexAttribArray(positionHandle);
  
      int vertexStride = COORDS_PER_VERTEX * 4; // 4 bytes per vertex
      GLES20.glVertexAttribPointer(positionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, m_vertexBuffer);
  
      int timeHandle = GLES20.glGetUniformLocation(m_program, "time");
      GLES20.glUniform1f(timeHandle, time);
  
      int mvpMatrixHandle = GLES20.glGetUniformLocation(m_program, "uMVPMatrix");
      BackgroundRenderer.checkGlError("glGetUniformLocation");
  
      GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, mvpMatrix, 0);
      BackgroundRenderer.checkGlError("glUniformMatrix4fv");
  
      GLES20.glDrawElements(GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, m_drawListBuffer);
  
      GLES20.glDisableVertexAttribArray(positionHandle);
  }
  </code></pre>
  
  <p>Unfortunately, all I get is</p>
  
  <pre><code>java.lang.RuntimeException: glGetUniformLocation: glError 1282
  </code></pre>
  
  <p>raised on this line</p>
  
  <pre><code>int mvpMatrixHandle = GLES20.glGetUniformLocation(m_program, "uMVPMatrix");
  </code></pre>
  
  <p>How should I change my code?</p>