gpt4 book ai didi

c++ - 我的照明是否正确?

转载 作者:行者123 更新时间:2023-11-28 01:02:19 24 4
gpt4 key购买 nike

我一直在阅读 pdf file on OpenGL lighting .

Gouraud Shading 说:

• Gouraud shading
– Set vertex normals
– Calculate colors at vertices
– Interpolate colors across polygon
• Must calculate vertex normals!
• Must normalize vertex normals to unit length!

这就是我所做的。这是我的顶点和片段着色器文件

V_Shader:

#version 330

layout(location = 0) in vec3 in_Position; //declare position
layout(location = 1) in vec3 in_Color;

// 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);
ambient = vec3(0.0f,0.0f,1.0f);
ex_Color = ambient * normalize(in_Position) ; //anti ex_Color=in_Color;
}

F_shader:

#version 330

in vec3 ex_Color;
out vec4 gl_FragColor;

void main(void) {
gl_FragColor = vec4(ex_Color,1.0);
}

片段着色器负责插值,对吗?

这是我的球体(顺便说一句,它是低多边形):

enter image description here

这是实现 Gouraud 着色的标准方法吗?(我的球体的中心是 (0,0,0))感谢您的耐心等待

最佳答案

ex_Color = ambient * normalize(in_Position) ; //anti ex_Color=in_Color;

请允许我quote myself , “它当然不符合‘照明’的条件。”从你第一次问这个问题到现在,这并没有停止。

这不是照明。这只是标准化模型空间位置并将其乘以环境颜色。即使我们假设模型空间位置以零为中心并代表球体上的一个点,将光线乘以法线也是没有意义的。它不是照明。

如果您想了解照明的工作原理,read this. Or this.

关于c++ - 我的照明是否正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8109451/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com