Jump to content
  • Advertisement
Sign in to follow this  
Infinite_Daremo

Flickering lights when animating models - Resolved

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

For some reason when i animate my models lights seem to flicker. There is only 2 lights active in the scene a static source light and a dynamic spotlight but im not sure theyre the issue. Heres a video, the light blue coloured blob is the dynamic spotlight i randomly created its not the problem, the problem is what seems to look like lightning flashes:
Any ideas what could be causing this? Ill provide code if needed. [Edited by - Infinite_Daremo on July 2, 2008 4:28:55 PM]

Share this post


Link to post
Share on other sites
Advertisement
I think it's a hidden out-of-array-bounds error. Somewhere in your skinning (animation) code, you write to memory-space, that belongs to the lights' info variables.
Try to put some debugging code at places, where you access arrays - code, that checks what index for the array-access you'll be using.

Share this post


Link to post
Share on other sites
Im gonna debug now, ill post the code here for now incase theres a more obvious error:

void CBaseModel::doRender(float posX, float posY, float posZ, int frameNum)
{
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);

CVector *pointList = 0;
CVector tempVec0, tempVec1, tempVec2, normal;

pointList = &m_pModelData->pointList[ m_pModelData->numPoints * frameNum ]; // Pointer to current frame

glBindTexture( GL_TEXTURE_2D, m_pModelData->modelTex->texID );

// Render model
glBegin(GL_TRIANGLES);
for( int i = 0; i < m_pModelData->numTriangles; i++ )
{
normal = UTILITY.calculateNormal( &pointList[ m_pModelData->triIndex.meshIndex[0]], &pointList[ m_pModelData->triIndex.meshIndex[1]], &pointList[ m_pModelData->triIndex.meshIndex[2]] );
glNormal3f( normal.x, normal.y, normal.z );

// To avoid constant dereferencing
tempVec0 = pointList[ m_pModelData->triIndex.meshIndex[0]];
tempVec1 = pointList[ m_pModelData->triIndex.meshIndex[1]];
tempVec2 = pointList[ m_pModelData->triIndex.meshIndex[2]];

glTexCoord2f( m_pModelData->st[ m_pModelData->triIndex.stIndex[0]].s, m_pModelData->st[ m_pModelData->triIndex.stIndex[0]].t );
glVertex3f( tempVec0.x, tempVec0.y, tempVec0.z);

glTexCoord2f( m_pModelData->st[ m_pModelData->triIndex.stIndex[1]].s, m_pModelData->st[ m_pModelData->triIndex.stIndex[1]].t );
glVertex3f( tempVec1.x, tempVec1.y, tempVec1.z);

glTexCoord2f( m_pModelData->st[ m_pModelData->triIndex.stIndex[2]].s, m_pModelData->st[ m_pModelData->triIndex.stIndex[2]].t );
glVertex3f( tempVec2.x, tempVec2.y, tempVec2.z);
}
glEnd();
}

Share this post


Link to post
Share on other sites
In the vid it looks like the terrain is picking up too much shininess, a per frag shader (rather than what looks like standard vertex lighting) would eliminate the flashes.

Or you could lower the shininess, if of course that is the problem!

GLint materialShininess = 12; //try roughly in the range of 2 to 125
glMateriali( GL_FRONT, GL_SHININESS, materialShininess );

Share this post


Link to post
Share on other sites
I tried rendering without the terrain as i have not bothered calculating proper normals for it yet but the problem still persists.

Also debugging at the time of the lighting errors there is no out of bound reading. Everything seems to be fine.

Share this post


Link to post
Share on other sites
I cant believe i made such a dumb mistake. My normal calculation wasnt returning a reference so data it was returning was becoming jargon. All runs fine now. Thanks guys.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!