使用するアルゴリズムを決定するためにブールユニフォームを渡す代わりに、コードを別のシェーダーを使用するように切り替えました。残念ながら、精力的なテストの結果、属性の1つ(halo)が新しいシェーダーを通過していないことがわかりました。ただし、使用する他の属性(位置)は渡されます。
簡略化されたコードは次のとおりです。
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);
...
フラグメントシェーダーは単純な「得られるテクスチャと色をレンダリングする」シェーダーです。
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 > 0.5){
colour.g = 0.0;
...
}
fragColour = colour;
...
halo > 0.5
上記のステートメントで緑の値を変更halo == 0.0
または交換すると、赤がレンダリングされます。それ以外の場合は、黄色がレンダリングされます。テストのために入力バッファをすべて1.0に変更しようとしましたが、違いはありませんでした。ハローが通過していないようです。
以前は、2つのシェーダーをマージし、実行するコードを決定するためのブールユニフォームを使用していましたが、正常に機能していました。他に何も変わっていません。入力バッファは同じで、カウントも同じです。今は別のシェーダーを使用しているだけです。何かご意見は?