Jump to content
  • Advertisement
Sign in to follow this  
wakingjohn

Terrain Details and Alpha Masks

This topic is 4955 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

Hey, This is how I would like my engine set up: I have one big texture for the base terrain. On top of this I would like to gl_modulate tiled textures (such as grass, rocks etc.) There can be any number of these dependant on the level. However I need those to be alpha mapped. The alpha maps are in a seperate files as black and white textures and can not be combined with the textures due to my caching and file system. So I need a way to draw the terrain, add the details of (for example) grass with consideration to their alpha map, add the details on top of that of (for example) rocks again in consideration to their seperate alpha map etc. Altering my caching or file system is undoable. Could someone please explain to me how to do this ? Any code examples would be appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Actually, If there was a way to just copy the rgb layer of one texture (already binded) to the alpha of another (also binded) that would work too.

Like t1.alpha[index] =[t2[index].r + t2[index].g + t3[index.b]/3

I'm not very knowledgable in opengl yet, so if that doesnt make sense... sorry.

Share this post


Link to post
Share on other sites
Quote:
Original post by wakingjohn
The alpha maps are in a seperate files as black and white textures and can not be combined with the textures due to my caching and file system.


Definately, the best solution would be combining images with their alpha maps from the level of OpenGL. If there is a possibility in your app to read pixel data from each bitmap - that's all what you need. You can do the following thing :

1) Read image pixel data
2) Read alpha mask pixel data
3) Allocate a memory for the new image with alpha chanell
4) For every element of an array created in 3) copy RGB values
from image 1) and use data from 2) to calculate alpha

Then you can simply create a 32BPP texture using freshly created data from 4).

Hope it makes sense ;)

Share this post


Link to post
Share on other sites
Ok, I've gotten a little further with help from another old thread on this site:



bind(textures[base]); //my binding/cacheing function
glDrawElements( GL_TRIANGLES, 16*16*6, GL_UNSIGNED_SHORT, array );

//draw the b&w texture to the alpha
glDisable(GL_BLEND);
glColorMask(0, 0, 0, 1);
glEnable(GL_TEXTURE_2D);
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
bind(textures[alpha]);
glDrawElements( GL_TRIANGLES, 16*16*6, GL_UNSIGNED_SHORT, array );

//draw the texture
glColorMask(1,1,1,0);
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
glEnable(GL_BLEND);

// Render only to areas where any color (r, g, or b) is greater that zero in the
glBlendFunc( GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA );

bind(textures[detail]); //my bind function for cacheing etc
glDrawElements( GL_TRIANGLES, 16*16*6, GL_UNSIGNED_SHORT, array )

glDisable(GL_BLEND);



But it still doesnt do what I think it should ... hmmm

Anybody spot the problem?

Share this post


Link to post
Share on other sites
Quote:
Original post by clapton
Quote:
Original post by wakingjohn
The alpha maps are in a seperate files as black and white textures and can not be combined with the textures due to my caching and file system.


Definately, the best solution would be combining images with their alpha maps from the level of OpenGL. If there is a possibility in your app to read pixel data from each bitmap - that's all what you need. You can do the following thing :

1) Read image pixel data
2) Read alpha mask pixel data
3) Allocate a memory for the new image with alpha chanell
4) For every element of an array created in 3) copy RGB values
from image 1) and use data from 2) to calculate alpha

Then you can simply create a 32BPP texture using freshly created data from 4).

Hope it makes sense ;)


Yeah.

Well, I'm really clueless on how to do that. How do I extract RGB values from data thats ready to be passed to glBindTexture or glGenTexture ? Is the value passed just an unsigned char array ?

(Thanks a bunch for your time btw)

Share this post


Link to post
Share on other sites
Quote:
Original post by clapton
Quote:
Original post by wakingjohn
The alpha maps are in a seperate files as black and white textures and can not be combined with the textures due to my caching and file system.


Definately, the best solution would be combining images with their alpha maps from the level of OpenGL. If there is a possibility in your app to read pixel data from each bitmap - that's all what you need. You can do the following thing :

1) Read image pixel data
2) Read alpha mask pixel data
3) Allocate a memory for the new image with alpha chanell
4) For every element of an array created in 3) copy RGB values
from image 1) and use data from 2) to calculate alpha

Then you can simply create a 32BPP texture using freshly created data from 4).

Hope it makes sense ;)


Hmm, Tried this to very little success.

Theres gotta be some multitexturing solution orblending solution? Please say yes... =-)

Share this post


Link to post
Share on other sites
depends on what card youve got, with glsl the effect u wanna achieeve is very easy, ie u need to specify what u want this run on

Share this post


Link to post
Share on other sites
Thats a good question.

I'm working on a map editor for a game and this will be an extra option.

So...

As many as possible while still being able to do it.

Specifically though I would like to see the ATI Radeon work as the game has a fair mac following and alot of macs these days ship standard with that.


Also upon relooking at stuff its actually GL_COMBINE I wish to acheive (though knowing both would be helpful as I'm still trying to pick up on ogl).

Thanks TONS
-John

Share this post


Link to post
Share on other sites
Ok, I did a little something else, and tried to interpolate


glActiveTextureARB( GL_TEXTURE0_ARB );//base
glEnable(GL_TEXTURE_2D);
BindTexture( base );//returns the texture number
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_RGB_EXT);
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE);

glActiveTextureARB( GL_TEXTURE1_ARB );//alpha
BindTexture( detailmask );

glActiveTextureARB( GL_TEXTURE2_ARB );//detail
BindTexture(detail );
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_ARB,GL_INTERPOLATE_ARB);
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_TEXTURE2);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB_ARB,GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE2_RGB_ARB,GL_TEXTURE1);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND2_RGB_ARB,GL_SRC_COLOR);








When i do this i get a the base. =-/

EDIT: Note also now that the alpha texture is a one channel GL_LUMINANCE

[Edited by - wakingjohn on November 29, 2004 3:19:32 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!