问题了解OpenGL中的光照

Trt*_*Trt 0 opengl glsl

我在理解OpenGL中的光照效果方面遇到了一些问题(特别是理解预定义的变量.在某处有一个列表吗?).我一直在我的Vertex Shader文件中弄乱我的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;

}
Run Code Online (Sandbox Code Playgroud)

我将球体上的每个点与MVP矩阵相乘,然后与环境变量相乘.

片段着色器:

#version 330
precision highp float;

in vec3 ex_Color;
out vec4 gl_FragColor;

void main(void) {

gl_FragColor = vec4(ex_Color,1.0);

}
Run Code Online (Sandbox Code Playgroud)

什么是"精密highp浮动"; 呢?我知道顶点文件将颜色传递给片段着色器,然后该片段被"插入".好的插值是如何工作的?Opengl如何知道停止插值的位置?

Nic*_*las 5

ambient = ambient * in_Position ; // HERE IS WHAT I DONT GET!
Run Code Online (Sandbox Code Playgroud)

这使得我们两个.我不知道你打算用这个完成什么.那肯定会产生一种颜色.但它没有任何实际意义.它当然不符合"照明"的条件.

什么是"精密highp浮动"; 呢?

没有.不在桌面OpenGL中.我真的不知道为什么有人把它放在那里; 这些precision highp东西是为了GL ES兼容性,但版本3.30着色器从根本上与GL ES 2.0不兼容,因为ES 2.0不使用in/out限定符和桌面GLSL 3.30.

好的插值是如何工作的?

太宽泛了,无法在这里回答.这里有更好的解答,这是我更大的教程系列的一部分.

Opengl如何知道停止插值的位置?

三角形的边缘.