problem with per fragment lighting (pictures inside) (problem not resolved)

This topic is 4945 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, My loader seems to work without the shaders. The per fragment shader works perfectly under renderMonkey. But when i activate this shader the model isn't lighted... i just can see the material's color and this shader works for one of my models but not with the others. I have had a similar problem before i have tought that it was an attenuation problem. I have changed the value of the quadratic factor (1.0, 0.00035,...) but i don't know what to use because nothing works (except for one model). Can you help me to choose the attenuation factor(s) ? or tell me if it comes from something else ? [Edited by - TheSeb on July 5, 2005 10:37:56 AM]

Share on other sites
The shader works for one model, but not another? That would suggest to me a problem with the model itself. Maybe the normals on that model are malformed? Are all of it's triangles front facing? Does it have the appropriate texture stages (normal, specular, whatever you need)? Basic stuff, but often times people can miss 'em.

Also, you said it works in Render Monkey, but were you testing it with a default (teapot or somthing) model, or your actual in game models? Also, Render Monkey takes care of a lot of state changes on it's own in the background (although it let's you tweak them quite a bit.) I would suggest making sure that the state settings in your engine match the Render Monkey settings as closely as possible.

Share on other sites
in fact, it looks that that there are two problem :
1)Attenuation is not correct for some models
2)my lighting is correct(when attenuation is correct too) only for the part of the object which is firstly lighted by the light. But when i turn the model on itself, the parts which were hidden are either not lighted or lighted incorrectly.
Do you see what i mean ? and do have an idea ?

Share on other sites
i have swapped the y and z normals coordinates and the part which wasn't lighted is lighted now, except for the sides of the model which i display(the lighting is stange).
The orientation of the faces are apparently the same, therefore i don't understand why it works for some parts of the mesh and not with the others.
if i multiply the normals of this mesh with the transformation matrix i have the same results (in this case).
i'm a little lost so if you can help me, i would be glad

Share on other sites
Quote:
 my lighting is correct(when attenuation is correct too) only for the part of the object which is firstly lighted by the light. But when i turn the model on itself, the parts which were hidden are either not lighted or lighted incorrectly.

This suggests to me that you may not be rotating yourn normals properly, or may not be calculating them correctly in the first place.

It would be very helpful to have screenshots of the issue or a simple demo to show what's wrong.

Share on other sites
Since Seb doesn't have a web host, I'll host these for him till he can get this sorted out:

(Linked due to size - 1024x768)

Pic 1
Pic 2

I'll take a closer look later and see what suggestions I have, but for now I'm off to work!

Share on other sites
after u set up the camera eg glulookat(..) then reposition the light , get it working first with a directional light (ie dont worry about attenuation)

Share on other sites
see here http://www.opengl.org/resources/faq/technical/lights.htm
hmm just see at the top "The per fragment shader works perfectly under renderMonkey" u mean this is a shader + not gl lighting in that case
r u doing bumpmapping?
my suggestion is do it first without bumpmapping

use this as the fragment shader

float diffuse_amount = dot( vec3(0,0,1), normal ) );
gl_FragColor = vec4(diffuse_amount,diffuse_amount,diffuse_amount,1.0)

pass the normal from the vertex shader to the fragment shader, if it doesnt wotrk then youre normals are buggered

Share on other sites
(i'm not doing bump mapping, it's just per pixel lighting)

it's really a problem a normals (i have the same problem with your shader), but i don't understand, i don't manage to find the error (the code is not so complex) and i find strange that some parts are lighted correctly and not the others knowing that the computations are the same for all the vertices.
i put my code (it's long but a lot is simple) can you take a look at it and tell me if you find (or not) errors ?
file.read((char*) &(myObjects[counterObj].nbPoly), sizeof (unsigned short int));		for (polyCounter = 0 ; polyCounter< myObjects[counterObj].nbPoly ; polyCounter++)	{			file.read((char*) &(myObjects[counterObj].myIndices[polyCounter][0]), sizeof (unsigned short int));		file.read((char*) &(myObjects[counterObj].myIndices[polyCounter][1]), sizeof (unsigned short int));		file.read((char*) &(myObjects[counterObj].myIndices[polyCounter][2]), sizeof (unsigned short int));		file.read((char*) &(faceInfo), sizeof (short int));		cout<<"face info "<<faceInfo<<endl ;		oFile2<<"face info "<<faceInfo<<endl ;		int Va = myObjects[counterObj].myIndices[polyCounter][0] ;		int Vb = myObjects[counterObj].myIndices[polyCounter][1] ;		int Vc = myObjects[counterObj].myIndices[polyCounter][2] ;                                                                       		//on se sert de ab et ca pour le produit vectoriel, ça et le reste servent uniquement pour la normal weight		float Vab[] = {(myObjects[counterObj].myVertices[Vb][0] - myObjects[counterObj].myVertices[Va][0]),					(myObjects[counterObj].myVertices[Vb][1] - myObjects[counterObj].myVertices[Va][1]),					(myObjects[counterObj].myVertices[Vb][2] - myObjects[counterObj].myVertices[Va][2])};		float Vac[] = {(myObjects[counterObj].myVertices[Vc][0] - myObjects[counterObj].myVertices[Va][0]),					(myObjects[counterObj].myVertices[Vc][1] - myObjects[counterObj].myVertices[Va][1]),					(myObjects[counterObj].myVertices[Vc][2] - myObjects[counterObj].myVertices[Va][2])};				float Vba[] = {(myObjects[counterObj].myVertices[Va][0] - myObjects[counterObj].myVertices[Vb][0]),					(myObjects[counterObj].myVertices[Va][1] - myObjects[counterObj].myVertices[Vb][1]),					(myObjects[counterObj].myVertices[Va][2] - myObjects[counterObj].myVertices[Vb][2])};		float Vbc[] = {(myObjects[counterObj].myVertices[Vc][0] - myObjects[counterObj].myVertices[Vb][0]),					(myObjects[counterObj].myVertices[Vc][1] - myObjects[counterObj].myVertices[Vb][1]),					(myObjects[counterObj].myVertices[Vc][2] - myObjects[counterObj].myVertices[Vb][2])};		float Vca[] = {(myObjects[counterObj].myVertices[Va][0] - myObjects[counterObj].myVertices[Vc][0]),					(myObjects[counterObj].myVertices[Va][1] - myObjects[counterObj].myVertices[Vc][1]),					(myObjects[counterObj].myVertices[Va][2] - myObjects[counterObj].myVertices[Vc][2])};		float Vcb[] = {(myObjects[counterObj].myVertices[Vb][0] - myObjects[counterObj].myVertices[Vc][0]),					(myObjects[counterObj].myVertices[Vb][1] - myObjects[counterObj].myVertices[Vc][1]),					(myObjects[counterObj].myVertices[Vb][2] - myObjects[counterObj].myVertices[Vc][2])};				switch (faceInfo)		{			case 0x3 :crossProduct(&myObjects[counterObj].perFaceNormals[polyCounter], Vac, Vbc) ;				      break ;			case 0x7 :crossProduct(&myObjects[counterObj].perFaceNormals[polyCounter], Vab, Vbc) ;				      break ;			case 0x6 :crossProduct(&myObjects[counterObj].perFaceNormals[polyCounter], Vab, Vbc) ;				      break ;			case 0x5 :crossProduct(&myObjects[counterObj].perFaceNormals[polyCounter], Vac, Vab) ;				      break ;			case 0x4 :crossProduct(&myObjects[counterObj].perFaceNormals[polyCounter], Vab, Vcb) ;				      break ;			case 0x2 :crossProduct(&myObjects[counterObj].perFaceNormals[polyCounter], Vca, Vbc) ;				      break ;			case 0x1 :crossProduct(&myObjects[counterObj].perFaceNormals[polyCounter], Vac, Vcb) ;				      break ;			case 0x0 :crossProduct(&myObjects[counterObj].perFaceNormals[polyCounter], Vba, Vcb) ;				      break ;		}		normalize(&myObjects[counterObj].perFaceNormals[polyCounter]) ;							}//fin de la boucle for		cout<<"face info "<<hex<<faceInfo<<endl ;		for (polyCounter = 0 ; polyCounter< myObjects[counterObj].nbVertices ; polyCounter++)	{		myObjects[counterObj].perVertexNormals[polyCounter][0] = 0 ;		myObjects[counterObj].perVertexNormals[polyCounter][1] = 0 ;		myObjects[counterObj].perVertexNormals[polyCounter][2] = 0 ;	}			for(nIndice=0 ; nIndice < myObjects[counterObj].nbVertices ; nIndice++)	{		for(i=0 ; i < myObjects[counterObj].nbPoly ; i++)		{			for(j=0 ; j< 3; j++)			{				if(myObjects[counterObj].myIndices[j]==nIndice)				{					myObjects[counterObj].perVertexNormals[nIndice][0] += myObjects[counterObj].perFaceNormals.x/**angle[j]*/ ;					myObjects[counterObj].perVertexNormals[nIndice][1] += myObjects[counterObj].perFaceNormals.y/**angle[j]*/ ;					myObjects[counterObj].perVertexNormals[nIndice][2] += myObjects[counterObj].perFaceNormals.z/**angle[j]*/ ;					myObjects[counterObj].nbFace[nIndice]++ ;				}			}		}	}		/*multiplyMatrixVertices(myObjects[counterObj].localAxisMatrix, 				   &myObjects[counterObj].myVertices[0][0], 				   &myObjects[counterObj].nbVertices) ;*/	multiplyMatrixNormals(myObjects[counterObj].localAxisMatrix, 				   &myObjects[counterObj].perVertexNormals[0][0], 				   &myObjects[counterObj].nbVertices) ;		float tempSwap, tempSwap2 ;	for(counter=0 ; counter < myObjects[counterObj].nbVertices ; counter++)	{		tempSwap = myObjects[counterObj].myVertices[counter][1] ;		myObjects[counterObj].myVertices[counter][1]= myObjects[counterObj].myVertices[counter][2] ;		myObjects[counterObj].myVertices[counter][2]= -tempSwap ;		tempSwap2 = myObjects[counterObj].perVertexNormals[counter][1] ;		myObjects[counterObj].perVertexNormals[counter][1]= myObjects[counterObj].perVertexNormals[counter][2] ;		myObjects[counterObj].perVertexNormals[counter][2]= -tempSwap2 ;	}//average	for(counter=0 ; counter < myObjects[counterObj].nbVertices ; counter++)	{		myObjects[counterObj].perVertexNormals[counter][0] /= myObjects[counterObj].nbFace[counter] ;		myObjects[counterObj].perVertexNormals[counter][1] /= myObjects[counterObj].nbFace[counter] ;		myObjects[counterObj].perVertexNormals[counter][2] /= myObjects[counterObj].nbFace[counter] ;	}	cout.flush() ;

up ! :-o

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 9
• 15
• 14
• Forum Statistics

• Total Topics
634071
• Total Posts
3015336
×