1

I need to set const spot light position with GLKBaseEffect: so when I change modelview, light stays in the same place. How can I achieve this?

kpower
  • 3,871
  • 4
  • 42
  • 62

2 Answers2

1

When you set the position of a light using GLKBaseEffect, it uses the value currently stored in its modelviewMatrix property. So, you need to set this value twice, once for the light and once for your object:

self.effect.transform.modelviewMatrix = GLKMatrix4Identity;
self.effect.light1.position = GLKVector4Make(0.0, 1.0, 3.0, 1);

GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -3.0f);
modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, GLKMathDegreesToRadians(90), 0, 1, 0);
self.effect.transform.modelviewMatrix = modelViewMatrix;

That should do the trick

Ricardo RendonCepeda
  • 3,271
  • 4
  • 23
  • 30
  • Hmm. Solution is wrong for me. Seems that subsequent modelview modification affects light also (for OpenGL 1.0 it's as excepted and `GLKBaseEffect` tries to emulate it). – kpower Dec 28 '12 at 07:13
  • 1
    I'll have look, but in my project this works fine when declared inside the draw function. I admit I mostly use OpenGL ES 2.0 shaders precisely because I know what my code is doing. Although GLKBaseEffect emulates OpenGL ES 1.1, a lot of the implementation details are quite tricky and hidden. Shaders all the way! – Ricardo RendonCepeda Dec 28 '12 at 14:58
  • Quite agree with you. But for now I simply want to save time: I don't know GLSL and want to simply make first apps version ASAP. – kpower Dec 28 '12 at 16:29
0

The only solution helped me here was to make own shaders.

kpower
  • 3,871
  • 4
  • 42
  • 62