Blending textures with transparency

Started by
7 comments, last by _WeirdCat_ 9 years, 2 months ago

I have already asked about this on another forum and after being unable to resolve the issue I thought I'd try here. I have been trying to fix this for a very very very long time and its very frustrating...

Basically I want to draw a texture on top of a face like a decal but i also want the textures color to be blended with the faces color(WITHOUT MODIFYING THE ACTUAL FACE! ONLY TEXTURE!)

the problem is the texture is transparent and blending it makes the face transparent too.
Here is one texture
rorojU7.png
Here is an example using this texture
no blending:
90y7Fjg.png
blending:
HW5CoIc.png
I have been told to use


 glEnable(GL_ALPHA_TEST);
 glAlphaFunc(GL_GREATER, 0.0f);
but here is the result with no blending:
clSlJqq.png
and with blending:
XIoZSYB.png
by using gl env mode GL_DECAL, i can see the actual face color but the texture of course is white instead of blended with the face...
here is what i mean:
I8mxFN0.png
what i want to achieve is a combination of both of these.
texture color blended but then placed on the original face like a decal
35yjMmu.png
I have been told to sort the faces with alpha but it doesnt do anything since the blending is changing the actual face to almost invisible
Advertisement

i would suggest you to use a shader on that face then you will simply bind a texture (that with clouds) read the color and if the color is bigger than 0 you will perform blending (in this case you make your own one) anyway what sort of glBlendFUnc are you using i am pretty sure this will help:

http://www.andersriggelsen.dk/glblendfunc.php

and

use gl_src_color and maybe gl_dst_color, becasue i see that your texture has wrong alpha values, additionally i am not sure but you will have to disable depth testing for this case,

so the answer is simple use shader for that.

i would suggest you to use a shader on that face then you will simply bind a texture (that with clouds) read the color and if the color is bigger than 0 you will perform blending (in this case you make your own one) anyway what sort of glBlendFUnc are you using i am pretty sure this will help:

http://www.andersriggelsen.dk/glblendfunc.php

and

use gl_src_color and maybe gl_dst_color, becasue i see that your texture has wrong alpha values, additionally i am not sure but you will have to disable depth testing for this case,

so the answer is simple use shader for that.

I dont really know anything at all about shaders. Can you give me an example shader and how to implement it into the rendering (besides the compiling which i know how to do)

also i swear i have tried just about every combination possible for glblendfunc and glblendfuncseparate but i will try out that tool

Not sure I entirely understand what you want to achieve, but try something like this:


// Draw face without blending "base color"
drawSolid();

// Draw blended on top of already drawn faces
glDepthFunc(GL_EQUAL);

glBlendFunc(..);
glEnable(GL_BLEND);

drawBlended();

Could do the same with modulate instead of blend, or some other combination, or even draw several blending passes on top.

Out of principle I don’t help people who are using the fixed-function pipeline.
#1: It’s just encouraging bad behavior. Bad dog.
#2: It’s like someone asking you to help figure out how to use his or her 1980 Apple III when there is a 2017 Alienware L. Spiro Supreme Mega Ultra Plus Neo Giga Mecha Panties Over-9,000 PC sitting right next to him or her. You’re helping for a bad reason (he or she is just intimidated by the more-complex look of the newer machine), and in the end you’ll just have to re-teach him or her once he or she finally moves on to the bigger better machine, so you’re wasting your time anyway.


I can’t really understand what you are trying to do. It doesn’t help that the image you showed of what you want to achieve (“desired”) is for some reason the only image that is basically impossible to see. That’s the one image that should be absolutely clearest and easiest to see.

My best guess: Your model has vertex colors or a material and you want to blend them with a texture.
#1: glBlendFunc() and glAlphaFunc() apply to how the final pixel mixes with the back buffer (or gets discarded). Disable blending and alpha testing. You’re not trying to blend with the back buffer, you are trying to blend a texture over a model’s material/vertex color.
#2: glTexEnvi(). Read carefully how pixels travel through the texture-stage states and carefully figure out what settings you need to apply to get the result you want. Since you posted that GL_MODULATE isn’t working for you, once again I don’t know what you are trying to do so I can’t really make many suggestions, but the result you posted of GL_MODULATE isn’t the result I would have expected, so you may not have gotten the pname value correct.

Here is the thought process:
#1: What is source 0? The model’s base color.
::glTexEnvi( GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS );
#2: What is source 1? The texture in slot 0.
::glTexEnvi( GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE0 );
#3: How do you want to combine these 2 inputs? Multiply them?
::glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE );
Repeat for alpha.

I don’t know what you want to do, but if you use these 3 steps and carefully pick the sources (which I am fairly sure I already got correct above) and the way in which they are combined you should be able to find your result.


Or you should just switch to shaders and make whatever you want happen.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Out of principle I don’t help people who are using the fixed-function pipeline.#1: It’s just encouraging bad behavior. Bad dog.#2: It’s like someone asking you to help figure out how to use his or her 1980 Apple III when there is a 2017 Alienware L. Spiro Supreme Mega Ultra Plus Neo Giga Mecha Panties Over-9,000 PC sitting right next to him or her. You’re helping for a bad reason (he or she is just intimidated by the more-complex look of the newer machine), and in the end you’ll just have to re-teach him or her once he or she finally moves on to the bigger better machine, so you’re wasting your time anyway.I can’t really understand what you are trying to do. It doesn’t help that the image you showed of what you want to achieve (“desired”) is for some reason the only image that is basically impossible to see. That’s the one image that should be absolutely clearest and easiest to see.My best guess: Your model has vertex colors or a material and you want to blend them with a texture.#1: [font='courier new', courier, monospace]glBlendFunc()[/font] and [font='courier new', courier, monospace]glAlphaFunc()[/font] apply to how the final pixel mixes with the back buffer (or gets discarded). Disable blending and alpha testing. You’re not trying to blend with the back buffer, you are trying to blend a texture over a model’s material/vertex color.#2: [font='courier new', courier, monospace]glTexEnvi()[/font]. Read carefully how pixels travel through the texture-stage states and carefully figure out what settings you need to apply to get the result you want. Since you posted that [font='courier new', courier, monospace]GL_MODULATE[/font] isn’t working for you, once again I don’t know what you are trying to do so I can’t really make many suggestions, but the result you posted of [font='courier new', courier, monospace]GL_MODULATE[/font] isn’t the result I would have expected, so you may not have gotten the pname value correct. Here is the thought process:#1: What is source 0? The model’s base color.[font='courier new', courier, monospace]::glTexEnvi( GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS );[/font]#2: What is source 1? The texture in slot 0.[font='courier new', courier, monospace]::glTexEnvi( GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE0 );[/font]#3: How do you want to combine these 2 inputs? Multiply them?[font='courier new', courier, monospace]::glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE );[/font]Repeat for alpha. I don’t know what you want to do, but if you use these 3 steps and carefully pick the sources (which I am fairly sure I already got correct above) and the way in which they are combined you should be able to find your result. Or you should just switch to shaders and make whatever you want happen. L. Spiro


I don't have access to a computer right now but I don't have any experience at all with shaders. Someone over at the LWJGL forum told me the fix to this would be too complex if I didn't know anything about shaders and that I should just avoid it. I have tried disabling the blending but then anything with alpha zero shows as opaque black. And what I'm trying to do is apply these textures to a face and blend the face color with the texture. I DONT want the face color to change though. When it blends the face with these transparent textures it turns the face nearly completely transparent because it's blending the face too. Last time I tried to use shaders I ended up getting a black model with no color or texture but I can give it a shot

Someone over at the LWJGL forum told me the fix to this would be too complex if I didn't know anything about shaders and that I should just avoid it.

Then fuck that dude. No sane OpenGL developer from the last 10 years tells someone to "avoid shaders because they're too complex."

I don't have access to a computer right now but I don't have any experience at all with shaders.
Well, then its time for you to know what you're doing! Here: Learning Modern OpenGL Programming.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

You spend more time explaining what did not work than what result you want. What exactly did you not like about the result from using GL_DECAL? If you dont like the color of the decal, you could just use a differently colored texture or if you want the color to partially shine through change the texture to halve the alpha values.

But really you should learn to use shaders.

still his problem is texture alpha and blending equation but he didint say what is the correct result thus shaders would be the best option.

This topic is closed to new replies.

Advertisement