3

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.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
ytur
  • 1,232
  • 12
  • 22
  • 1
    How do you define combining two textures without alpha blending? What should the output be, versus what you're getting? – Dan F Aug 07 '12 at 14:13
  • This doesn't really make sense. How would you combine textures without blending them? – Roest Aug 07 '12 at 14:16
  • 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 Aug 07 '12 at 14:17
  • Still doesn't make sense to combine the textures without alpha blending them – Dan F Aug 07 '12 at 14:18
  • Oh, so you want the needle to simply appear on top of the environment background? – Dan F Aug 07 '12 at 14:35
  • yes, I try to get an opaque reflection of a needle, not a semi transparent. – ytur Aug 07 '12 at 14:38
  • 1
    Could you then base the `mix()` operation on the alpha channel of your needle texture, instead of a fixed 0.5 value? – Brad Larson Aug 07 '12 at 14:39
  • if I change the mix value to 1.0 for example, background scene is disappear. apparently mix method not a solution, I need an another way to find. – ytur Aug 07 '12 at 14:42

1 Answers1

1

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);
}
Roest
  • 826
  • 6
  • 16
  • thanks for your reply, I tried but it didn't work. actually I don't understand your solution. But it's inspired me to use two different shader program to send textures separately to fragment shader. I will try this, if it's works I will shared here. – ytur Aug 07 '12 at 15:11