首页 > 解决方案 > 根据另一个纹理的亮度,从一个纹理到另一个纹理的平滑渐变过渡

问题描述

我希望能够根据另一个纹理 (texture2) 的颜色/亮度从一个纹理 (texture0) 平滑地步进到另一个 (texture1)。

我可以使两个纹理重叠,但无法找到平滑步进纹理的解决方案。

    vec4 texture0 = texture2D(text0, vec2(text0_texture_x, text0_texture_y));
    vec4 texture1 = texture2D(text1, vec2(text1_texture_x, text1_texture_y));
    vec4 texture2 = texture2D(text2, vec2(text2_texture_x, text2_texture_y));


    if((texture2.r < 0.58 && texture2.r > 0.5) && (texture2.g < 0.58 && texture2.g > 0.5 ) && (texture2.b < 0.58 && texture2.b > 0.5)){
            if(texture1.r > 1.0){
                othertexture.a = 1.0;
            }
            else if(texture1.r <= 1.0){
                othertexture.a = othertexture_data_transparency + 0.25;
            }
            
            othertexture.rgb *= othertexture.a;
            texture0.rgb *= texture0.a;
            
            
            vec4 texture0_final_color;
            texture0_final_color.rgb = othertexture.rgb + (texture0.rgb * (1.0 - othertexture.a));
            texture0_final_color.a = othertexture.a + (texture0.a * (1.0 - othertexture.a));
            texture1.rgb *= texture1.a;
            
            vec4 texture1_final_color;
            texture1_final_color.rgb = othertexture.rgb + (texture1.rgb * (1.0 - othertexture.a));
            texture1_final_color.a = othertexture.a + (texture1.a * (1.0 - othertexture.a));
            // gl_FragColor = texture0_final_color*(1.0 - 0.1) + texture1_final_color*0.3;

            gl_FragColor = (texture0_final_color*(1.0 - 0.4) + texture1_final_color*0.3);
            // gl_FragColor = smoothstep(0.0, 0.9, texture2);
        }


        else if(texture2.r < 0.5 && texture2.g < 0.5 && texture2.b < 0.5){
            othertexture.a = othertexture_data_transparency;
            othertexture.rgb *= othertexture.a;
            texture0.rgb *= texture0.a;
            
            
            vec4 texture0_final_color;
            texture0_final_color.rgb = othertexture.rgb + (texture0.rgb * (1.0 - othertexture.a));
            texture0_final_color.a = othertexture.a + (texture0.a * (1.0 - othertexture.a));
            gl_FragColor = texture0_final_color;



        }
        else{
        
            if(texture1.r > 1.0){
                othertexture.a = 1.0;
            }
            else if(texture1.r <= 1.0){
                othertexture.a = othertexture_data_transparency + 0.25;
            }
            
            othertexture.rgb *= othertexture.a;
            texture1.rgb *= texture1.a;
            
            vec4 texture1_final_color;
            texture1_final_color.rgb = othertexture.rgb + (texture1.rgb * (1.0 - othertexture.a));
            texture1_final_color.a = othertexture.a + (texture1.a * (1.0 - othertexture.a));
            gl_FragColor = texture1_final_color;

        }
}

是否有更好的步进渐变解决方案来平滑过渡两个着色器?

标签: openglglslshaderalphablendingblending

解决方案


推荐阅读