3
votes

I'm trying to combine two texture using shaders in opengl es 2.0

enter image description here

as you can see on the screen shot, I am trying to create a needle reflection on backward object using dynamic environment mapping. but, reflection of the needle looks semi transparent and it's blend with my environment map.

here is the my fragment shader;

varying highp vec4 R;

uniform samplerCube cube_map1;
uniform samplerCube cube_map2;

void main()
{
    mediump vec3 output_color1;
    mediump vec3 output_color2;

    output_color1 = textureCube(cube_map1 , R.xyz).rgb;
    output_color2 = textureCube(cube_map2 , R.xyz).rgb;

    gl_FragColor = mix(vec4(output_color1,1.0),vec4(output_color2,1.0),0.5);  
}

but, "mix" method cause a blending two textures.

I'm also checked Texture Combiners examples but it didn't help either.

is there any way to combine two textures without blend each other.

thanks.

1
How do you define combining two textures without alpha blending? What should the output be, versus what you're getting? - Dan F
This doesn't really make sense. How would you combine textures without blending them? - Roest
I have two cube maps and one of these textures creating dynamically for reflection to other objects in scene. basically I don't want to blend dynamic map with my environment map. ok I will take a screen shot for better explanation. - ytur
Still doesn't make sense to combine the textures without alpha blending them - Dan F
Could you then base the mix() operation on the alpha channel of your needle texture, instead of a fixed 0.5 value? - Brad Larson♦

1 Answers

1
votes

Judging from the comments, my guess is you want to draw the needle on top of the landscape picture. I'd simply render it as an overlay but since you want to do it in a shader maybe this would work:

void main()
{
    mediump vec3 output_color1;
    mediump vec3 output_color2;

    output_color1 = textureCube(cube_map1 , R.xyz).rgb;
    output_color2 = textureCube(cube_map2 , R.xyz).rgb;

    if ( length( output_color1 ) > 0.0 )
         gl_FragColor = vec4(output_color1,1.0);
    else 
         gl_FragColor = vec4(output_color2,1.0);
}