过多的镜面光opengl
Posted
技术标签:
【中文标题】过多的镜面光opengl【英文标题】:too much specular light opengl 【发布时间】:2014-04-06 11:37:38 【问题描述】:这些是我的漫反射、环境和镜面反射设置以及我的灯光位置。我的场景在镜面光下看起来非常明亮。我试过调整灯光的位置,但没有任何效果。 GLfloat greenDiffuseMaterial[] = 0.0, 1.0, 0.0,1.0; GLfloat whiteSpecularMaterial[] = 1.0, 1.0, 1.0,1.0; GLfloat greenAmbientMaterial[] = 0.0, 1.0, 0.2,1.0;
GLfloat greenEmissiveMaterial[] = 0.0, 1.0, 0.5,1.0;
GLfloat lightPosition[] = 0.0,1.0,0.0, 0.0;
GLfloat ambientLight[] = 0.0, 0.0, 0.0, 1.0 ;
GLfloat diffuseLight[] = 1.0, 1.0, 1.0, 1.0 ;
GLfloat specularLight[] = 1.0, 1.0, 1.0, 1.0 ;
编辑 1
for (int g =0;g<6400;g++)
glBegin(GL_QUADS);
if(mountText %2 ==0)glTexCoord2f(islandVert[g][0] /xscale,islandVert[g][2] / zscale);
else
glEnable(GL_NORMALIZE);
glDisable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_DEPTH_TEST);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, greenAmbientMaterial);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, greenDiffuseMaterial);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, whiteSpecularMaterial);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mShininess);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT);
glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glNormal3f(vertNorm[g][0],vertNorm[g][1],vertNorm[g][2]);
glVertex3f(islandVert[g][0],islandVert[g][1],islandVert[g][2]);
g++;
if(mountText %2 ==0)glTexCoord2f(islandVert[g][0] / xscale, islandVert[g][2] / zscale);
else
glEnable(GL_NORMALIZE);
glDisable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_DEPTH_TEST);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, whiteSpecularMaterial);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, greenAmbientMaterial);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, greenDiffuseMaterial);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mShininess);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT);
glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glNormal3f(vertNorm[g][0],vertNorm[g][1],vertNorm[g][2]);
glVertex3f(islandVert[g][0],islandVert[g][1],islandVert[g][2]);
g++;
if(mountText %2 ==0)glTexCoord2f(islandVert[g][0] / xscale, islandVert[g][2] / zscale);
else
glEnable(GL_NORMALIZE);
glDisable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_DEPTH_TEST);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, greenAmbientMaterial);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, greenDiffuseMaterial);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, whiteSpecularMaterial);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mShininess);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT);
glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glNormal3f(vertNorm[g][0],vertNorm[g][1],vertNorm[g][2]);
glVertex3f(islandVert[g][0],islandVert[g][1],islandVert[g][2]);
g++;
if(mountText %2 ==0)glTexCoord2f(islandVert[g][0] / xscale, islandVert[g][2] / zscale);
else
glEnable(GL_NORMALIZE);
glDisable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_DEPTH_TEST);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, greenAmbientMaterial);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, greenDiffuseMaterial);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, whiteSpecularMaterial);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mShininess);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT);
glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glNormal3f(vertNorm[g][0],vertNorm[g][1],vertNorm[g][2]);
glVertex3f(islandVert[g][0],islandVert[g][1],islandVert[g][2]);
glEnd();
基本上在每个坐标上,我都会检查纹理是否打开,如果不是,我想将其设置为原始绿色材质。我得到的结果是我的对象的一侧被极度照亮,而另一侧则是环境。顶点法线起作用是因为有平滑的阴影,但我认为这可能与我的灯光的位置有关。当我尝试改变它时,场景保持不变。
【问题讨论】:
【参考方案1】:仅此部分
GLfloat greenEmissiveMaterial[] = 0.0, 1.0, 0.5,1.0;
将使任何对象以颜色 (0, 1, 0.5) 显示,与您指定的任何光源无关。真正的光照只会添加该颜色,使其更加明亮。
【讨论】:
我忘了说我还有其他材质 setGLfloat greenDiffuseMaterial[] = 0.0, 1.0, 0.0,1.0; GLfloat whiteSpecularMaterial[] = 1.0, 1.0, 1.0,1.0; GLfloat greenAmbientMaterial[] = 0.0, 1.0, 0.2,1.0; 请提供代码中显示您遇到的问题的相关部分。以上是关于过多的镜面光opengl的主要内容,如果未能解决你的问题,请参考以下文章