在OpenGL中了解照明问题 [英] Issue Understanding Lighting in OpenGL

查看:120
本文介绍了在OpenGL中了解照明问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在理解光照在OpenGL中的工作方式时遇到了一些问题(特别是了解预定义的变量.在某处有它们的列表吗?).我一直在我的顶点着色器"文件中弄乱了阴影,以使我的阴影变深.所以我设法遮住了阴影,但我不知道自己做了什么.这是代码:

I am having some problems understanding how lighting works in OpenGL (especially understanding the pre-defined variables. is there a list of them somewhere?). I have been messing around in my Vertex Shader file to shade my shpere. So I managed to shade it but I don't know what I did. Here is the code:

顶点着色器:

#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矩阵相乘,然后与环境变量相乘.

I am multiplying each point on the sphere with a MVP matrix, and then with an ambient variable.

片段着色器:

#version 330
precision highp float;

in vec3 ex_Color;
out vec4 gl_FragColor;

void main(void) {

gl_FragColor = vec4(ex_Color,1.0);

}

高精度浮点"是什么意思?做?我知道顶点文件将颜色传递给片段着色器,然后该片段被插值".插值如何工作? Opengl如何知道在哪里停止插值?

What does "precision highp float;" does? I know that the vertex file passes the color to the fragment shader and then that fragment gets "interpolated". Ok how does interpolation works? How does Opengl know where to stop the interpolation ?

推荐答案

ambient = ambient * in_Position ; // HERE IS WHAT I DONT GET!

那使我们两个人成为了现实.我不知道您打算完成什么.那肯定会产生颜色.但这实际上没有任何意义.当然,它不符合照明"的条件.

That makes two of us. I have no idea what it is that you intend to accomplish with this. That will certainly produce a color. But it won't be meaningful in any real way. It certainly doesn't qualify as "lighting".

高精度浮点"是什么意思?是吗?

What does "precision highp float;" does?

什么都没有.不在桌面OpenGL中.我真的不知道为什么有人把它放在那里. precision highp用于GL ES兼容性,但是3.30版着色器与GL ES 2.0基本不兼容,因为ES 2.0不使用in/out限定符,而台式机GLSL 3.30则使用.

Nothing. Not in desktop OpenGL. I really have no idea why someone put that there; the precision highp stuff is for GL ES compatibility, but version 3.30 shaders are fundamentally incompatible with GL ES 2.0, since ES 2.0 doesn't use in/out qualifiers and desktop GLSL 3.30 does.

确定插值如何工作?

Ok how does interpolation works?

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

Way too broad to answer here. This is better answered here, which is part of my much larger tutorial series.

Opengl如何知道在哪里停止插值?

How does Opengl know where to stop the interpolation ?

三角形的边缘.

这篇关于在OpenGL中了解照明问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆