为什么GLKit缩放导致颜色/光照变暗?

时间:2013-04-29 06:47:18

标签: ios4 opengl-es glkit

我看到一种我似乎无法掌握的奇怪行为。 出于某种原因,当我应用比例(在z轴上)时,我的纹理映射多边形网格变暗,就好像光线突然被禁用或漫反射颜色设置为0.如果我反转比例(以便缩放返回到0)然后颜色再次变得明亮和鲜艳。

*使用其他信息进行更新。 * 当我的顶点上的z值处于其原始/初始化值时,亮度似乎很好。但是当我沿着z轴缩放时,这是当颜色变暗(不是完全黑暗,但亮度明显变化)时。 我正在使用索引缓冲区进行渲染。

究竟是什么导致这种“故障”?

与此相关的代码如下:

float aspect = fabsf(self.view.bounds.size.width / self.view.bounds.size.height);
GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(60.0f), aspect, 0.1f, 100.0f);

self.effect.transform.projectionMatrix = projectionMatrix;

// Compute the model view matrix for the object rendered with GLKit
GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 15.0f, -90.0f);
modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, rotationAngle, 0, 1, 0);

// where g_depthScale is a value that increases based on a slider control.
modelViewMatrix = GLKMatrix4Scale(modelViewMatrix, 0.1f, 0.1f, g_depthScale);

self.effect.transform.modelviewMatrix = modelViewMatrix;

1 个答案:

答案 0 :(得分:1)

正如Matic Oblak所述,您可能会在缩放模型时缩放法线。

让整个场景按比例缩放的便宜而简单的方法是更改​​投影矩阵的视角,请参阅OpenGL ES 2.0 Pinch and Zoom