Transparent Texture Maps
If this is posted before, I apologize and if you could post a link, it would be greatly appreciated…
OK…My OpenGL experience is say moderate and I am now diving into more advanced techniques. Now I am trying to render a model of the planet Saturn. I have the model created, I know it a sphere how hard could it be, and the rings, and again a disc I know easy. Actually, I have the whole solar system with skybox, lighting, shading, realistic orbits, sizes and distances so now its time to add a little realism. Transparent rings, atmospheres and glow effects.
I have created a smaller scale sample program for testing just this purpose. I have the model rendered and shaded, textured with a surface and a ring texture. The textures are from planet pixel emporium to give credit to the texture creator. Also on the site is a transparency map for the ring. It is an 8-bit transparency map. I would like to apply the transparency map to the rings that are rendered. One to give a more realistic look and two to see the planet behind the rings at certain angles.
I have heard of this technique called 8-bit alpha channel but am still not sure if that is the case. From what I gather, it is really noting more than setting up the alpha blend method, disabling the depth buffer and rendering polygons. I have the red book and super bible but nothing stands out. Anyone have a code snippet or lead to an area that may shed some light?
Thanks…
The easiest thing for you to do would be to take the 24-bit colour map you are using as the ring texture into Photoshop (or other suitable imaging software) and then add the 8-bit alpha image as the Alpha Channel.
Either that, or bind the alpha channel texture and in a shader simply calculate the colour based on that alpha texture.
Either that, or bind the alpha channel texture and in a shader simply calculate the colour based on that alpha texture.
I was afraid of that...
I was looking into texture combiners. Is this something I can do say load ring texture into TEXTURE0 and alpha into TEXTURE1 and somehow with these glTexEnv* commands combine the RGB of TEXTURE0 and A of TEXTURE1 then apply that to the filter chain?
BTW...A point to a good tut or texture alpha blending would be appreciated. I am making progress but it is slow going.
Thanks...
I was looking into texture combiners. Is this something I can do say load ring texture into TEXTURE0 and alpha into TEXTURE1 and somehow with these glTexEnv* commands combine the RGB of TEXTURE0 and A of TEXTURE1 then apply that to the filter chain?
BTW...A point to a good tut or texture alpha blending would be appreciated. I am making progress but it is slow going.
Thanks...
Well progress...I made a png with alpha channel and have been able to get parts of the transparency to work. Next question is, it seems the alpha map is not taking into consideration all the levels. It seems to only be filtering out only the highest levels. Since I am new at this not sure what blending and alpha functions to use. Any suggestions?
Code section showing blend and alpha code/comments...
.
.
.
.
.
.
Code section showing blend and alpha code/comments...
.
.
.
for(uint j = 0; j < segment->face_count; j++) { surface_t* surface = &surfaces[face->surface]; if(surface != current_surface) { glMaterialfv(GL_FRONT, GL_AMBIENT, surface->ambient); glMaterialfv(GL_FRONT, GL_EMISSION, surface->emissive); glMaterialfv(GL_FRONT, GL_DIFFUSE, surface->diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, surface->specular); glMaterialf(GL_FRONT, GL_SHININESS, surface->reflectivity); //glActiveTexture(GL_TEXTURE0); set_gl_texture(surface->main_texture); //glDisable(GL_ALPHA); glDisable(GL_BLEND); if(i == 1) { // No alpha map (Temporary until I find a better way to trigger blending in the model) //if(surface->alpha_texture[0] != 0) { // No alpha map //glEnable(GL_ALPHA_TEST); //glEnable(GL_ALPHA); glEnable(GL_BLEND); //glAlphaFunc(GL_SRC_ALPHA, 0.2); glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } current_surface = surface; } face_vertex_t* fvert = (face_vertex_t*)&face->fvert_data; glBegin(GL_TRIANGLES); for(uint k = 0; k < face->count; k++) { glNormal3fv((float*)&fvert[k].normal); glTexCoord2fv((float*)&fvert[k].texel); glVertex3fv((float*)&vertexes[fvert[k].index]); } glEnd(); face = (face_t*)((uint)face + face->length); }
.
.
.
Where's the code where you load your textures? You should have this code in it:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture[0].width, texture[0].height, 0, GL_RGBA, GL_UNSIGNED_BYTE, *pointer);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture[0].width, texture[0].height, 0, GL_RGBA, GL_UNSIGNED_BYTE, *pointer);
Unless you've got a very odd effect in mind, you probably want glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) instead of your current blend func.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement