我正在尝试向我的应用程序添加凹凸贴图功能,但我得到了非常多面的模型:

发生这种情况的原因是因为我正在计算每个面的切线、副法线和法线,而完全忽略了我从模型文件中获得的法线。
计算目前使用三角形的两条边和纹理空间向量得到切线和副法线,然后通过叉积计算法线。模型加载后,这一切都在 CPU 上完成,然后将值存储为模型几何的一部分。
vector1 = vertex2.coords - vertex1.coords;
vector2 = vertex3.coords - vertex1.coords;
tuVector = vertex2.texcoords - vertex1.texcoords;
tvVector = vertex3.texcoords - vertex1.texcoords;
float den = 1.0f / (tuVector.x * tvVector.y - tuVector.y * tvVector.x);
tangent.x = (tvVector.y * vector1.x - tvVector.x * vector2.x) * den;
tangent.y = (tvVector.y * vector1.y - tvVector.x * vector2.y) * den;
tangent.z = (tvVector.y * vector1.z - tvVector.x * vector2.z) * den;
binormal.x = (tuVector.x * vector2.x - tuVector.y * vector1.x) * …Run Code Online (Sandbox Code Playgroud) 我想知道如何使用顶点法线来实现闪电效果?目前我所拥有的是我可以将顶点和纹理坐标发送到着色器并使用它们但是使用法线,我不知道如何在着色器程序中使用它们.以下是我到目前为止的情况.
// vertex shader
layout(location = 0) in vec4 vert;
layout(location = 1) in vec4 color;
layout(location = 2) in vec2 texcoord;
uniform mat4 m_model;
uniform mat4 m_view;
uniform mat4 m_proj;
void main() {
gl_Position = m_proj * m_view * m_model * vert;
}
// fragment shader
in vec2 fragtexcoord;
out vec4 color;
uniform sampler2D textureunit;
void main(void) {
color = texture(textureunit, fragtexcoord);
}
Run Code Online (Sandbox Code Playgroud)
编辑 以下是我的着色器.
顶点着色器
layout(location = 0) in vec4 vert;
layout(location = 1) in vec4 color;
layout(location …Run Code Online (Sandbox Code Playgroud)