Jump to content
  • Advertisement
Sign in to follow this  
hellknight

Multitexturing for planet rendering

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

I am working in a project that requieres accurate rendering of planets. Some planets may have as many as 4 textures. Coloured Texture Normal Map Texture Night side texture Cloud texture The program will run in a card that has 4 texturing units, so I am hoping that it is possible to achieve all the effects without using shaders. For now I haven't implemented Normal Mapping, because it is only important for close ups (which is not vital right now), however I am having problems with night+cloud texturing. I am relativly new to multitexturing (had only used it for detail texturing using GL_ADD_SIGNED_EXT), so I know my logic is failing somewhere. After looking at the results I have to assume GL_PRIMARY_COLOR_EXT is not giving me what I expected (the lighting value for a pixel) in the third pass. I have a working version using glBlend, but it requires 2 passes, and therefore is a tad slower. Here is the relevant code:
// Earth texture (Unit 0)
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
// Cloud texture (Unit 1 or 2)
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT,  GL_PRIMARY_COLOR_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT,  GL_PREVIOUS_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT,  GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT,  GL_INTERPOLATE_EXT);
// Night texture (Unit 1 or 2)
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT,  GL_PREVIOUS_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT,  GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT,  GL_PRIMARY_COLOR_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT,  GL_INTERPOLATE_EXT);


Earth texture is loaded as GL_BGR Cloud texture is loaded as GL_LUMINANCE Night texture is loaded as GL_LUMINANCE I have tried rendering first the night texture, then the clouds, and the other way around. Here is a screenshot of the results I am getting: image Image hosted by Photobucket.com Thanks in advance for your time and help. [Edited by - hellknight on June 13, 2005 8:27:28 PM]

Share this post


Link to post
Share on other sites
Advertisement
Well I'm sure you did this, but you are binding the correct texture and also call glActiveTextureARB(texunit) before each of those texture parameter calls, right?

Also, when interpolating textures, the 3rd component needs to be the interpolating value. So set SOURCE2 to be the primary color.

Try doing this:


// Earth texture (Unit 0)
glActiveTextureARB(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, earthTexture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

// Cloud texture (Unit 1 or 2)
glActiveTextureARB(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, cloudTexture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_INTERPOLATE_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE1);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, GL_PRIMARY_COLOR_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_COLOR);

// Night texture (Unit 1 or 2)
glActiveTextureARB(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, nightTexture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_INTERPOLATE_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_PREVIOUS_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_TEXTURE2);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, GL_PRIMARY_COLOR_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_COLOR);

Share this post


Link to post
Share on other sites
Yep, all texture units are assigned and textures binds occur where they should.

I tried your suggestion and had no positive imporovement. Please take a look at the image I linked at my original post so you can see the results I am getting.

If I use the changes you suggested for the cloud texture settings, the result (for clouds alone) is incorrect, it obscures the areas that do not have clouds. I am aware of the 3rd component role in GL_INTERPOLATE_EXT

result=operand0(source0)*operand2(source2)+operand1(source1)*(1-operand2(source2))

Remeber this should look realistic, so clouds should be obscured at night, and night lights should only be visible at night.

Thanks anywayz. PLEEAAASEEEE somebody help me!!

PS: On a side note, I think there is something weird with your code, you suggested using glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE1); and glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE2); resepectivly, which according to my interpretation of glTexEnv man pages is an incorrect usage. You should only use GL_TEXTURE, and OpenGL will assign the value of the selected texture of the current texturing unit.

Share this post


Link to post
Share on other sites
Just so you know; after doing a flash update of my vid card and updating my drivers (I was running on a laptop with linux) everything works properly. Sadly I know don't know weather it was the driver update or the flash upgrade that fixed the problem. I think the problem was that only the first two texturing units were working/enabled for some reason.

To the admin: I suggest deleting this whole thread, as nothing new may be learnt from it (other than updating your drivers and flashing your vid card frequently).

Image hosted by Photobucket.com

Share this post


Link to post
Share on other sites
Quote:
Original post by hellknight
To the admin: I suggest deleting this whole thread, as nothing new may be learnt from it (other than updating your drivers and flashing your vid card frequently).


Well that is always a good point, and worth making sure every one learns. There are many times where I was about to go nuts from somthing not working only to find out later it was a driver issue.

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!