[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

OpenGL Multipass Rendering



Hey people,



	Long time since someone last posted here :) Well, I'm having some
trouble with multipass rendering using OpenGL. Here's the situation:
	I'm doing three passes: first is diffuse texture + diffuse lighting,
second is specular highlight + gloss map and third is emissive texture.
In OpenGL it's something like this (some redundant calls are made for
sake of clarity):

// Diffuse pass
glDepthFunc(GL_LESS);
glEnable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBindTexture(GL_TEXTURE_2D, diffuse_texture);
// Note: the diffuse texture is of internal format GL_RGB //
RenderObject();

// Specular pass
glDepthFunc(GL_EQUAL);
glEnable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBindTexture(GL_TEXTURE_2D, gloss_texture);
// Note: the gloss texture is of internal format GL_ALPHA //
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
RenderObject();

// Emissive pass
glDepthFunc(GL_EQUAL);
glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBindTexture(GL_TEXTURE_2D), emissive_texture);
// Note: the emissive texture is of internal format GL_RGBA //
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
RenderObject();


	Ok, so I think I got this right :) So this works just fine using Linux
(with an ATI Rage Fury Pro). Now here comes the problem: this does not
work in all machines I tested on (Linux and Windows)! Let's take it
slow. For now, let us ommit the emissive pass. The gloss mapping doesn't
work. The specular highlight works fine, but it's not attenuated by the
gloss map. I had also tryed previously some passes using GL_DST_ALPHA
for the gloss mapping, but it also didn't work on every machine (but
GL_DST_ALPHA is not mandatory in OpenGL implementations).
	I solved the problem for the gloss mapping by using this:

// Specular pass
...
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBindTexture(GL_TEXTURE_2D, gloss_texture);
// Gloss texture (just an alpha channel) now in internal format
GL_LUMINANCE //
...
glBlendFunc(GL_ONE, GL_ONE);
RenderObject();

	I'm still having problems with the emissive pass. Nothing that uses
GL_SRC_ALPHA seems to work on every machine. As a matter of fact, this
seems all to much related with the alpha channel in some way. Any
pointers on this one? (Sorry about the extensive msg)





Many thanks,
M.