问题描述
我刚刚从 videotutorialsrock.com 上做了一个关于 C++ OpenGL 照明的教程.我了解环境光,但不了解定位光和直射光之间的区别,因为两者的想法和代码看起来非常相似.这是我的定位光代码:
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);
对于定向光:
//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);
谁能解释一下?
推荐答案
在定向中,光只从一个方向射出,而点光源从它的各个方向向外辐射光.
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.
(图片来自 okino.com)
(image credit to okino.com)
这篇关于C++ OpenGL中定位光和直射光的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!