0
votes

I have one background texture and transparent layer texture for that. When I loaded these texture only _layer3 final texture is active.

I want all the texture should be active so that I know the layer to be proceed further.

   glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, texture[0]);//texture _floorTexture
    glUniform1i(_textureUniform, 0);
           //glUniform1i(glPrograms[currentProgram].glUniforms[_textureUniform],_floorTexture);

    glActiveTexture(GL_TEXTURE0 + 1);
    glBindTexture(GL_TEXTURE_2D, texture[1]); //_layer0
    glUniform1i(_textureUniform, 1);

    glActiveTexture(GL_TEXTURE0 + 2);
    glBindTexture(GL_TEXTURE_2D, texture[2]); //_layer1
    glUniform1i(_textureUniform, 2);

    glActiveTexture(GL_TEXTURE0 + 3);
    glBindTexture(GL_TEXTURE_2D, texture[3]); //_layer2
    glUniform1i(_textureUniform, 3);

    glActiveTexture(GL_TEXTURE0 + 4);
    glBindTexture(GL_TEXTURE_2D, texture[4]); //_layer3
    glUniform1i(_textureUniform, 4); 
2
When you want to use multiple textures, you will also need multiple samplers in the shader and combine their results. Atm, you override the binding of the uniform after each texture binding.BDL
hi, could you share the sample shader for multiple texture?SathiyaKrishnan

2 Answers

0
votes

When using multiple textures, one also has to use multiple samplers in the shader. This could look for example like this:

in vec2 uv;

out vec3 color;

uniform sampler2D floor_texture;
uniform sampler2D layer0_texture;

void main()
{
    vec4 f = texture(floor_texture, uv);
    vec4 l0 = texture(layer0_texture, uv);

    color = mix(f.rgb, l0.rgb, 1 - l0.a);
}

Note that the composition depends on what you want to achieve and is just an example here.

-2
votes

This my shader

precision highp float;
varying vec2 interpolatedTextureCoordinate;
uniform sampler2D sourceTexture;
uniform float amount;
uniform sampler2D layerTexture;
const float PI = 3.14159265358979323846264;
const vec4 backgroundColor = vec4(0.0, 0.0, 0.0, 1.0);
const vec2 center = vec2(0.5, 0.5);
void main()
{   
vec4 source = texture2D(sourceTexture, interpolatedTextureCoordinate);
vec4 layer0 = texture2D(layerTexture, interpolatedTextureCoordinate);
float sigma = amount;
float distance = distance(center, interpolatedTextureCoordinate);
loat alpha = 2.0 * (1.0 / sqrt(2.0 * PI)) * exp((-sigma) * pow(distance, 2.0));   
gl_FragColor = mix(source.rgb, layer0.rgb , 1-layer0.a);

}

Regards Sathiya