• Advertisement
Sign in to follow this  

Correct blending for multiple per pixel light sources

This topic is 4786 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, I have been trying to add multiple per pixel light sources, however, I have two problems and they are both blending related (well I think they are...). Note: The actual lights are working fine. Firstly, despite setting up two light sources it only draws the results of one (whichever I call first). Secondly, I do an additional pass to render the base textures by blending to combine the lights with the base texture but this doesn't work. Here's my code:

// First pass

	glEnable(GL_REGISTER_COMBINERS_NV);

	glEnable(GL_BLEND);
	glBlendFunc(GL_ONE, GL_ZERO);

	glActiveTextureARB(GL_TEXTURE0_ARB);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, 3);

	glActiveTextureARB(GL_TEXTURE1_ARB);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, 3);

	glBegin(GL_QUADS);

		// Light source 1

		ProcessVertex(-5.0f, 0, 5.0f, 1);
		ProcessVertex(-5.0f, 0, -5.0f, 1);
		ProcessVertex(-5.0f, 4, -5.0f, 1);
		ProcessVertex(-5.0f, 4, 5.0f, 1);

		... and the rest

		// Light source 2
	
		ProcessVertex(-5.0f, 0, 5.0f, 2);
		ProcessVertex(-5.0f, 0, -5.0f, 2);
		ProcessVertex(-5.0f, 4, -5.0f, 2);
		ProcessVertex(-5.0f, 4, 5.0f, 2);

		... and the rest

	glEnd();

	glActiveTextureARB(GL_TEXTURE0_ARB);
	glDisable(GL_TEXTURE_2D);

	glActiveTextureARB(GL_TEXTURE1_ARB);
	glDisable(GL_TEXTURE_2D);

	glDisable(GL_BLEND);
	
	glDisable(GL_REGISTER_COMBINERS_NV);

// Second pass

	glEnable(GL_BLEND);
	glBlendFunc(GL_DST_COLOR, GL_ZERO);

	glActiveTextureARB(GL_TEXTURE2_ARB);
	glBindTexture(GL_TEXTURE_2D, 5);
	glEnable(GL_TEXTURE_2D);

	glBegin(GL_QUADS);

		TextureVertex(-5.0f, 0, 5.0f, 0, 0);
		TextureVertex(-5.0f, 0,-5.0f, 1, 0);
		TextureVertex(-5.0f, 4,-5.0f, 1, 1);
		TextureVertex(-5.0f, 4, 5.0f, 0, 1);

		... and the rest

	glEnd();

	glActiveTextureARB(GL_TEXTURE2_ARB);
	glDisable(GL_TEXTURE_2D);

	glDisable(GL_BLEND);

Any ideas where i'm going wrong? Cheers!

Share this post


Link to post
Share on other sites
Advertisement
Quote:
I have two problems and they are both blending related (well I think they are...).

Not an answer as such, but this sounds like it could be an API-related issue rather than a theoretical problem. As such, maybe you'll get a better response by sticking this in with all the other OpenGL posts..?

hth
Jack

Share this post


Link to post
Share on other sites
You'll want to add each pass, so the blend func should likely be "GL_ONE, GL_ONE".

If it still draws only 1 pass, perhaps you have depth tests set to LESS rather than LESSEQUAL. Check for that.

Share this post


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

  • Advertisement