Jump to content
  • Advertisement
Sign in to follow this  
Hydrael

OpenGL Multipass Rendering [Resolved]

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

Hello everyone, I've recently implemented a per-pixel lighting shader (written in glsl) within my engine. I'm doing multiple passes per active light (up to 8). Everything works fine, except that I don't know, how to properly combine the results from each pass, for the final, fully illuminated image. It seems like, I'm missing something to tell OpenGL, that the results from each pass should be added together, and not overwritten (that's whats happening). Here is the the main piece of code for the rendering loop:
glEnable(GL_LIGHT0);
m_pPerPixelShader->Activate();
for(int i=0;i<m_iActiveLightCount;i++)
{
	ActivatePerPixelLight(i);
	RenderBruteForce();		
}							
m_pPerPixelShader->Deactivate();
glDisable(GL_LIGHT0);
This is the class, that sets up one light for each pass:
void CNGRenderer::ActivatePerPixelLight(int iLight)
{
	float fAmbient[4]={0.0f,0.0f,0.0f,1.0f};
	float fDiffuse[4];
	float fPos[4];
	float fConstAtt;
	float fQuadAtt;

	fDiffuse[0]=m_pActiveLights[iLight]->LightColor[0];
	fDiffuse[1]=m_pActiveLights[iLight]->LightColor[1];
	fDiffuse[2]=m_pActiveLights[iLight]->LightColor[2];
	fDiffuse[3]=1.0f;

	fPos[0]=m_pActiveLights[iLight]->LightPos[0];
	fPos[1]=m_pActiveLights[iLight]->LightPos[1];
	fPos[2]=m_pActiveLights[iLight]->LightPos[2];
	fPos[3]=1.0f;

	fConstAtt=1.0f/m_pActiveLights[iLight]->fAttenuationStart;
	fQuadAtt=1.0f/m_pActiveLights[iLight]->fAttenuationEnd;

	glLightfv(GL_LIGHT0,GL_DIFFUSE,fDiffuse);
	glLightfv(GL_LIGHT0,GL_AMBIENT,fAmbient);
	glLightfv(GL_LIGHT0,GL_POSITION,fPos);
	glLightf( GL_LIGHT0,GL_LINEAR_ATTENUATION,0);
	glLightf( GL_LIGHT0,GL_CONSTANT_ATTENUATION,fConstAtt);
	glLightf( GL_LIGHT0,GL_QUADRATIC_ATTENUATION,fQuadAtt);
}
Can anyone help? Thanks a lot in advance Chris [Edited by - Hydrael on May 8, 2006 10:59:07 AM]

Share this post


Link to post
Share on other sites
Advertisement
glBlendFunc(GL_ONE,GL_ONE);
glEnable(GL_BLEND);

for additive blending

the "material" color should be multiplied with the lighthing results

Share this post


Link to post
Share on other sites
Ok, I'm having transparency issues now. Here is a screenshot on what's happening:



Do I have to sort my objects back to front, or is there any other things I could do?

[Edited by - Hydrael on May 7, 2006 10:45:56 AM]

Share this post


Link to post
Share on other sites
I dont know coding much ..yet but it looks like the model hashidden polys. Did you model the stairs in a program like 3DSM or Blender? If so make sure you dont have any extra vertices where the light is rendering odd. It looks like it's trying to render an extra face behind the other. I hope I am making since.

Share this post


Link to post
Share on other sites
Unfortunatly it has to do with the blending, because when I render the scene with normal fixed pipeline lighting (single pass), it works and looks perfect.

In "per-pixel-mode" I render 1 to 8 (or less, if less lights) passes, each with no textures and additive blending enabled.
After that, I render the scene textured with blendmode (GL_ZERO, GL_SRC_COLOR) and lighting disabled, to create the final image.
Somewhere in between those steps, I create z-order issues, like seen in the screenshot :/

Edit: changed screenshot, so the difference can be seen

[Edited by - Hydrael on May 7, 2006 10:18:42 AM]

Share this post


Link to post
Share on other sites
Ok, I got it working now.
I had to implement another pass, with only writing to the Z-buffer (glColorMask(all false))

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!