Difference between positioned and direct light in C++ OpenGL?

﹥>﹥吖頭↗ 提交于 2019-12-12 03:54:27

问题


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?


回答1:


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.

(image credit to okino.com)


回答2:


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



来源:https://stackoverflow.com/questions/16406861/difference-between-positioned-and-direct-light-in-c-opengl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!