PDA

View Full Version : Why the heck... is the quad black? Please help!



BlackJack
04-14-2002, 05:22 AM
Ok, I've played today a bit with the lighting to don't light the polys myself anymore. I thought the easiest way to check, if the result looks like with my once software lighting would be to make a poly with a normal of 0,0,-1 and to let the light as well look into 0,0,-1. I thought if it would be inifinite directional the lighting of it should be so 100%, but in fact it's 0% =/. I set the ambient lighting to 0.3,0.3,0.3,1.0 and the diffuse lighting to 1.0,1.0,1.0,1.0. Emission is 0,0,0,1.0, Shininess is 0 and specular is 0,0,0,0... but the quad just gets the ambiental light, but is not a bit brightened by the diffusal, although the vectors are absolutely equal... why?! =/





glEnable(GL_LIGHT0);
float t[4] = {0.f, 0.f, -1.f, 0};
glLightfv(GL_LIGHT0,GL_POSITION,&t[0]);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);

C00Vector tempvec = Vec(0,0,-1.f);
glBegin(GL_QUADS);
glNormal3fv(&tempvec.mfX);
glTexCoord2f(0,0);
glVertex3f(-20,-20,-40);
glTexCoord2f(1,0);
glVertex3f(20,-20,-40);
glTexCoord2f(1,1);
glVertex3f(20,20,-40);
glTexCoord2f(0,1);
glVertex3f(-20,20,-40);
glEnd();


Ah yes, something else, which meight be of importance: Because this didn't work I tried to let the normal vector of the polygon rotate and for a short time the quad got lighted then, BUT the left and right side of the quad were lighted uneven intensive... as if there would still be any distance test done.... =/

Thanks for the help,

Michael

[This message has been edited by BlackJack (edited 04-14-2002).]

NordFenris
04-14-2002, 06:29 AM
One thing I can think of is that you've set up your face culling incorrectly, since you get your strange lighting using two-sided lighting... Other than that, I cannot see anything wrong.

BlackJack
04-14-2002, 08:37 AM
No, the culling is set correctly, also the culling wouldn't raise such an effect. As said... w-component of the lightposition is zero, so by documentation it should be take as directional light and the vertex coordinates shouldn't affect the lighting, but they do... and they do heavily. And why the polygon isn't lighted a bit through diffusional although the lightdirection and the 4 normal vectors of the vertices are 100% equal I absolutely don't understand anymore =/.

Michael

jwatte
04-14-2002, 08:50 AM
Some things to think about:

Why are your light position and normal Z components negative? OpenGL is typically right-handed.

Have you enabled LIGHTING?

What are the material and light properties for DIFFUSE and AMBIENT?

I'm assuming the modelview is identity; else the light will be transformed when you set it. (this bites a lot of people, including me :-)

BlackJack
04-14-2002, 09:09 AM
void C09AphInterfaceGL::AphBeginFrame(bool clearcolor)
/*
<================================================== ===========================>
DESCRIPTION:
Prepares everything to start drawing. Calculates the view frustum.

HISTORY:
December 2001 - Implemented by MI.
<================================================== ===========================>
*/
{
//------------------------- SELECT HANDLE -------------------------
//wglMakeCurrent(WinDC,RC);
//------------------------- LOAD BASEMATRIX -------------------------
glLoadIdentity();
//------------------------- BACK IT UP -------------------------
glPushMatrix();
//------------------------- SET CLEARCOLOR TO BLACK -------------------------
glClearColor(0,0,0,1);
//------------------------- CLEAR Z AND IF WANTED ALSO COLORBUFFER -------------------------
glClear((clearcolor*GL_COLOR_BUFFER_BIT) | GL_DEPTH_BUFFER_BIT);
//------------------------- SET MATRIX-MODE -------------------------
glMatrixMode(GL_MODELVIEW);
//------------------------- SET DISPLAYREGION IN COLORBUFFER -------------------------
glViewport(0,0,mdwClientWidth,mdwClientHeight);
//------------------------- ENABLE DEPTHTEST -------------------------
glEnable(GL_DEPTH_TEST);
//------------------------- CALCULATE AND SET FRUSTUM -------------------------
mfFrTop = mfClipNear*(float)tan((mfAugYAngle/2.f)*(pi/180.f));
mfFrRight = mfFrTop*(mfAugXAngle/mfAugYAngle);
mfFrBottom = -mfFrTop;
mfFrLeft = -mfFrRight;
glFrustum(mfFrLeft,mfFrRight,mfFrBottom,mfFrTop,mf ClipNear,mfClipFar);
};

int C09AphInterfaceGL::AphSelectMaterial(C09AphMateria l *material)
/*
<================================================== ===========================>
DESCRIPTION:
Selects a material, does the selection of textures, loads the needed scripts,
sets the material lighting properties and so on.

HISTORY:
31.03.02 - Implemented by MI
<================================================== ===========================>
*/
{
int i;

//do texture settings
for(i=0; i<4; i++)
{
if(mdwActTextures[i]!=material->mTextures[i].mdwTexture)
{
AphSetTexSlot(i);
AphSelectTexture(material->mTextures[i].mdwTexture);
};
AphSetBlendMode(i,material->mTextures[i].BlendMode);
};

//if ambient = 255, the object is totally self lighting and the lighting will be disabled
if(material->mcAmbient.mc[3]==255)
{
if(mdwActualFlags&amp;afLighting)
AphSetFlags(mdwActualFlags-afLighting);
}
else
{
if(!(mdwActualFlags&amp;afLighting))
AphSetFlags(mdwActualFlags|afLighting);

float t[4];
int i;

//ambient
for(i=0;i<4;i++)
t[i]=(material->mcAmbient.mc[i]-((i==3)*127))/(128.0*(1+(i!=3)));
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,t);

//diffuse
for(i=0;i<4;i++)
t[i]=(material->mcDiffuse.mc[i]-((i==3)*127))/(128.0*(1+(i!=3)));
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,t);

//specular
for(i=0;i<4;i++)
t[i]=(material->mcSpecular.mc[i]-((i==3)*127))/(128.0*(1+(i!=3)));
glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,t);

//emission
for(i=0;i<4;i++)
t[i]=(material->mcEmission.mc[i]-((i==3)*127))/(128.0*(1+(i!=3)));
glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,t);

//shininess
t[0]=(material->mucShininess)/512;
glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,t[0]);

};

return 0;
};


The light is enabled for sure and I also didn't change the observers or objects position, there's not any single translate or rotate call before the light is set, also not after. To be exactly, here the properties the material is set with:

Ambient : 0.31,0.31,0.31,0.992
Diffuse : 0.99,0.99,0.99,1.0
Specular : 0,0,0,0
Emission : 0,0,0,1
Shininess : 0

Well, if I shouldn't find it out myself or with help from here within the next days, I'll post here a little demo about it... mysterious....

Michael

[This message has been edited by BlackJack (edited 04-14-2002).]