在 glBlendFunc() 中使用 GL_SRC1_COLOR [英] Using GL_SRC1_COLOR in glBlendFunc()

查看:158
本文介绍了在 glBlendFunc() 中使用 GL_SRC1_COLOR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 glBindFragDataLocationIndexed() 并在片段着色器中写入两种颜色.以下是我的代码:

I am using glBindFragDataLocationIndexed() and writing two colors in fragment shader. Following is my code :

glBindFragDataLocationIndexed(shader_data.psId, 0, 0, "Frag_Out_Color0");
glBindFragDataLocationIndexed(shader_data.psId, 0, 1, "Frag_Out_Color1");

glActiveTexture ( GL_TEXTURE0 );
LoadTexture(texture1);    
glBindTexture ( GL_TEXTURE_2D, tex_id1);
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,width, height, 0, GL_RGBA,GL_UNSIGNED_BYTE, texture1_data);

glActiveTexture ( GL_TEXTURE1 );
LoadTexture(texture2);
glBindTexture ( GL_TEXTURE_2D, tex_id2);
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,width, height, 0, GL_RGBA,GL_UNSIGNED_BYTE, texture2_data);


glEnable(GL_BLEND);
glBlendFunc(GL_SRC_COLOR, GL_SRC1_COLOR);

glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

片段着色器是:

#version 150
in vec2 texcoord;

uniform sampler2D basetexture1;
uniform sampler2D basetexture2;

out vec4 Frag_Out_Color0;
out vec4 Frag_Out_Color1;

void main(void)
{
    Frag_Out_Color0 = texture2D(basetexture1, texcoord);

    Frag_Out_Color1 = texture2D(basetexture2, texcoord);

}

OGL3.3 规范说:

OGL3.3 spec says that :

Data written to the first of these outputs becomes the first source
color input to the blender (corresponding to SRC_COLOR and SRC_ALPHA). Data
written to the second of these outputs generates the second source color input to
the blender (corresponding to SRC1_COLOR and SRC1_ALPHA).

我已将 GL_SRC_COLOR、GL_SRC1_COLOR 作为输入传递给 glBlendFunc().我不确定结果是否正确.请找到附件图片.此外,如果我通过 GL_ONE,GL_ONE ,则仅渲染第一个纹理,而根本没有第二个纹理的迹象.我如何验证我的其余代码是否正常(并且正确完成了混合)?

I have passed GL_SRC_COLOR, GL_SRC1_COLOR as inputs to glBlendFunc(). I am not sure whether the result is correct or not. Please find attached images. Also if I pass GL_ONE,GL_ONE ,only first texture is rendered and no sign of second texture at all. How can I verify that rest of my code is fine (and blending is correctly done) ?

以下分别是纹理 1、纹理 2 和结果.

Following are texture 1 , texture 2 and result respectively.

推荐答案

假设目标颜色是黑色,您的结果就是您所期望的.目前尚不清楚您究竟打算 glBlendFunc(GL_SRC_COLOR, GL_SRC1_COLOR); 做什么.但它会混合总是做什么.

Your result is what you would expect, assuming that the destination color is black. It's not clear what exactly you intend glBlendFunc(GL_SRC_COLOR, GL_SRC1_COLOR); to do. But what it will do is what blending always does.

源因子 (GL_SRC_COLOR) 将乘以源颜色(或者更准确地说是 source0 颜色).目标因子 (GL_SRC1_COLOR) 将乘以目标颜色.这些乘法的结果将加在一起.

The source factor (GL_SRC_COLOR) will be multiplied by the source color (or, to be more precise, the source0 color). The destination factor (GL_SRC1_COLOR) will be multiplied by the destination color. The results of these multiplications will be added together.

在您的情况下,这意味着 source0 颜色将乘以 本身(因此使结果更暗).目标颜色将乘以源 1 颜色;如果目标为零,则为 0.因此,将获得 source0 颜色乘以自身作为输出.

In your case, this means that the source0 color will be multiplied by itself (therefore making the result darker). The destination color will be multiplied by the source1 color; if the destination is zero, you get 0. Therefore, you get the source0 color multiplied by itself as the output.

双源混合有用(因为如果您需要在两种源颜色和目标颜色之间执行某些操作,那么这是您在着色器中无法做到的.如果它可以表示为(Src0 op Src1) op Dest,那么这就是你应该在你的着色器中做的事情.

Dual source blending is only useful (in that it's something you couldn't do in your shader) if you need to perform some operation between the two source colors and the destination color. If it can be expressed as (Src0 op Src1) op Dest, then it's stuff you should do in your shader.

这篇关于在 glBlendFunc() 中使用 GL_SRC1_COLOR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆