【发布时间】:2011-11-11 02:13:49
【问题描述】:
我在理解光照在 OpenGL 中的工作原理时遇到了一些问题(尤其是理解预定义变量。在某处是否有它们的列表?)。我一直在我的顶点着色器文件中弄乱我的 shpere。所以我设法遮住了它,但我不知道我做了什么。代码如下:
顶点着色器:
#version 330
precision highp float;
in vec3 in_Position; //declare position
in vec3 in_Color; //color passed from the cpp file
//mycode
in vec3 in_Normal;
// mvpmatrix is the result of multiplying the model, view, and projection matrices */
uniform mat4 MVP_matrix;
vec3 ambient;
out vec3 ex_Color;
void main(void) {
// Multiply the MVP_ matrix by the vertex to obtain our final vertex position (mvp was created in *.cpp)
gl_Position = MVP_matrix * vec4(in_Position, 1.0);
//mycode
ambient = vec3(0.0f,0.1f,1.0f); // just a test vector
ambient = ambient * in_Position ; // HERE IS WHAT I DONT GET!
ex_Color = ambient;
}
我将球体上的每个点乘以 MVP 矩阵,然后乘以环境变量。
片段着色器:
#version 330
precision highp float;
in vec3 ex_Color;
out vec4 gl_FragColor;
void main(void) {
gl_FragColor = vec4(ex_Color,1.0);
}
“precision highp float;”是什么意思?做?我知道顶点文件将颜色传递给片段着色器,然后该片段被“插值”。好的插值是如何工作的? Opengl 怎么知道在哪里停止插值?
【问题讨论】:
-
"在某处是否有它们的列表" 是的。 The OpenGL specification. 真的,你需要停止零敲碎打地问这些问题,去look up a good tutorial already。这类问题对任何人都没有好处。你基本上是在问,“OpenGL 的整个部分是如何工作的?”
-
@NicolBolas 我知道教程,我只是没有时间,而且大多数都使用自定义库。所以这就是我问这个的原因。
-
@TrtTrt:您不想花时间正确学习,所以您要求我们基本上为您编写教程。我不确定我是否理解你的逻辑。使用“自定义库”有什么问题?还是您相信通过重新发明轮子会有所收获?学习像图形编程这样复杂的东西需要能够切入手头的实际问题。这意味着使用库来处理无关紧要的事情。
-
@NicolBolas:这个“我没有时间”的论点,以及 Trt Trt 提出的所有问题都让我想起了在 comp.graphics.api.opengl 新闻组中飞过的 Skybuck @ 987654323@