PDA

View Full Version : multitexturing+alpha channel



IronRaph
06-22-2002, 04:24 AM
Hi I want to know if it is possible to do something like this with multitexturing

-superpose 1 grass texture + 1 snow texture but I want to change the transparency of one of these texture in order tomake some transitions like grass to snow so I can I define the alpha channel (for one texture) of each vertex of a triangle in order to make this ... thanks (it works fine with 2 pass but it is too slow)

Bob
06-22-2002, 05:44 AM
With the alpha channel in the primary color, it is possible to to it in one pass with two texture units, using the extension ARB_texture_env_combine or OpenGL 1.3 (or maybe even 1.2, not sure).

You should set up the texture units something like this.

Texture unit 0:
GL_COMBINE_RGB = GL_REPLACE
GL_SOURCE0_RGB = GL_TEXTURE

Texture unit 1:
GL_COMBINE_RGB = GL_INTERPOLATE
GL_SOURCE0_RGB = GL_PREVIOUS
GL_SOURCE1_RGB = GL_TEXTURE
GL_SOURCE2_RGB = GL_PRIMARY_COLOR
GL_OPERAND2_RGB = GL_SRC_ALPHA

The alpha channel of the primary oclor will now control the amount of the two textures are applied to the final fragment color. Alpha = 0 will give you full color from the texture on unit 1, and alpha = 1 full color from texture 0.

IronRaph
06-22-2002, 06:35 AM
ok thanks I try it http://www.opengl.org/discussion_boards/ubb/smile.gif

IronRaph
06-22-2002, 06:38 AM
thanks !!! it works very fine !!!!! thanks http://www.opengl.org/discussion_boards/ubb/smile.gif
but can I also modulate the color of the 2 textures ?(for shadow) thanks
and can I for example do something like this with mulit texturing:
glColor4f( for the 0 unit texture)
glColor4f( for the 1 unit texture)
on each vertex so I can change the color of each texture on each vertex is it possible ?? I think now but I hope ...


[This message has been edited by IronRaph (edited 06-22-2002).]

Bob
06-22-2002, 08:45 AM
To modulate with the primary color, I think you need a third texture unit (altough you won't use an actual texture, but just to modulate with the primary color) if you want to use ARB_texture_env_combine.

Maybe you can do it with NV_texture_env_combine4 and/or NV_register_combiner (assuming NVIDIA hardware), but not sure. Not very familliar with those extensions yet.

You cannot set color per texture unit. There's only one primary color for a vertex.

IronRaph
06-22-2002, 09:07 AM
ok thanks snif ... http://www.opengl.org/discussion_boards/ubb/frown.gif

IronRaph
06-22-2002, 10:10 AM
and what is faster drawing 20 000 triangles witout lightning or drawing 10 000 triangles with lightning ?
and does the lightning work with multi texturing ? thanks

Bob
06-22-2002, 10:26 AM
For a question like "which is faster, A or B", there's only one answer: Try it out yourself. You haven't said anything about what system you have, and even if you do, there are SO many factors affecting performance.

Multitexturing and lighting are two independent operations. Lighting operates per vertex, and is completed before multitexturing comes into the picture. Lighting with multitexture can "work" in so many different ways. How you want it to work, I don't know, cause you didn't say. Since they are two independent operations, chances are pretty large they can be setup to give you what you want.

IronRaph
06-22-2002, 12:30 PM
ok thanks (I don't know the architecture of open gl http://www.opengl.org/discussion_boards/ubb/frown.gif)

IronRaph
06-25-2002, 02:11 PM
I have a problem with light.
my omini light don't affect the 2nd texture
how can I solve this porbleme ? thanks

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, texture[0]);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, GL_CONSTANT_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT, GL_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_EXT, GL_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 1.0f);
glTexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, 1.0f);

//texture 1
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, texture[1]);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_INTERPOLATE_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, GL_PRIMARY_COLOR_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT, GL_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_EXT, GL_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 1.0f);
glTexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, 1.0f);

and I want to specifiy with the vertex glColor just the alpha channel to the 1 unit texture and the 0 unit take the RGB value

every thing work but the ligning no ! http://www.opengl.org/discussion_boards/ubb/frown.gif

[This message has been edited by IronRaph (edited 06-25-2002).]

IronRaph
06-26-2002, 01:15 AM
and what is :
glSecondaryColor3fEXT(.5,.5,.5);

is this fonction avaliable on every 3D cards ?

Mazy
06-26-2002, 02:45 AM
it's an EXT, and therefor possibly not supported by all cards. but that color cant be used in the combiners, it only adds last in the pipe (after texturing) and was mainly for specular highlight over texture for own light calcs (where the separate speular extention did fit)

IronRaph
06-26-2002, 02:59 AM
my problem is what I want to make a snow system in 2 pass it works but I want to do it in 1 pass using multitexturing
so I have a omni light for the mountain
and I have a detail texture (with a color for each vertex in order to have a grass color or earth color because my detail texture is in gray) and my seconde texture is a classique snow texture but the problem is that light don't affect the snow texture but I don't know how I can do this ...
thanks

IronRaph
06-27-2002, 04:13 AM
and how can you explain that :
GL_QUAD_STRIP is faster than:
GL_TRINAGLE_STRIP
(I do exactly the same things)
and I have a tnt2 M64