[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] After installing latest Minefield : VertexAttribPointer: index out of range



Assuming this isn't a problem that arose during transcribing your code & shaders, I see the following issue:

<-- from the shader -->
  attribute vec3 vertexNormale;
...
  uniform mat4 projektionsMatrix;
  uniform mat4 normalenMatrix;

<-- from the code -->
     shaderProgram.vertexNormalAttribute = gl.getAttribLocation(shaderProgram, "vertexNormal");
...
     shaderProgram.pMatrixUniform = gl.getUniformLocation(shaderProgram, "projectionsMatrix");
..
     shaderProgram.nMatrixUniform = gl.getUniformLocation(shaderProgram, "normalMatrix");

----

The string that is used in the GLSL code and to query from the source code must match exactly.

That is "vertexNormale" will not match "vertexNormal".  Similarly with "projektionsMatrix"  vs. "projectionsMatrix" and for "normalenMatrix" vs "normalMatrix".

That said, I'm not quite sure how this would work on any platform, so perhaps you just transcribed the code wrong.  If that's the case, please copy/paste your code *exactly* as you are trying to compile it.

Hope this helps,
Daniel

On 2010-10-24, at 1:22 PM, M.Sirin wrote:

Okay, here it is:


<script id="shader-fs" type="x-shader/x-fragment">

   #ifdef GL_ES
   precision highp float;
   #endif
  
   varying vec3 vLightWeighting;
   varying vec3 myColor;

   void main(void) {
    gl_FragColor = vec4(myColor * vLightWeighting, 1.0);
   }
</script>

<script id="shader-vs" type="x-shader/x-vertex">
  attribute vec3 vertexPosition;
  attribute vec3 vertexNormale;
  attribute vec3 vertexColor;

  uniform mat4 modelViewMatrix;
  uniform mat4 projektionsMatrix;
  uniform mat4 normalenMatrix;
  uniform vec3 ambientLight;
 
  uniform vec3 constantColor; 
  uniform bool useUniformColor;
  uniform bool selecting;

  varying vec3 vLightWeighting;
  varying vec3 myColor;

  void main(void) {

      vec4 mvPosition=modelViewMatrix*vec4(vertexPosition,1.0); 
      gl_Position = projektionsMatrix * mvPosition;

      vec3 ambientColor = ambientLight;
      vec3 directionalLightColor = vec3(0.6, 0.6, 0.6);
      vec3 directionalVector = vec3(-0.7, -0.7, 0.9);

      // if(useUniformColor){
          myColor=constantColor;
      //}
      //else{ myColor=vertexColor;} 
      
      if(selecting){
          vLightWeighting=vec3(1.0,1.0,1.0);
      }else{
          vec3 lightDirection=normalize(directionalVector - mvPosition.xyz); 
            vec4 transformedNormal = normalenMatrix * vec4(vertexNormale, 1.0);

          float directionalLightWeighting = max(dot(transformedNormal.xyz, lightDirection), 0.0);    
          vLightWeighting = ambientLight + (directionalLightColor * directionalLightWeighting);
      }
  }

</script>

I think there is nothing odd with that? Again: It work's with Firefox 4.0b3 and Chromium. 
-----------

Then I've got another question: In case I remove the comments  

      // if(useUniformColor){
           myColor=constantColor;
      //}
      //else{ myColor=vertexColor;} 

Nothing is working with Chromium any more. That means there are no visible objects on screen, only the ones drawn via "vertexColor" . In my application there are 3 objects that uses this color-Attribute. Then I want to draw some objects via color that is sent with uniform to the shader (uniform vec3 constantColor; ) . Of course I first do     gl.disableVertexAttribArray(shaderProgram.vertexColorAttribute);  but still all of a sudden chromium is not drawing these objects.. 

Maybe you know why?

2010/10/24 Vladimir Vukicevic <vladimir@mozilla.com>


----- Original Message -----
> That is the shader program code:

I meant the GLSL code -- that is, whatever's in your shader-fs and shader-vs blocks.

   - Vlad


---
                        Daniel Koch -+- daniel@transgaming.com
Senior Graphics Architect -+- TransGaming Inc.  -+- www.transgaming.com