OpenGL ES 2.0顶点光照不一致

时间:2014-03-26 20:31:15

标签: opengl-es-2.0 glkit

我正在设置我的照明,如下所示。问题是看起来中间有一个巨大的光(你可以在下面的球体截图中看到)。目标是让三个灯呈三角形状,每个灯都可以在球体上看到(这是底部的截图)。要做到这一点,我是否需要将每个灯光创建为“聚光灯”?我注意到GLKEffectPropertyLight确实有这个属性,但不确定这是否是我想要的效果。

- (void)setupLighting
{
   // setup the lighting
   self.lightingType = GLKLightingTypePerPixel;
   self.colorMaterialEnabled = GL_TRUE;

   // light positions
   GLKVector4 light0Pos = GLKVector4Make(0.0f, 0.0f, 40.0f, 1.0f);
   GLKVector4 light1Pos = GLKVector4Make(-2.0f, -2.0f, 40.0f, 1.0f);
   GLKVector4 light2Pos = GLKVector4Make(2.0f, -2.0f, 40.0f, 1.0f);
   GLKVector4 frontLightDif = GLKVector4Make(0.1f, 0.1f, 0.1f, 1.0f);

   // specular, diffuse and ambient colors
   GLKVector4 specular = GLKVector4Make(0.45f, 0.45f, 0.45f, 1.0f);
   GLKVector4 diffuse = GLKVector4Make(0.15f, 0.15f, 0.15f, 1.0f);
   GLKVector4 ambient = GLKVector4Make(0.2f, 0.2f, 0.2f, 1.0f);

   // setup light 0 - ambient light
   self.light0.enabled = GL_TRUE;
   self.light0.position = light0Pos;
   self.light0.ambientColor = ambient;
   self.light0.diffuseColor = specular;
   self.light0.specularColor = specular;

   // setup light 1 - head on light
   self.light1.enabled = GL_TRUE;
   self.light1.position = light1Pos;
   self.light1.diffuseColor = frontLightDif;
   self.light1.specularColor = specular;

   // setup light 2
   self.light2.enabled = GL_TRUE;
   self.light2.position = light2Pos;
   self.light2.diffuseColor = diffuse;
   self.light2.specularColor = specular;
}

Incorrect sphere lighting

Correct sphere lighting

0 个答案:

没有答案