Multitexturing in two passes

hello,

I try to mix two textures (grass and soil for example) but would setup the mix factor with a third texture that is a grayscale texture…

these are the grass textures and soil texture:

I would mix the two textures above, using the color of this texture in order to setup the mix factor between them:

and I would obtain this:

My graphic card is a geforce4 MX440 with 2 textures units.

But I don’t find a way to do the mix using these three textures with 2 texture units even if I do this in two passes…

Someone has an Idea?

Thank you.

If I remember well, this has been covered quiete recently in those forums. So make a search.

Yes, he had this question in the advanced forums, but since he had trouble understanding even the basics of texture combining, after a lengthy discussion, he’s been sent over to the beginners forum. So now we can start from scratch :slight_smile:

Ok, so first of all, you have to decide if you really need pixel level mixing information! Because if you don’t, then you can use vertex colors to create a ramp to mix the two textures, and then you could do that in one pass. My advice is to stick to the simple one pass solution, because a multi pass solution will probably be too difficult (and of course slower). So, which solution do you choose?

:slight_smile: If someone (a beginner with multitexturing) understand how I can do this with the thread I put in opengl advanced coding forum i will congratulate him…frankly we beat about the bush all over the thread! And I know the basics of texture combining and I will repeat for the 100th time that my problem is that I don’t find the way to do the mix and not that I don’t understand code lines…

Moreover, if I persist to ask how I can do this with a grayscale texture it is not to do this with vertex color ,because I want to use other grayscale texture more complicated.
If I don’t find a mean to do this with a grayscale texture I will do it with vertex color…but it is not my 1st goal…

if I suggest a 2 passes rendering it is because I didn’t find the way to do the mix in a single pass with 2 texture units, and I know that it is slower.
So I accept in a first time single pass and two passes rendering with two texture units and the grayscale texture

In a 2nd time I accept to use vertex color if we don’t find a way to this with the grayscale texture

thank you

draw the first pass texture (grass) opaquely. then load the sand and gradient (make sure the gradient is in the alpha channel, and the rgb channels are white) into units 0 and 1 respectively, enable modulate texenv (the default), enable glBlendFunc( GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA) blending, then draw your second pass. simple.

you should give dorbie and crazybutcher 10 stars each after what they did for you. they really went the extra yard for you in the advanced forum, don’t you think? it’s not often that beginners get their hands held in the advanced forum, so consider yourself very fortunate.

hope this helps

ok, who are you- dorbie or the butcher :stuck_out_tongue: ?

thank you, but How can I do to set SOURCE1’s RGB channels ( gradient texture ) white?

because the gradient texture is a loaded from a tga and I can’t make the entire picture white and make the alpha channel as a gradient…anyway photoshop 7 don’t allow me to save a alpha layer in addition to the tracing paper! ( I hope you understand me I did find better than tracing paper for “calque” in french!) :slight_smile:

I don’t have photoshop right here so I can’t give you the full way to do the job, but yes, you can do a 32bits TGA with it. You don’t need multiple layers to do so. Just do a plain white layer and add an alpha channel. Select your alpha channel and draw your gradient in it… that’s all…

Sorry I confused my forums there.

Please clarify,

Do you need lighting? You did in the last thread.

Just making sure that we have ALL the facts this time before answering the wrong question over and over (someone hasn’t learned their lesson).

This is actually a simple problem if you understood multitexture+combiners+crossbar in sufficient detail this would have been done by now.

In fact photoshop 7 had some problems with tga pictures, but now it is repaired and I obtained a tga picture white painted and a alpha layer as gradient.

but ghlaksde what do you mean when you say :
“enable glBlendFunc( GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA) blending, then draw your second pass. simple.”

I have already enable blending and glBlendfunc() but then I don’t know what I have to do to draw the second pass…
I have to modulate the source0 ( soil) and source1: gradient ( white colored), for the RGB layer but I do nothing with the alpha layer.
So i did not obtain the good result.

Yes I need the light, I use GL_MODULATE in the first pass.
Please explain me “crossbar” I think I did not understant this and I don’t use this to do the mix.
thank you

i think this guy’s just getting his jollies busting people’s chops.

he was emberassed when his unvarnished understanding of opengl was revealed in the advanced forum, so now he’s seeking revenge in the beginner’s forum.

dletozen, don’t you have some small animals to torture? i hear tiny tim is looking for his crutch.

Voila t’as tout compris!
moi qui pensais tout savoir me voila bien embarrassé!

If I posted in advanced forum it is because I thought that I had more success in it than the beginner forum because multitexturing is not the first thing we learn to do with opengl.

Et maintenant si t’as rien d’autre a foutre que pourrir ce thread Jason, tu peux te casser ou repondre a la question.

Don’t pay any attention to that dletozeun, this is the best thing to do, beleive me :slight_smile:

salut! Merci…je sais, c’est pour ca que je lui laisse le soin de traduire si il comprend pas :slight_smile:

Crossbar just lets you feed multiple textures into a single unit, this was already explained (other extensions apparently encompass the same functionality).

It’s not simple if you don’t properly account for what the components do in your blendfunc, you need to think about the arithmetic in your blending pass. That would only work if you output the ramp as the alpha channel of the second pass. Then it’d work just fine.

Another approach that uses an RGB ramp follows:

Disable blending and in the first pass use grass * texture ramp, that would be a modulate;

Next set glBlendfunc(GL_ONE, GL_ONE);

and draw texture soil * 1-ramp, that is another modulate and you can use operand modifiers for the 1-SRC_COLOR for teh ramp.

Voilà!

Still no mention of lighting in your question, I guess we’ll have to deal with that now that you’ve been given the answer you asked for but are still no nearer a solution.

thank you everybody for your help!! Dorbie your are a genius! :smiley: At last It works!

I have just read blending paragraph in the redbook and I have realize that I had a bad idea about alpha layer with opengl.
In fact in photoshop more the alpha layer is white more the picture is transparent! this layer represent the picture’s trasparency. But ist is the opposite! more the alpha layer is white more the fragment is opaque…so alpha layer represent texture’s opacity!

So I had already try to use youy 2nd approach Dorbie but I did not set glBlendFunc() correctly!

But it is not perfect…there is still a problem! :stuck_out_tongue:
In fact it is a lighting problem, because in the 1st pass dark and lighted zones are correctly modulate with the texture, but in the 2nd pass the texture is not modulate with map lighting…

I think it is normal viewing what I am doing but I dont find another way to obtain lighting in 1st and 2nd passes.

nom[0] soil
nom[1] grass
nom[2] gradient
nom[4] 1-gradient

1st pass

glDisable(GL_BLEND);
        glActiveTextureARB( GL_TEXTURE0_ARB );
        glEnable( GL_TEXTURE_2D );
        glBindTexture( GL_TEXTURE_2D, nom[1] );

        glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB );
        glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE );
        glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE );
        glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR );
        
        glActiveTextureARB( GL_TEXTURE1_ARB );
        glEnable( GL_TEXTURE_2D );
        glBindTexture( GL_TEXTURE_2D, nom[2] );
        glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB );
        glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE );
        
        glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS );
        glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR );
        glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE );
        glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR );

2nd pass

glEnable(GL_BLEND);
        glBlendFunc(GL_ONE, GL_ONE);
        
        glActiveTextureARB( GL_TEXTURE0_ARB );
        glEnable( GL_TEXTURE_2D );
        glBindTexture( GL_TEXTURE_2D, nom[0] );
        glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB );
        glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE );
        glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE0 );
        glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR );

        glActiveTextureARB(GL_TEXTURE1_ARB );
        glEnable( GL_TEXTURE_2D );
        glBindTexture( GL_TEXTURE_2D, nom[4] );

        glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB );
        glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE );
        
        glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE0 );
        glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR );
        
        glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE1 );
        glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR );

thank you.

You are using texture0 as an input instead of previous in the second unit of your second pass, this means that the modulate of texture by primary_color (I assume primary_color holds your lighting) is ignored. Use previous as the source instead of texture0 in the second unit of the second pass and all should be OK (although I don’t see where 1-ramp is coming from in the second pass, maybe you have two textures; ramp and 1-ramp, that’s a bit of a waste since that operand would generate the negative image on the fly for you).

You should be able to visualize what is going on here and figure this out for yourself, try to sketch out what is happening in the combiners on a piece of paper to help your understanding. I am not a genius, this is actually a pretty simple problem. If you could see the data flow through the combiners (not hard to do) you’d have solved this pretty quickly.

This brings me to my last point, for you this should not be about solving this one problem, rather it should be about gaining the insight to solve it yourself, since it hopefully won’t be your last use of combiners there will be more problems for you to face in the future, some of them a bit more complex than this one.

Thank you!

It is normal that I did not solve the problem myself …because I did not read all the opengl specification…
but now this problem is resolved and I understand better the multitexturing mechanism.
And the problem is that I am not sure of operation’s order…

And 1-ramp is nom[4] texture. Before I set the operand to GL_ONE_MINUS_SRC_COLOR using the ramp in the 2nd pass but I had a strange problem in another part of my program…when I want to modulate an other texture ( of graphic interface ) with a ramp. In fact when multitexturing is active the ramp that is modulate with interface texture is very dark, whereas when the multitexturing is not active the drakness of this ramp is normal…
It is very strange because there is no link with this texture and the other that are used by terrain…
In short, I am not sure that you will understand me in this last paragraph because it is difficult to explain this…

No now there is no problem any more, in fact I had forgotten an operand when I modulate interface’s texture and the ramp.

you can add mask data to a alpha value of texture.