Skip to main content
GameDev.net gamedev.net
🔒 Locked

Interpolating Between Textures...

Started by HellRaiZer Oct 18, 2003 at 2:00 PM 5 replies 400+ views
Original Post
HellRaiZer
HellRaiZer
[This is the second time posting this, because while i was submitting some changes the thread was screwed up, so i had to repost. I say this because 6 people had saw the previous post, and maybe someone was answering when i destroyed it.] Hi! I have a little question. Is it possible to interpolate between 2 textures with the equation: Result = Tex0 * time + Tex1 * (1.0 - time); using OpenGL (not manually). I''m currently working on a GeForce 256 (2 texture units), so i tried to find something relevant in nVidia''s site. I found a presentation on Register Combiners for GeForce 256, and they mention that the above equation is possible with two texture units. Their equation is: Result = A * B + C * D; My problem is, that i can''t figure out how to map A, B, C, D to Tex0, Tex1, time, 1.0 - time. More simple: How can i setup regcoms to get the result i want. Note that this is my first time playing with register combiners, so if you can explain things a little, i''d be glad! Thanks in advance. HellRaiZer PS. They mention an extension named GL_EXT_texenv_op, but it doesn''t appear in my extension list. Has it been merged to an other extension?
HellRaiZer
Ilici
Ilici
i do it in 2 passes:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor(..., time);

//render pass 1

glColor(..., 1 - time);

//render pass 2

This works fine but it does not interpolate the alpha channel.

I think you can use GL_ARB_texture_env_combine but i've tried it and after many attempts i couldn't get it working.


this is probably the way to use texture_env_combine:
(smth similar to this - i dont know how to setup each texture)

float color[4] = {time, time, time, time};
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
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_ONE_MINUS_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_CONSTANT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_COLOR);

and the same for alpha


[ My Site ]
'I wish life was not so short,' he thought. 'Languages take such a time, and so do all the things one wants to know about.' - J.R.R Tolkien
Founding member of "Un-Ban nes8bit and Jesper T" association (UNAJA) (to join put this in your sig)
/*ilici*/

[edited by - Ilici on October 18, 2003 3:13:08 PM]

[edited by - Ilici on October 18, 2003 3:15:10 PM]
HellRaiZer
HellRaiZer
Ilici thanks for the code.

I had thought of something similar.
My problem is that i don't know where the second texture comes in! This sounds stupid, isn't it?

Also if someone can explain how we get here from the equations, just to clear things a little, i'd like to hear it.

Thanks again for repling. I'll to see what i can get.

HellRaiZer

[edited by - HellRaiZer on October 18, 2003 3:29:02 PM]
HellRaiZer
_DarkWIng_
_DarkWIng_
bind Tex0 to texture unit 0 and Tex1 to texture unit 1. Then use following env_combine on unit 1.


float color[4] = {time, time, time, time};
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);

//Arg0 * (Arg2) + Arg1 * (1-Arg2)
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB);

// tex0
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);

// tex1
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);

// interpolation factor
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_CONSTANT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_COLOR);



You should never let your fears become the boundaries of your dreams.
You should never let your fears become the boundaries of your dreams.
Ilici
Ilici
quote:

My problem is that i don't know where the second texture comes in! This sounds stupid, isn't it?



That's exactly my problem

I'll try _DarkWing_'s code now...

The equasion is: Tex0.Color * (1 - c.Color) + Tex1.Color * c.Color
so load c in the texture env color and use the color of the fragments of the 2 textures. and the extnesion does the rest.


[ My Site ]
'I wish life was not so short,' he thought. 'Languages take such a time, and so do all the things one wants to know about.' - J.R.R Tolkien
Founding member of "Un-Ban nes8bit and Jesper T" association (UNAJA) (to join put this in your sig)
/*ilici*/

[edited by - Ilici on October 18, 2003 4:51:14 PM]

[edited by - Ilici on October 18, 2003 4:52:34 PM]
HellRaiZer
HellRaiZer
_DarkWing_ thanks for the explanation! I haven't tried it, but it seems reasonable, and i'll do so. Thanks.

What must the enviroment for tex0 be? By default, i set it to modulate. Is this correct?

HellRaiZer

[edited by - HellRaiZer on October 19, 2003 2:54:02 AM]
HellRaiZer
_DarkWIng_
_DarkWIng_
quote:
Original post by HellRaiZer
What must the enviroment for tex0 be? By default, i set it to modulate. Is this correct?


I think it should be GL_REPLACE (or GL_DECAL).



You should never let your fears become the boundaries of your dreams.
You should never let your fears become the boundaries of your dreams.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.