Archived

This topic is now archived and is closed to further replies.

Texture Map x Constant = Posible?

This topic is 5025 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all. Im trying to do one simple thing yet i dont seem to find my way in OpenGL. Ive got a multitexturing module working quite fine, and im using it to do some dynamic lightmaping; that is, using a ligthmap as a flashlight that moves around the enviroment. Works quite fine... BUT, i need to fade this light when i turn it on/off. I can see HOW this is done... its obvious that if i could multiply the result of the ligthmap modulation by a variable i could set up (say, ranged [0,1]) i would get this result. So basically the question is HOW can i multiply the resulting fragment after multitexturing (or even before, what ever) by a defined scale factor? I want something wich does exactly like: glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE, 2); but without the strange (to my surprise) limitation of this factor being 1,2 or 4. Thx in advance.

Share this post


Link to post
Share on other sites
In D3D there is something called TextureFactor, which you might want to try and find in GL.


--
MFC is sorta like the swedish police... It''''s full of crap, and nothing can communicate with anything else.

Share this post


Link to post
Share on other sites

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_CONSTANT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);

Multiplies the texture colour of the selected unit with its constant colour (and takes the alpha component directly from the texture without further processing).


[edited by - ALX on April 15, 2004 6:46:52 PM]

Share this post


Link to post
Share on other sites
You could throw together a simple pixel shader or use register combiners (NV only I think).

Check out these extensions(google):

ARB_texture_env_combine, NV_register_combiner, ARB_fragment_program

Share this post


Link to post
Share on other sites
ALX:

Thx for the reply, that does work ofcourse, but is very limiting... you se, im working (as many) in my own system (aka engine ), hence im aiming to flexibility. That way of doing what i need cuts my posibilities drasticly... as an example, i couldnt do this:

Modulate Texture0 with base color
Modulate Texture1 with previous fragment (for example, a lightmap)

I could of course use your way and set the combiner to madulate the first texture with the enviroment constant, but then i wouldnt be able to specifie a multiplyer for EVERY texture involved, just the first one.

I other words, it seems like i must choose to combine with the las fragment OR a scalar... and i want BOTH things.

Its so incredibly simple that i am amazed this does not exist in a straight forward maner in OpenGL.


Klajntib, i supose i could use a simple shader for this, but my sistem is not ready for shaders yet (im finishing the texture module and this is the last small hole to fill). Ive never looked at combiners, though i will... but that NV only warning doesnt sound very good to me.

Thanks again... and if anyone has a fast way of doing such a simple thing, please reply... (or if im missing something or saying something stupid)

Share this post


Link to post
Share on other sites
Well, texture_env_combine is very limited, of course. If you want more, and you want to stay vendor independent, then there is no way around a fragment shader. Limiting you to DX9 type cards (GeForce FX, Radeon 9200 and above).

Everything inbetween in vendor dependent. Register combiners (NV_register_combiner) are pretty good, and will do what you need. But they are nvidia only. You'll have to write a separate codepath for ATI (using ATI_fragment_shader, or ATI_texture_env_route).

quote:

Its so incredibly simple that i am amazed this does not exist in a straight forward maner in OpenGL.


It's generally not needed, because typically these kind of lighting issues are solved in a different way.


[edited by - ALX on April 15, 2004 7:34:10 PM]

Share this post


Link to post
Share on other sites
what about

glColor3f(Scale, Scale, Scale);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

or even

glColor4f(Whatever, Whatever, Whatever, Scale);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);


the glBlend way will multiply the final fragemnt by its alpha value before being written to the framebuffer.

the other one will pre-multiply the texture by Scale.

[edited by - waramp on April 15, 2004 10:12:10 PM]

Share this post


Link to post
Share on other sites