开发者

gl_fragColor with multiple textures

I currently have two textures being applied to a single object. Eventually there will be a couple more added to that, but I am having trouble getting the current two to work properly.

At the moment, I am setting my fragcolor to the two images added together. Literally all I am doing is something similar to :

gl_FragColor = texture1 + texture2;

I am sure there is a better way to do such things to begin with, but it also creates the problem that where the images overlap is added together (obviously), which is not what I am trying to do with my current project.

I am not sure if this is simply an issue with only my fragColor, where there's some built in function of GLSL to do something like this, or if I need to do something like c开发者_Python百科ombine the images before hand in some other fashion.

EDIT :: Example of the color adding I meant : http://i.imgur.com/0vH4F.png


I take it you want to blend the two textures in the shader instead of doing it with regular blending. Something like this should work, I believe - you can probably simplify this if you make assumptions.

gl_FragColor = backgroundcolor;
gl_FragColor = (gl_FragColor*(1-texture1.a))+(texture1*texture1.a);
gl_FragColor = (gl_FragColor*(1-texture2.a))+(texture2*texture2.a);

EDIT:

The final answer here ended up being regular blending, and not blending in the fragment shader.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜