I am currently trying to get multiple textures working on android (with one fragment shader). It works fine on my Nexus 4 but on all Samsung devices I've tested it on, it just doesn't show the rectangle at all. The problem seems to be that texture2d is called twice within the fragment shader code:
precision mediump float;
uniform sampler2D uTexture;
uniform sampler2D refractTexture;
varying vec2 vTexCoordinate;
varying vec2 vRefTexCoordinate;
void main() {
vec2 scaleVec = vec2(0.05, 0.05);
vec4 bumpTex = 2.0 * texture2D(refractTexture, vRefTexCoordinate) - 1.0;
vec2 refCoords = vTexCoordinate.xy + bumpTex.xy * scaleVec;
gl_FragColor = texture2D(uTexture, refCoords);
}
In this shader I distort the texture (uTexture
) with a normal map (refractTexture
).
I've tried out using the correct (not the calculated) coordinates for gl_FragColor
and as soon as I delete vec4 bumpTex = 2.0 * texture2D(refractTexture, vRefTexCoordinate) - 1.0;
it appears on the devices.
Any hint will help.
As requested here is the Java Code I use to set up the textures:
mTextureUniformHandle = GLES20.glGetUniformLocation(mProgram,
"uTexture");
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle);
GLES20.glUniform1i(mTextureUniformHandle, 0);
if (refractNormal && textureRefBuffer != null) {
mTextureRefUniHandle = GLES20.glGetUniformLocation(mProgram,
"refractTexture");
GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureRefDataHandle);
GLES20.glUniform1i(mTextureRefUniHandle, 1);
mTextureRefCoordinateHandle = GLES20.glGetAttribLocation(mProgram,
"aRefTexCoordinate");
GLES20.glVertexAttribPointer(mTextureRefCoordinateHandle,
mTextureCoordinateDataSize, GLES20.GL_FLOAT, false, 0,
textureRefBuffer);
GLES20.glEnableVertexAttribArray(mTextureRefCoordinateHandle);
}
mTextureCoordinateHandle = GLES20.glGetAttribLocation(mProgram,
"aTexCoordinate");
GLES20.glVertexAttribPointer(mTextureCoordinateHandle,
mTextureCoordinateDataSize, GLES20.GL_FLOAT, false, 0,
textureBuffer);
GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);
And the C Code of the vertex shader:
uniform mat4 uMVPMatrix;
attribute vec4 vPosition;
attribute vec2 aTexCoordinate;
attribute vec2 aRefTexCoordinate;
varying vec2 vTexCoordinate;
varying vec2 vRefTexCoordinate;
void main() {
vTexCoordinate = aTexCoordinate;
vRefTexCoordinate = aRefTexCoordinate;
gl_Position = uMVPMatrix*vPosition;
}