Difference between positioned and direct light in

2019-09-14 17:05发布

I just did a tutorial from videotutorialsrock.com on lighting in C++ OpenGL. I understand ambient light, but don't understand the difference between positioned light and direct light, since the idea and the code of both looked very similar. Here's my code for positioned light:

//Add positioned light
GLfloat lightColor0[] = {.6, .6, .6, 1};
GLfloat lightPos0[] = {4, 0, 8, 1};
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos0);

And for directional light:

//Add direct light
GLfloat lightColor1[] = {.5, .2, .2, 1};
GLfloat lightPos1[] = {-1, .5, .5, 0};
glLightfv(GL_LIGHT1, GL_DIFFUSE, lightColor1);
glLightfv(GL_LIGHT1, GL_POSITION, lightPos1);

Could someone explain?

2条回答
欢心
2楼-- · 2019-09-14 17:20

Different w in the position vector(xyzw).

GLfloat lightPos0[] = {4, 0, 8, 1};
w = 1 means point (3d position)

GLfloat lightPos1[] = {-1, .5, .5, 0};
w = 0 means vector (3d direction)

https://gamedev.stackexchange.com/questions/14115/do-i-need-the-w-component-in-my-vector-class

查看更多
混吃等死
3楼-- · 2019-09-14 17:31

In directional, the light is only coming from a single direction, while a point light radiates light out in every direction from it.

Directional light can be used to simulate a point light extremely far away, such as the sun shining on earth.

http://www.okino.com/new/toolkit/image22.gif (image credit to okino.com)

查看更多
登录 后发表回答