Note that there are some explanatory texts on larger screens.

plurals
  1. POVertex attributes not being passed to shader
    primarykey
    data
    text
    <p>I've just switched my code over to using a separate shader instead of passing a boolean uniform to decide which algorithm to use. Unfortunately, after vigorous testing, I've discovered that one of the attributes (halo) is not being passed through the the new shader. The other attribute it uses (position) <strong>is</strong> passed through, though.</p> <p>Abdridged code follows:</p> <pre><code>Java code: // Attributes protected static int position = 0; protected static int colour = 1; protected static int texture = 2; protected static int halo = 3; protected static int normal = 4; protected static int program1; protected static int program2; ... // Linking shader1 GLES20.glBindAttribLocation(program1, position, "position"); GLES20.glBindAttribLocation(program1, colour, "colour"); GLES20.glBindAttribLocation(program1, texture, "texCoord"); GLES20.glBindAttribLocation(program1, normal, "normal"); GLES20.glLinkProgram(program1); ... // Linking shader2 GLES20.glBindAttribLocation(program2, position, "position"); GLES20.glBindAttribLocation(program2, halo, "halo"); GLES20.glLinkProgram(program2); ... GLES20.glUseProgram(program1); GLES20.glVertexAttribPointer( position, 3, GLES20.GL_FLOAT, false, 0, buffer); ... //Render with program1 ... GLES20.glUseProgram(program2); GLES20.glVertexAttribPointer( halo, 1, GLES20.GL_FLOAT, false, 0, doHaloBuffer); GLES20.glEnable(GLES20.GL_BLEND); GLES20.glDisable(GLES20.GL_DEPTH_TEST); ... // Using lines for testing purposes GLES20.glDrawElements(GLES20.GL_LINE_LOOP, haloIndexCount, GLES20.GL_UNSIGNED_SHORT, haloIndexBuffer); ... </code></pre> <p>Fragment shaders are just simple "Render the texture and colour you get" shaders</p> <pre><code>shader1.vsh: attribute vec3 position; attribute vec4 colour; attribute vec2 texCoord; attribute vec3 normal; ... varying vec2 fragTexCoord; varying vec4 fragColour; ... // All attributes used at some point shader2.vsh: attribute vec3 position; attribute float halo; varying vec4 fragColour; ... vec4 colour = vec4(1.0, 1.0, 0.0, 1.0); if(halo &gt; 0.5){ colour.g = 0.0; ... } fragColour = colour; ... </code></pre> <p>If i change <code>halo &gt; 0.5</code> to <code>halo == 0.0</code> or swap the green values in the above statements, red is rendered otherwise yellow is rendered. I tried altering the input buffer to be all 1.0 for testing but it made no difference. It seems that <em>halo</em> is not being passed through.</p> <p>Previously, I had the two shaders merged and had a boolean uniform to decide which code to run and it worked fine. Nothing else has changed; the input buffers are the same, the counts are the same it's just that I'm using separate shaders now that is different. Any thoughts?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload