简体   繁体   English

如何使用GLSL组合两个没有alpha混合的纹理

[英]How to combine two textures without alpha blending using GLSL

I'm trying to combine two texture using shaders in opengl es 2.0 我正在尝试在opengl es 2.0中使用着色器组合两个纹理

在此输入图像描述

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. 但是,“mix”方法会导致混合两个纹理。

I'm also checked Texture Combiners examples but it didn't help either. 我也检查了Texture Combiners示例,但它也没有帮助。

is there any way to combine two textures without blend each other. 有没有办法组合两个纹理而不相互混合。

thanks. 谢谢。

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM